Skip to content

Commit 50d45da

Browse files
committed
Use any existing TIME hints in graph to do further ordering.
Signed-off-by: Alex Nelson <[email protected]>
1 parent 351afb9 commit 50d45da

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

case_prov/case_prov_dot.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
NS_PROV = rdflib.Namespace("http://www.w3.org/ns/prov#")
4545
NS_RDFS = rdflib.RDFS
46+
NS_TIME = rdflib.TIME
4647

4748
# This one isn't among the prov constants.
4849
PROV_COLLECTION = NS_PROV.Collection
@@ -772,6 +773,43 @@ def _render_edges(
772773
dot_edge = pydot.Edge(node_id_1, node_id_2, **kwargs)
773774
dot_graph.add_edge(dot_edge)
774775

776+
# Include any temporal ordering among the filtered nodes as hidden edges to impose ordering.
777+
# This sorting assumes the non-normative alignment of TIME and PROV-O, available at:
778+
# https://github.com/w3c/sdw/blob/gh-pages/time/rdf/time-prov.ttl
779+
invisible_edge_node_pairs: typing.Set[
780+
typing.Tuple[rdflib.URIRef, rdflib.URIRef]
781+
] = set()
782+
n_predicate: rdflib.URIRef
783+
order: str
784+
for (n_predicate, order) in {
785+
(NS_TIME.after, "rtl"),
786+
(NS_TIME.before, "ltr"),
787+
(NS_TIME.intervalAfter, "rtl"),
788+
(NS_TIME.intervalBefore, "ltr"),
789+
}:
790+
for triple in graph.triples((None, n_predicate, None)):
791+
if str(triple[0]) not in iris_used:
792+
continue
793+
if str(triple[2]) not in iris_used:
794+
continue
795+
if not isinstance(triple[0], rdflib.URIRef):
796+
continue
797+
if not isinstance(triple[2], rdflib.URIRef):
798+
continue
799+
800+
if order == "ltr":
801+
invisible_edge_node_pairs.add((triple[0], triple[2]))
802+
else:
803+
invisible_edge_node_pairs.add((triple[2], triple[0]))
804+
_logger.debug(
805+
"len(invisible_edge_node_pairs) = %d.", len(invisible_edge_node_pairs)
806+
)
807+
for invisible_edge_node_pair in invisible_edge_node_pairs:
808+
node_id_1 = record[0]
809+
node_id_2 = record[1]
810+
dot_edge = pydot.Edge(node_id_1, node_id_2, style="invis")
811+
dot_graph.add_edge(dot_edge)
812+
775813
dot_graph.write_raw(args.out_dot)
776814

777815

0 commit comments

Comments
 (0)