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

Semantica provides dedicated exporters in semantica/export/ that serialize knowledge graphs to Parquet via ParquetExporter, RDF/OWL via RDFExporter, and Cypher via LPGExporter, each with explicit schemas, namespace management, and validation hooks.

The semantica-agi/semantica repository ships with a modular export layer capable of converting internal knowledge graph structures into four critical interchange formats. Mastering how to export knowledge graphs from Semantica to RDF, OWL, Parquet, and Cypher formats enables seamless integration with semantic web tools, columnar data warehouses, and graph databases like Neo4j.

Exporting to Parquet with ParquetExporter

The ParquetExporter class in semantica/export/parquet_exporter.py serializes entities and relationships into compressed Apache Arrow tables using explicit schemas.

Arrow Schema Definitions

The exporter defines strict Arrow schemas (ENTITY_SCHEMA and RELATIONSHIP_SCHEMA) to ensure type safety without inference. These schemas map entity fields like label to text, handle nullable strings, and store metadata as structs.


# semantica/export/parquet_exporter.py

ENTITY_SCHEMA = pa.schema([
    pa.field("id", pa.string(), nullable=False),
    pa.field("text", pa.string(), nullable=True),
    pa.field("metadata", pa.struct([
        pa.field("keys", pa.list_(pa.string())),
        pa.field("values", pa.list_(pa.string())),
    ]), nullable=True),
])

Writing Compressed Columnar Files

The export_knowledge_graph() method normalizes the input dictionary, validates IDs, and writes to .parquet files using pa.Table.from_pylist() followed by pq.write_table(). Compression options include snappy, gzip, and zstd.

from semantica.export import ParquetExporter

# Initialize with optional compression

exporter = ParquetExporter(compression="snappy")

# Export produces: output/kg_entities.parquet and output/kg_relationships.parquet

exporter.export_knowledge_graph(kg, "output/kg")

Serializing to RDF and OWL with RDFExporter

The RDFExporter class in semantica/export/rdf_exporter.py handles semantic web serialization, including OWL-compatible Turtle output through namespace management.

Namespace Management and Validation

The exporter uses NamespaceManager (lines 41-84) to handle prefix-to-URI mappings and resolve conflicts. RDFValidator runs syntax, namespace, and consistency checks before serialization begins.

Format Dispatch

The export_to_rdf() method dispatches to format-specific serializers based on the format parameter:

  • turtle → serialize_to_turtle()
  • rdfxml → serialize_to_rdfxml()
  • jsonld → serialize_to_jsonld()
  • ntriples → serialize_to_ntriples()

# From semantica/export/rdf_exporter.py

if format == "turtle":
    result = self.serializer.serialize_to_turtle(...)
elif format == "rdfxml":
    result = self.serializer.serialize_to_rdfxml(...)
elif format == "jsonld":
    result = self.serializer.serialize_to_jsonld(...)
elif format == "ntriples":
    result = self.serializer.serialize_to_ntriples(...)

OWL Compatibility and Temporal Data

OWL ontologies are produced by utilizing the owl namespace within Turtle output. Setting include_temporal=True injects OWL-Time namespace triples (time) for temporal bounds, creating OWL-compatible RDF graphs without requiring a separate exporter.

from semantica.export import RDFExporter

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

Generating Cypher Scripts with LPGExporter

For graph database ingestion, the LPGExporter (exposed via semantica/export/methods.py) generates Cypher CREATE statements compatible with Neo4j and Memgraph.

Literal Conversion and Statement Generation

The exporter relies on helper functions _value_to_cypher_literal() and _props_to_cypher_literal() from semantica/graph_store/age_store.py (lines 113-138) to convert Python values into Cypher-safe syntax. It normalizes entities into nodes and relationships into edges, outputting executable .cypher files.

from semantica.export import export_knowledge_graph

# Generates output/graph.cypher with CREATE statements

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

Example output 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);

Unified Export Interface

The export_knowledge_graph() helper in semantica/export/methods.py serves as a unified dispatcher. It accepts a format parameter ("parquet", "rdf", "cypher", etc.) and routes to the appropriate exporter class, handling ProgressTracker integration for long-running operations.

from semantica.export import export_knowledge_graph

# Parquet via dispatcher

export_knowledge_graph(kg, "output/data", format="parquet")

# RDF JSON-LD via dispatcher

export_knowledge_graph(kg, "output/data.jsonld", format="rdf", rdf_format="jsonld")

Summary

  • Parquet exports use ParquetExporter with explicit Apache Arrow schemas (ENTITY_SCHEMA, RELATIONSHIP_SCHEMA) and configurable compression.
  • RDF/OWL exports utilize RDFExporter with NamespaceManager for prefix handling and support Turtle, RDF/XML, JSON-LD, and N-Triples; OWL compatibility is achieved through the owl namespace and optional temporal triples.
  • Cypher exports are handled by LPGExporter via the unified interface, generating executable Cypher scripts using literal conversion helpers from age_store.py.
  • All exporters validate input structures and integrate with Semantica's ProgressTracker for cancellation support.

Frequently Asked Questions

Which exporter should I use for Neo4j?

Use the Cypher exporter by calling export_knowledge_graph(..., format="cypher") or instantiating LPGExporter directly. This produces a .cypher file containing CREATE statements for nodes and relationships that can be executed directly in Neo4j or Memgraph using their standard import tools.

Can I export temporal data to OWL format?

Yes. When using RDFExporter.export() with format="turtle" and include_temporal=True, the serializer automatically injects OWL-Time namespace triples and temporal bound assertions. This creates OWL-compatible output suitable for temporal reasoning in semantic web applications.

What schema does the Parquet exporter use?

The ParquetExporter uses explicit Arrow schemas defined in semantica/export/parquet_exporter.py: ENTITY_SCHEMA requires a non-nullable id string and nullable text field, while RELATIONSHIP_SCHEMA enforces source_id, target_id, and type fields. Metadata is stored as a struct of key-value lists to preserve arbitrary properties.

How do I handle validation errors during export?

Each exporter includes validation logic: RDFExporter uses RDFValidator for syntax and namespace checks, while ParquetExporter validates ID existence and type consistency. If validation fails, exporters raise exceptions before writing output. Wrap calls in try-except blocks to catch these errors, or pre-validate your knowledge graph using Semantica's validation utilities.

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 →