Skip to content

Commit

Permalink
Use Top type to handle wildcards in queries.
Browse files Browse the repository at this point in the history
Cf. #94, #95, #96.
  • Loading branch information
nsbgn committed Jun 24, 2022
1 parent 39c7769 commit bd567a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
22 changes: 21 additions & 1 deletion tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rdflib.term import BNode, Node, URIRef, Literal
from rdflib.namespace import RDF

from transformation_algebra.type import TypeOperator, Type, TypeAlias
from transformation_algebra.type import TypeOperator, Type, TypeAlias, _
from transformation_algebra.expr import Operator, Expr
from transformation_algebra.lang import Language
from transformation_algebra.graph import TransformationGraph, TA, TEST
Expand Down Expand Up @@ -292,6 +292,26 @@ def test_that_supertypes_are_captured(self):
self.assertQuery(lang, graph, F(X), results={TEST.fx, TEST.fy})
self.assertQuery(lang, graph, F(Y), results={TEST.fy})

def test_that_wildcards_are_captured(self):
# Test that using a wildcard in a query captures all types
X = TypeOperator()
Y = TypeOperator(supertype=X)
F = TypeOperator(params=2)
FFXYY, FYY = TypeAlias(F(F(X, Y), Y)), TypeAlias(F(Y, Y))
lang = Language(locals(), namespace=TEST, include_top=True)

graph = make_graph(lang, {
TEST.x: ~X,
TEST.y: ~Y,
TEST.ffx: ~F(F(X, Y), Y),
TEST.fy: ~F(Y, Y)
})

self.assertQuery(lang, graph, _, results={TEST.x, TEST.y, TEST.ffx,
TEST.fy})
self.assertQuery(lang, graph, F(_, _), results={TEST.ffx, TEST.fy})
self.assertQuery(lang, graph, F(F(_, _), _), results={TEST.ffx})

def test_tree_unfold(self):
# Test if the optional unfolding of trees happens.
# We construct a workflow that shouldn't match with the DAG for our
Expand Down
3 changes: 2 additions & 1 deletion transformation_algebra/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ def parse_shortcuts(self, remove: bool = True) -> None:
ns = self.language.namespace
# TODO handle collections of types/operators
for subj, obj in self[:ns.type:]:
type = self.language.parse_type(str(obj))
type = self.language.parse_type(str(obj)).concretize(
wildcard=Top)
node = self.type_nodes[type]
self.add((subj, TA.type, node))

Expand Down
2 changes: 1 addition & 1 deletion transformation_algebra/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def backtrack():
else:
stack.append(None)
elif token == "_":
stack.append(TypeVariable())
stack.append(TypeVariable(wildcard=True))
elif token == "*":
t1 = stack.pop()
assert isinstance(t1, TypeInstance)
Expand Down

0 comments on commit bd567a3

Please sign in to comment.