diff --git a/transformation_algebra/query.py b/transformation_algebra/query.py index a90f035..79a7da0 100644 --- a/transformation_algebra/query.py +++ b/transformation_algebra/query.py @@ -191,12 +191,6 @@ def assign_variables(self, node: Node, path: list[Node] = []) -> Variable: return var - def run(self, graph: Graph) -> set[Node]: - """ - Find all workflows in a graph that match this query. - """ - return set(r.workflow for r in graph.query(self.sparql())) - def sparql(self) -> str: """ Obtain a SPARQL query. @@ -307,6 +301,9 @@ def chronology(self) -> Iterator[str]: if current in visited: continue + # afters = " ".join(a.n3() for a in self.after[current]) + # yield f"{{SELECT DISTINCT {current.n3()} {afters} WHERE {{" + # Connect the initial nodes (ie outputs) if not self.after[current]: assert current in self.outputs @@ -332,6 +329,23 @@ def chronology(self) -> Iterator[str]: yield from union(f"{current.n3()} :type/rdfs:subClassOf*", self.type.get(current, ())) + # Make sure as early as possible that there is no earlier on the + # same branch + # for c in self.after[current]: + # types = self.type.get(current) or [] + # if not len(types) == 1: + # continue + # between = next(self.generator) + # yield "FILTER NOT EXISTS {" + # yield f"{current.n3()} ^:to+ {between.n3()}." + # yield f"{c.n3()} :to* {between.n3()}." + # for t in types: + # yield f"{between.n3()} :type/rdfs:subClassOf* {t.n3()}." + # yield "}" + + # Make sure we don't check the same node + # yield "}}" + visited.add(current) # Add successors to queue