Skip to content

Commit

Permalink
Remove useless UNIONs in query.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbgn committed Jul 21, 2023
1 parent 3531de0 commit a258e93
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions transforge/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from transforge.lang import Language
from transforge.graph import (
TransformationGraph, CyclicTransformationGraphError)
from transforge.bag import Bag
from transforge.bag import Bag, TypeUnion


def union(prefix: str, subjects: Iterable[Node]) -> Iterator[str]:
Expand Down Expand Up @@ -240,7 +240,8 @@ def types(self) -> Iterator[str]:

bag = Bag()
for tus in self.type.values():
bag.add(*(self.lang.parse_type_uri(tu) for tu in tus))
bag.add(*(self.lang.parse_type_uri(tu)
for tu in tus if isinstance(tu, URIRef)))

for ts in bag.content:
if len(ts) == 1:
Expand Down Expand Up @@ -334,10 +335,13 @@ def chronology(self) -> Iterator[str]:
yield f"{c.n3()} :from+ {current.n3()}."

# Write operator/type properties of this step
type_set = TypeUnion(self.lang.parse_type_uri(t)
for t in self.type.get(current, ()) if isinstance(t, URIRef))

yield from union(f"{current.n3()} :via",
self.operator.get(current, ()))
yield from union(f"{current.n3()} :type/rdfs:subClassOf*",
self.type.get(current, ()))
yield from union(f"{current.n3()} :type/rdfs:subClassOf*",
(self.lang.uri(t) for t in type_set))

# Make sure as early as possible that there is no earlier on the
# same branch
Expand Down

0 comments on commit a258e93

Please sign in to comment.