Skip to content

Commit

Permalink
Include union-of-types in query.
Browse files Browse the repository at this point in the history
Until #79 is implemented, as of 11bc3fc
we work around the issue of intersection types by using choice, as
described in #77. That is, if we want to query for `R(x, y)`, we also
accept `R(x, y & z)` (or, temporarily using product types for
intersection types, `R(x, y * z)`. However, this means that when we are
querying for workflows that contain an intersection type, we can't just
ignore it: we must query for `{... R(x, y * z)} UNION { ... R(x, y)}`.
This is implemented with this commit, but it should surely not be the
solution we end up with.
  • Loading branch information
nsbgn committed Aug 22, 2022
1 parent 041c242 commit 6d15140
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions transformation_algebra/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ def sparql(*elems: str | Iterable[str]) -> str:
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>",
"SELECT ?workflow WHERE {",
"GRAPH ?workflow {",
"{SELECT ?workflow WHERE {",
"?workflow a :Transformation.",
self.io() if self.by_io else (),
self.operators() if self.by_operators else (),
self.types() if self.by_types else (),
"} GROUP BY ?workflow}",
self.io() if self.by_io else (),
self.chronology() if self.by_chronology else (),
"}} GROUP BY ?workflow"
"}",
"} GROUP BY ?workflow"
)
return result

Expand All @@ -236,7 +239,17 @@ def types(self) -> Iterator[str]:
types.add(type_choice[0])

for type in types:
yield f"?workflow :contains/rdfs:subClassOf* {type.n3()}."
# yield f"?workflow :contains/rdfs:subClassOf* {type.n3()}."
yield f"{next(self.generator).n3()} {next(self.generator).n3()} {type.n3()}."

# Also include union types. TODO this is temporary until #79 is
# resolved; see also:
# https://github.com/quangis/transformation-algebra/issues/77#issuecomment-1215064807
for type_choice in self.type.values():
if len([t for t in type_choice if t not in types]) >= 2:
yield from union(
f"{next(self.generator).n3()} {next(self.generator).n3()}",
type_choice)

def operators(self) -> Iterator[str]:
"""
Expand Down

0 comments on commit 6d15140

Please sign in to comment.