Compose

SPARQL query composition from diagram paths - pure-library module.

Canonical implementation of query composition from diagram paths:

  • Each node position gets a fresh variable named after its URI local name.

  • Duplicate variables get suffixed: protein, protein_1, protein_2.

  • Triple patterns are deduplicated.

  • rdf:type assertions are optional.

  • OPTIONAL label clauses use rdfs:label + dc:title.

compose_query_from_paths(paths: list[dict[str, Any]], prefixes: dict[str, str], options: dict[str, Any] | None = None) dict[str, Any][source]

Generate a SPARQL query from diagram paths.

Parameters:
  • paths – List of path dicts, each with an edges list. Each edge has source, target, predicate, and is_forward.

  • prefixes – Namespace prefix map (e.g. {"wp": "http://..."}.

  • options – Optional dict with include_types (bool), include_labels (bool), limit (int), value_bindings (dict).

Returns:

{"query": "SELECT ...", "variable_map": {...}, "jsonld": {...}}

Return type:

dict