Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Merge branch 'main' into confidence-literal-typing

Mohd Kaif3063bf8096b0
diff --cc semantica/export/rdf_exporter.py
index 0e575ea6,de3d0dd0..696076f5
--- a/semantica/export/rdf_exporter.py
+++ b/semantica/export/rdf_exporter.py
@@@ -686,31 -600,22 +686,33 @@@ class RDFSerializer
# Convert entities to JSON-LD
entities = rdf_data.get("entities", [])
for entity in entities:
- # Generate @id if not provided
- entity_id = entity.get("id")
- if not entity_id:
- entity_text = entity.get("text", "")
- entity_id = f"semantica:entity/{entity_text}"
+ # Generate @id if not provided. Minted the same way the Turtle and
+ # N-Triples paths mint it (#1101), so one knowledge graph carries
+ # the same node identity whichever serializer wrote it. The former
+ # f"semantica:entity/{text}" interpolated the raw text into an IRI:
+ # any entity whose text contained a space produced an invalid IRI
+ # and was dropped in full by a JSON-LD parser, silently.
+ entity_id = entity.get("id") or mint_entity_iri(entity.get("text", ""))
- jsonld["@graph"].append(
- {
- "@id": entity_id,
- "@type": entity.get("type", "semantica:Entity"),
- "semantica:text": entity.get("text") or entity.get("label", ""),
- "semantica:confidence": entity.get("confidence", 1.0),
+ node = {
+ "@id": entity_id,
+ "@type": entity.get("type", "semantica:Entity"),
+ "semantica:text": entity.get("text") or entity.get("label", ""),
+ }
+ confidence = normalize_confidence(entity.get("confidence", 1.0))
+ if confidence is None:
+ self.logger.warning(
+ f"Entity {entity_id} has a confidence that is not a number "
+ f"({entity.get('confidence')!r}), so no confidence is written"
+ )
+ else:
+ # A native JSON number becomes xsd:double once expanded, so the
+ # value is written as a typed literal instead.
+ node["semantica:confidence"] = {
+ "@value": confidence,
+ "@type": CONFIDENCE_DATATYPE,
}
- )
+ jsonld["@graph"].append(node)
# Convert relationships to JSON-LD
relationships = rdf_data.get("relationships", [])