Semantica Knowledge Graph Export Pipeline: RDF, OWL, and Cypher Conversion Explained
Semantica's export pipeline converts internal knowledge graph dictionaries into RDF, OWL, or Cypher formats through a normalized dispatcher that routes to format-specific exporters with shared namespace management and validation.
The semantica-agi/semantica repository implements a modular export architecture for knowledge graph serialization. This article breaks down the complete pipeline from raw Python dictionaries to standard graph formats, with precise source code references from the implementation.
Payload Normalization: The First Pipeline Stage
Before any export occurs, Semantica normalizes the incoming knowledge graph structure. The normalize_graph_payload() function in semantica/utils/helpers.py (around line 976) standardizes vocabulary variations into a consistent shape.
Supported input vocabularies:
entities/relationships— the canonical Semantica formatnodes/edges— common graph theory terminology
The normalizer coerces both into { "entities": [...], "relationships": [...] }, ensuring downstream exporters receive a predictable data structure regardless of how users constructed their graphs.
Unified Export Entry Point: export_knowledge_graph()
The central dispatcher lives in semantica/export/methods.py at line 883. This function serves as the primary API for all export operations.
from semantica.export import export_knowledge_graph
kg = {
"entities": [{"id": "E1", "type": "Person", "name": "Alice"}],
"relationships": [{"source": "E1", "target": "E2", "type": "knows"}],
}
# Auto-detect format from extension
export_knowledge_graph(kg, "graph.ttl")
# Explicit format selection
export_knowledge_graph(kg, "graph.cypher", format="cypher")
The dispatcher resolves the target format through either:
- File extension inference (
*.ttl→turtle,*.cypher→cypher, etc.) - Explicit
format=parameter override
Format-Specific Exporter Dispatch
Once normalized and routed, the pipeline instantiates the appropriate exporter class. The dispatch logic at lines 883–910 in methods.py handles three primary format families.
RDF/Turtle/RDF-XML/JSON-LD/N-Triples: RDFExporter
Located in semantica/export/rdf_exporter.py, the RDFExporter class provides comprehensive RDF serialization through the export_to_rdf() method (lines 74–88).
Key components:
NamespaceManager(lines 72–82) — Collects standard RDF prefixes plus the shared Semantica base URI fromprovenance.manager.DEFAULT_BASE_URIRDFValidator.validate_rdf_syntax(lines 60–68) — Pre-serialization syntax validationRDFSerializer— Produces Turtle, RDF/XML, JSON-LD, or N-Triples output
from semantica.export import RDFExporter
# Direct exporter usage
RDFExporter().export_knowledge_graph(kg, "graph.ttl")
# With explicit format
RDFExporter().export(kg, "graph.jsonld", format="jsonld")
OWL/XML and OWL/Turtle: OWLExporter
The semantica/export/owl_exporter.py module handles OWL ontology export with two internal pathways:
_export_owl_xml()— OWL-XML serialization_export_owl_turtle()— OWL in Turtle syntax
from semantica.export import OWLExporter
ontology = {
"name": "FamilyOntology",
"classes": [{"id": "Person", "label": "Person"}],
"object_properties": [{"id": "hasChild", "domain": "Person", "range": "Person"}],
}
OWLExporter(ontology_uri="http://example.org/family#").export(
ontology, "family.owl", format="owl-xml"
)
Cypher/Neo4j: LPGExporter
The Labeled Property Graph exporter in semantica/export/lpg_exporter.py generates Cypher CREATE statements for Neo4j compatibility. The export_lpg() function (called from the dispatcher) routes to this class.
Core generation methods:
_generate_node_queries()(lines 42–58) — CreatesCREATE (n:Label {properties})statements_generate_relationship_queries()— CreatesCREATE (a)-[r:TYPE]->(b)statements
from semantica.export import LPGExporter, export_knowledge_graph
kg = {
"entities": [{"id": "n1", "type": "Person", "name": "Bob"}],
"relationships": [{"source": "n1", "target": "n2", "type": "knows"}],
}
# Via dispatcher
export_knowledge_graph(kg, "graph.cypher", format="cypher")
# Direct usage
LPGExporter().export(kg, "graph.cypher")
Namespace Management and IRI Resolution
RDF and OWL exports rely on consistent IRI generation. The RDFExporter initializes a NamespaceManager that binds:
- Standard W3C prefixes (
rdf,rdfs,owl,skos) - The Semantica base URI from
DEFAULT_BASE_URIinsemantica/provenance/manager.py
This ensures that exports from different sessions or components resolve to the same identifiers, critical for federated query scenarios.
Validation and Error Handling
Each exporter performs pre-serialization validation:
| Exporter | Validation Mechanism | Behavior |
|---|---|---|
RDFExporter |
RDFValidator.validate_rdf_syntax() |
Logs warnings, continues unless fatal |
OWLExporter |
Lightweight structural checks | Logs and filters invalid axioms |
LPGExporter |
ID uniqueness and type checks | Raises on malformed node/rels |
Validation errors are logged through the shared logging infrastructure without aborting the export unless explicitly configured.
File Output and Progress Tracking
The final pipeline stage handles physical file writing. All exporters use:
ensure_directory()— Creates parent directories as neededProgressTracker— Reports serialization progress for large graphs
From RDFExporter.export() (lines 31–41) and LPGExporter.export() (lines 11–17), the generated string or Cypher script is atomically written to the target path.
Complete Pipeline Summary
raw KG dict (entities/relationships or nodes/edges)
│
▼
normalize_graph_payload() ──► standard {entities, relationships}
│
▼
export_knowledge_graph() in methods.py ──► format detection
│
┌──────┼──────┐
▼ ▼ ▼
RDFExporter OWLExporter LPGExporter
│ │ │
▼ ▼ ▼
RDFSerializer OWL-XML/ Cypher CREATE
(Turtle/RDF Turtle statements
/JSON-LD/ (lines 42–58)
N-Triples)
│ │ │
└───────────┴───────────┘
▼
file write with
ProgressTracker
Summary
- Normalization occurs first —
normalize_graph_payload()inhelpers.pystandardizes vocabulary variants - Single entry point —
export_knowledge_graph()inmethods.pydispatches to format-specific exporters - Three exporter classes —
RDFExporter,OWLExporter, andLPGExporterhandle their respective formats - Shared infrastructure — Namespace management, validation, logging, and progress tracking are consistent across all exporters
- Line-precise locations — Key functions at lines 883–910 (
methods.py), 72–82 and 74–88 (rdf_exporter.py), 42–58 (lpg_exporter.py)
Frequently Asked Questions
How does Semantica detect which export format to use?
Semantica uses extension-based detection with optional override. The export_knowledge_graph() function inspects the file extension (*.ttl, *.cypher, *.owl) and maps it to internal format identifiers. Users can force a specific format with the format= parameter, which takes precedence over extension detection.
Can I use the exporter classes directly without the dispatcher?
Yes. While export_knowledge_graph() provides convenience, each exporter class (RDFExporter, OWLExporter, LPGExporter) exposes direct methods like export() and export_knowledge_graph(). Direct instantiation allows fine-grained control over namespace URIs, validation strictness, and serialization options.
What Cypher dialect does the LPGExporter produce?
The LPGExporter generates standard openCypher CREATE statements compatible with Neo4j and Apache AGE. The _generate_node_queries() and _generate_relationship_queries() methods produce property-bearing nodes and typed relationships without Neo4j-specific extensions, ensuring broad compatibility with labeled property graph databases.
Is there support for streaming or partial exports of large knowledge graphs?
The source analysis shows ProgressTracker integration for monitoring serialization progress, but does not indicate native streaming or chunked output. For very large graphs, users would need to partition the input dictionary before calling export_knowledge_graph(), as the current implementation normalizes and processes the complete payload in memory before file writing.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →