Skip to content

Commit

Permalink
Make adding ta:step connections optional.
Browse files Browse the repository at this point in the history
To clean up the visualization.
  • Loading branch information
nsbgn committed Sep 28, 2021
1 parent c71677d commit ad84a19
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions transformation_algebra/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def rdf_expr(self,
sources: Dict[str, Union[Node, Tuple[Node, Expr]]] = {},
variables: Dict[Variable, Node] = {},
include_types: bool = True,
include_labels: bool = True) -> Node:
include_labels: bool = True,
include_steps: bool = True) -> Node:
"""
Translate the given expression to a representation in RDF and add it
to the given graph, connecting all steps to root. Inputs that match the
Expand All @@ -149,7 +150,9 @@ def rdf_expr(self,

current = current or BNode()
output.add((root, RDF.type, TA.Transformation))
output.add((root, TA.step, current))

if include_steps:
output.add((root, TA.step, current))

if isinstance(expr, Base):
datatype = expr.type.output()
Expand Down Expand Up @@ -209,7 +212,8 @@ def rdf_expr(self,
# part, we eventually get a node for the function to which nodes
# for all parameters are attached.
f = self.rdf_expr(output, expr.f, root, current,
sources, variables, include_types, include_labels)
sources, variables, include_types, include_labels,
include_steps)

# For simple data, we can simply attach the node for the parameter
# directly. But when the parameter is a *function*, we need to be
Expand All @@ -235,7 +239,6 @@ def rdf_expr(self,
internal = BNode()
current_internal = internal
output.add((internal, RDF.type, TA.InternalData))
output.add((root, TA.step, internal))
output.add((f, TA.internal, internal))

if include_labels:
Expand All @@ -246,14 +249,17 @@ def rdf_expr(self,
{p: internal for p in expr.x.params}

x = self.rdf_expr(output, expr.x.body, root, BNode(),
sources, variables, include_types, include_labels)
sources, variables, include_types, include_labels,
include_steps)
else:
x = self.rdf_expr(output, expr.x, root, BNode(),
sources, variables, include_types, include_labels)
sources, variables, include_types, include_labels,
include_steps)
output.add((internal, TA.feeds, x))
else:
x = self.rdf_expr(output, expr.x, root, BNode(),
sources, variables, include_types, include_labels)
sources, variables, include_types, include_labels,
include_steps)
output.add((x, TA.feeds, f))

# If `x` has internal operations of its own, then those inner
Expand Down Expand Up @@ -283,7 +289,8 @@ def rdf_workflow(self,
output: Graph,
root: Node,
sources: set[Node],
steps: dict[Node, tuple[Expr, list[Node]]]) -> Node:
steps: dict[Node, tuple[Expr, list[Node]]],
**kwargs) -> Node:
"""
Convert a workflow to a full transformation graph by converting its
individual steps to representations of expressions in RDF and combining
Expand Down Expand Up @@ -312,9 +319,10 @@ def to_expr_node(step_node: Node) -> Node:
assert all(x in steps or x in sources for x in inputs), \
"unknown input data source"
cache[step_node] = self.rdf_expr(output, expr, root, sources={
f"x{i}": (to_expr_node(x), steps[x][0]) if x in steps else x
f"x{i}": (to_expr_node(x), steps[x][0])
if x in steps else x
for i, x in enumerate(inputs, start=1)
})
}, **kwargs)
return cache[step_node]

# One of the tool expressions must be 'last', in that it represents the
Expand Down

0 comments on commit ad84a19

Please sign in to comment.