Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(export): keep the full predicate on the reified relationship

FABIOTESSd7ee22cf1f75
diff --git a/semantica/export/rdf_exporter.py b/semantica/export/rdf_exporter.py
index d5ee173f..f07964e7 100644
--- a/semantica/export/rdf_exporter.py
+++ b/semantica/export/rdf_exporter.py
@@ -446,9 +446,12 @@ class RDFSerializer:
"""
rel_id = rel.get("id") or mint_relationship_iri(idx, source_id or "", target_id or "")
- type_label = rel_type.rsplit("#", 1)[-1].rsplit("/", 1)[-1]
+ # The full predicate, not its local name. Truncating to the fragment
+ # made https://a.example/ns#employs and https://b.example/ns#employs the
+ # same literal, so the temporal node no longer said which predicate it
+ # described, and it disagreed with the direct triple beside it.
escaped = (
- str(type_label)
+ str(rel_type)
.replace("\\", "\\\\")
.replace('"', '\\"')
.replace("\n", "\\n")
diff --git a/tests/export/test_owl_time_reachability.py b/tests/export/test_owl_time_reachability.py
index cdcb97b2..92473390 100644
--- a/tests/export/test_owl_time_reachability.py
+++ b/tests/export/test_owl_time_reachability.py
@@ -141,3 +141,49 @@ def test_the_reified_terms_are_declared_in_the_shipped_vocabulary():
undeclared = {t for t in emitted if t.startswith(NS) and t not in declared}
assert not undeclared, f"emitted but not declared in the vocabulary: {undeclared}"
+
+
+# ── Review finding on the first revision of this fix ─────────────────────────
+
+def test_the_reified_type_keeps_the_full_predicate():
+ """
+ Truncating to the local name made two predicates from different namespaces
+ indistinguishable, and disagreed with the direct triple beside it.
+ """
+ from rdflib import Literal
+
+ def reified_type(rel_type):
+ kg = {
+ "entities": KG["entities"],
+ "relationships": [
+ {
+ "source_id": E1,
+ "target_id": E2,
+ "type": rel_type,
+ "valid_from": "2024-01-01T00:00:00Z",
+ }
+ ],
+ }
+ graph = Graph()
+ graph.parse(
+ data=RDFSerializer().serialize_to_turtle(kg, include_temporal=True),
+ format="turtle",
+ )
+ node = next(iter(graph.subjects(RDF.type, URIRef(NS + "Relationship"))))
+ return set(graph.objects(node, URIRef(NS + "type")))
+
+ a = reified_type("https://a.example/ns#employs")
+ b = reified_type("https://b.example/ns#employs")
+
+ assert a == {Literal("https://a.example/ns#employs")}, a
+ assert a != b, "two distinct predicates produced the same reified type"
+
+
+def test_the_reified_type_matches_the_direct_triples_predicate():
+ from rdflib import Literal
+
+ graph = _graph(include_temporal=True)
+ node = next(iter(graph.subjects(RDF.type, URIRef(NS + "Relationship"))))
+
+ assert set(graph.objects(node, URIRef(NS + "type"))) == {Literal(EMPLOYS)}
+ assert (URIRef(E1), URIRef(EMPLOYS), URIRef(E2)) in graph