How to Export Knowledge Graphs from Semantica to RDF, OWL, Parquet, and Cypher Formats

Semantica exports knowledge graphs to Parquet, RDF/OWL, and Cypher using the ParquetExporter, RDFExporter, and LPGExporter classes located in semantica/export/, each providing explicit schema validation, namespace management, and format-specific serialization.

The semantica-agi/semantica repository provides a dedicated export layer that converts internal knowledge graph structures—standard Python dictionaries containing entities and relationships keys—into four industry-standard interchange formats. Understanding how to leverage these exporters allows you to move data seamlessly from Semantica into columnar warehouses, semantic web triplestores, and labeled property graph (LPG) databases.

Parquet Export with Apache Arrow Schemas

The ParquetExporter class in semantica/export/parquet_exporter.py serializes knowledge graphs to Apache Parquet files using explicit PyArrow schemas rather than runtime type inference. This ensures consistent column types across exports and eliminates schema drift.

The exporter defines two constants—ENTITY_SCHEMA and RELATIONSHIP_SCHEMA—that map Semantica’s internal fields to Arrow types:

  • id → pa.string() (non-nullable)
  • text → pa.string() (nullable)
  • metadata → pa.struct() containing keys and values lists

When you call export_knowledge_graph(), the method normalizes entity dictionaries (mapping fields like label to text) and writes two separate files: <base>_entities.parquet and <base>_relationships.parquet.

from semantica.export import ParquetExporter

# Initialize with optional compression: none, snappy, gzip, brotli, lz4, zstd

exporter = ParquetExporter(compression="snappy")

# Export the complete knowledge graph

exporter.export_knowledge_graph(
    kg={"entities": [...], "relationships": [...]}, 
    output_base_path="output/knowledge_graph"
)

The underlying implementation uses pa.Table.from_pylist(data, schema=schema) followed by pq.write_table(), ensuring efficient columnar storage compatible with pandas, Polars, and BigQuery.

RDF and OWL Serialization

For semantic web integration, semantica/export/rdf_exporter.py contains the RDFExporter class. This exporter supports Turtle (.ttl), RDF/XML (.rdf), JSON-LD (.jsonld), and N-Triples (.nt) through the RDFSerializer inner class.

The architecture follows three stages:

  1. Validation: RDFValidator checks syntax, namespace collisions, and consistency constraints
  2. Namespace Resolution: NamespaceManager handles prefix-to-URI mappings and resolves conflicts automatically
  3. Serialization: Format-specific methods like serialize_to_turtle() or serialize_to_jsonld() emit the final triples

OWL compatibility is achieved by emitting Turtle output that includes the OWL vocabulary. When you set include_temporal=True, the exporter automatically injects the OWL-Time namespace (time:) and generates OWL-compatible triples for temporal bounds alongside standard RDF assertions.

from semantica.export import RDFExporter

rdf_exporter = RDFExporter()

# Export to Turtle with OWL-Time extensions for temporal data

rdf_exporter.export(
    kg, 
    "output/ontology.ttl", 
    format="turtle", 
    include_temporal=True
)

# Alternative formats: "rdfxml", "jsonld", "ntriples"

rdf_exporter.export_to_rdf(kg, format="jsonld")

The NamespaceManager (lines 41-84 in the source) ensures that prefixes like semantica:, rdf:, xsd:, and owl: are correctly mapped and disambiguated during export.

Cypher Export for Neo4j and Memgraph

Semantica generates Cypher CREATE statements through the LPGExporter class, accessible via the high-level export_knowledge_graph() helper in semantica/export/methods.py. When you specify format="cypher", the dispatcher routes the request to the LPG exporter, which constructs a Cypher script containing CREATE clauses for nodes and relationships.

The implementation relies on literal conversion utilities defined in semantica/graph_store/age_store.py:

  • _value_to_cypher_literal(): Converts Python scalars (str, int, float, bool) to Cypher syntax
  • _props_to_cypher_literal(): Serializes property dictionaries with proper escaping and type annotations
from semantica.export import export_knowledge_graph

# Write a complete Cypher script ready for neo4j-admin import

export_knowledge_graph(
    kg, 
    "output/graph.cypher", 
    format="cypher"
)

The resulting .cypher file follows this structure:

CREATE (n:Person {id: "p1", name: "Alice", confidence: 0.98});
CREATE (n:Organization {id: "o1", name: "Acme Corp"});
MATCH (a:Person {id: "p1"}), (b:Organization {id: "o1"})
CREATE (a)-[:EMPLOYED_BY {since: "2020-01-01"}]->(b);

Complete Export Examples

Below are standalone implementations demonstrating each export path for a knowledge graph with entities and relationships.

Parquet with Gzip Compression:

from semantica.export import ParquetExporter

pq_exporter = ParquetExporter(compression="gzip")
pq_exporter.export_entities(kg["entities"], "output/entities.parquet")
pq_exporter.export_relationships(kg["relationships"], "output/relationships.parquet")

RDF/OWL with Custom Namespace:

from semantica.export import RDFExporter

exporter = RDFExporter()

# The exporter automatically includes semantica:, rdf:, rdfs:, owl:, and xsd: prefixes

exporter.export(kg, "output/graph.nt", format="ntriples")

Cypher with Explicit LPGExporter:

from semantica.export.methods import LPGExporter

lpg = LPGExporter()

# This bypasses the generic dispatcher for direct access to LPG-specific options

lpg.export_knowledge_graph(kg, "output/neo4j_import.cypher")

Provenance-Aware Export:

All exporters support optional provenance tracking via semantica/export/export_provenance.py, which wraps any export operation with audit metadata including timestamps, source versions, and transformation lineage.

Summary

  • Parquet: Use ParquetExporter in semantica/export/parquet_exporter.py with predefined Arrow schemas (ENTITY_SCHEMA, RELATIONSHIP_SCHEMA) for type-safe columnar storage.
  • RDF/OWL: Use RDFExporter in semantica/export/rdf_exporter.py with format="turtle" and include_temporal=True for OWL-compatible semantic web output; supports JSON-LD, RDF/XML, and N-Triples via RDFSerializer.
  • Cypher: Use the export_knowledge_graph() helper in semantica/export/methods.py with format="cypher" to generate Neo4j-compatible scripts, leveraging literal conversion helpers in semantica/graph_store/age_store.py.
  • Validation: All paths include pre-export validation (RDFValidator for RDF, schema checks for Parquet) and integrate with Semantica’s ProgressTracker for long-running operations.

Frequently Asked Questions

How do I export to OWL specifically?

OWL is a vocabulary built on RDF, so you use the same RDFExporter with format="turtle". Ensure your knowledge graph includes OWL-specific types (e.g., owl:Class, owl:ObjectProperty) in the entity metadata, and set include_temporal=True to automatically inject OWL-Time ontologies for temporal bounds.

Can I customize the Parquet schema or compression codec?

Yes. The ParquetExporter constructor accepts a compression parameter supporting "none", "snappy", "gzip", "brotli", "lz4", and "zstd". While the column schema is fixed as ENTITY_SCHEMA and RELATIONSHIP_SCHEMA in semantica/export/parquet_exporter.py, you can filter fields prior to export or subclass the exporter to modify the Arrow schema definitions.

Is there a single unified entry point for all export formats?

Yes. The export_knowledge_graph() function in semantica/export/methods.py acts as a dispatcher. Pass format="parquet", format="rdf", or format="cypher" to route to the appropriate exporter without instantiating specific classes manually.

How does Semantica handle RDF namespace conflicts during export?

The NamespaceManager class in semantica/export/rdf_exporter.py automatically detects prefix collisions and resolves them by appending numeric indices (e.g., ns1:, ns2:) while maintaining the correct URI mappings in the output document’s header.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →