|
43 | 43 |
|
44 | 44 | NS_PROV = rdflib.Namespace("http://www.w3.org/ns/prov#") |
45 | 45 | NS_RDFS = rdflib.RDFS |
| 46 | +NS_TIME = rdflib.TIME |
46 | 47 |
|
47 | 48 | # This one isn't among the prov constants. |
48 | 49 | PROV_COLLECTION = NS_PROV.Collection |
@@ -772,6 +773,43 @@ def _render_edges( |
772 | 773 | dot_edge = pydot.Edge(node_id_1, node_id_2, **kwargs) |
773 | 774 | dot_graph.add_edge(dot_edge) |
774 | 775 |
|
| 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 | + |
775 | 813 | dot_graph.write_raw(args.out_dot) |
776 | 814 |
|
777 | 815 |
|
|
0 commit comments