# How to Export Knowledge Graphs from Semantica to RDF, OWL, Parquet, and GraphML

> Export knowledge graphs from Semantica to RDF, OWL, Parquet, and GraphML. Learn how to use dedicated exporter classes for seamless data serialization and access.

- Repository: [Semantica /semantica](https://github.com/semantica-agi/semantica)
- Tags: how-to-guide
- Published: 2026-08-16

---

**Semantica provides dedicated exporter classes—`ParquetExporter`, `RDFExporter`, and `LPGExporter`—that serialize knowledge graphs into Parquet, RDF/OWL, and Cypher formats respectively, all accessible through a unified `export_knowledge_graph()` dispatcher.**

The Semantica framework (available at `semantica-agi/semantica`) includes a modular export layer designed for high-fidelity interchange with downstream analytics tools. Whether you need columnar storage for data science workflows, semantic web compatibility for ontology-driven applications, or graph database ingestion scripts, the export modules handle validation, normalization, and format-specific serialization automatically.

---

## Export Architecture Overview

All exporters in `semantica/export/` follow a consistent pattern:

1. **Input validation** — ensure the knowledge graph contains required `entities` and `relationships` keys with valid identifiers
2. **Schema normalization** — convert internal Python dictionaries to format-specific representations
3. **Progress tracking** — integrate with Semantica's `ProgressTracker` for cancellable long-running operations
4. **Serialization** — write to file or return in-memory strings

The high-level entry point `export_knowledge_graph()` in [`semantica/export/methods.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/methods.py) routes to the appropriate backend based on the `format` parameter.

---

## Exporting to Parquet Format

The **ParquetExporter** class in [`semantica/export/parquet_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/parquet_exporter.py) provides columnar storage optimized for analytical queries.

### Key Implementation Details

- Built on **Apache Arrow/PyArrow** for zero-copy operations
- Uses **explicit schemas** (`ENTITY_SCHEMA`, `RELATIONSHIP_SCHEMA`) to eliminate type inference overhead
- Splits output into two files: `{base}_entities.parquet` and `{base}_relationships.parquet`

### Schema Definition

```python

# 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("type", pa.string(), nullable=True),
    pa.field("confidence", pa.float64(), nullable=True),
    pa.field("metadata", pa.struct([
        pa.field("keys", pa.list_(pa.string())),
        pa.field("values", pa.list_(pa.string())),
    ]), nullable=True),
])

```

### Code Example

```python
from semantica.export import ParquetExporter

# Initialize with optional compression: "snappy", "gzip", "brotli", or "none"

exporter = ParquetExporter(compression="snappy")

# Export knowledge graph to Parquet files

exporter.export_knowledge_graph(
    kg,                          # dict with "entities" and "relationships"

    output_path="output/kg"      # creates kg_entities.parquet and kg_relationships.parquet

)

```

The `export_entities()` and `export_relationships()` methods allow separate handling of each component for incremental pipelines.

---

## Exporting to RDF and OWL Formats

The **RDFExporter** class in [`semantica/export/rdf_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/rdf_exporter.py) handles multiple RDF serialization formats and OWL-compatible output.

### Core Components

| Component | Class | Purpose |
|-----------|-------|---------|
| Namespace management | `NamespaceManager` | URI prefix resolution and conflict handling |
| Validation | `RDFValidator` | Syntax, namespace, and consistency checks |
| Serialization | `RDFSerializer` | Format-specific output generation |

### Supported Formats

The `export()` and `export_to_rdf()` methods accept these format strings:

- `"turtle"` — Terse, human-readable (`.ttl`)
- `"rdfxml"` — Standard RDF/XML (`.rdf`)
- `"jsonld"` — JSON-LD with `@context` (`.jsonld`)
- `"ntriples"` — Line-based N-Triples (`.nt`)

### Format Dispatch Logic

```python

# semantica/export/rdf_exporter.py (lines 69-78 in RDFExporter.export_to_rdf)

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

```

### Generating OWL-Compatible Output

OWL ontologies are valid RDF graphs using the `owl:` namespace. Enable OWL-Time temporal annotations with `include_temporal=True`:

```python
from semantica.export import RDFExporter

rdf_exporter = RDFExporter()

# Turtle output with OWL-Time extensions for temporal bounds

rdf_exporter.export(
    kg,
    "output/ontology.ttl",
    format="turtle",
    include_temporal=True  # adds time:Interval, time:hasBeginning, etc.

)

```

The serializer automatically includes required prefixes: `rdf`, `rdfs`, `xsd`, `owl`, `time`, and `semantica`.

---

## Exporting to Cypher Format (GraphML/Neo4j)

For **Cypher-compatible output**, Semantica uses the **LPGExporter** (Labeled Property Graph) accessible through `export_knowledge_graph(..., format="cypher")`.

### Implementation Path

- High-level routing: [`semantica/export/methods.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/methods.py)
- Literal conversion helpers: [`semantica/graph_store/age_store.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/graph_store/age_store.py) (`_value_to_cypher_literal`, `_props_to_cypher_literal`)

### Generated Cypher Structure

The exporter produces `CREATE` statements with proper escaping:

```cypher
// Example output from LPGExporter
CREATE (n0:Person {id: "ent_001", name: "Alice", confidence: 0.95});
CREATE (n1:Organization {id: "ent_002", name: "Acme Corp"});
MATCH (a:Person {id: "ent_001"}), (b:Organization {id: "ent_002"})
CREATE (a)-[:WORKS_AT {since: "2021-03-15", confidence: 0.87}]->(b);

```

### Code Example

```python
from semantica.export import export_knowledge_graph

# Using the unified dispatcher

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

# Or direct LPGExporter for advanced options

from semantica.export.methods import LPGExporter

lpg = LPGExporter()
lpg.export_knowledge_graph(kg, "output/graph.cypher", batch_size=1000)

```

---

## Complete Export Reference Table

| Target Format | Exporter Class | Primary Method | File Extension | Key Parameters |
|-------------|--------------|--------------|---------------|--------------|
| **Parquet** | `ParquetExporter` | `export_knowledge_graph()` | `.parquet` | `compression`, `schema_version` |
| **RDF/Turtle** | `RDFExporter` | `export(format="turtle")` | `.ttl` | `base_uri`, `include_temporal` |
| **RDF/JSON-LD** | `RDFExporter` | `export(format="jsonld")` | `.jsonld` | `base_uri` |
| **RDF/XML** | `RDFExporter` | `export(format="rdfxml")` | `.rdf` | `base_uri` |
| **N-Triples** | `RDFExporter` | `export(format="ntriples")` | `.nt` | `base_uri` |
| **Cypher/LPG** | `LPGExporter` | `export_knowledge_graph()` | `.cypher` | `batch_size` |

---

## Key Source Files

Understanding these files enables custom exporter development:

- **[`semantica/export/parquet_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/parquet_exporter.py)** — Arrow schema definitions, PyArrow table construction, and Parquet write operations with configurable compression

- **[`semantica/export/rdf_exporter.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/rdf_exporter.py)** — `NamespaceManager` for URI prefix handling, `RDFSerializer` with format-specific methods, and `RDFValidator` for pre-flight checks

- **[`semantica/export/methods.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/methods.py)** — The `export_knowledge_graph()` dispatcher that routes to `ParquetExporter`, `RDFExporter`, or `LPGExporter` based on the `format` parameter

- **[`semantica/graph_store/age_store.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/graph_store/age_store.py)** — Helper functions `_value_to_cypher_literal()` and `_props_to_cypher_literal()` for safe Cypher string construction

- **[`semantica/export/export_provenance.py`](https://github.com/semantica-agi/semantica/blob/main/semantica/export/export_provenance.py)** — Optional wrapper for adding audit trails to any export operation

---

## Summary

- **Parquet export** uses explicit Arrow schemas in `ParquetExporter` for type-safe columnar storage, splitting entities and relationships into separate files

- **RDF/OWL export** through `RDFExporter` supports Turtle, JSON-LD, RDF/XML, and N-Triples; OWL compatibility requires using `owl:` prefixed terms in source data and enabling `include_temporal` for OWL-Time extensions

- **Cypher export** routes through `LPGExporter` via the unified `export_knowledge_graph(..., format="cypher")` helper, generating executable `CREATE` and `MATCH` statements

- All exporters validate input, normalize data structures, and integrate with Semantica's progress tracking system for production reliability

---

## Frequently Asked Questions

### What is the difference between RDF and OWL export in Semantica?

Semantica does not provide a separate OWL exporter. OWL ontologies are valid RDF graphs that use the `owl:` namespace. When you export to Turtle or JSON-LD format with `RDFExporter`, include OWL vocabulary terms (like `owl:Class` or `owl:ObjectProperty`) in your entity and relationship definitions. Enable `include_temporal=True` to automatically add OWL-Time compatible temporal annotations.

### Can I export a knowledge graph to multiple formats in one operation?

Yes. Instantiate each exporter separately and call their export methods sequentially on the same `kg` dictionary. The exporters are stateless with respect to the input data—they only maintain configuration (compression, base URI, etc.). For batch pipelines, wrap multiple exports in a loop over format strings using the `export_knowledge_graph()` dispatcher.

### How does Semantica handle large knowledge graphs during export?

All exporters integrate with Semantica's `ProgressTracker` for chunked processing and cancellation support. The `ParquetExporter` uses PyArrow's streaming `RecordBatch` construction. For Cypher export, use the `batch_size` parameter in `LPGExporter.export_knowledge_graph()` to control transaction size. Tested exports handle millions of entities and relationships without memory exhaustion.

### What validation occurs before export?

Each exporter runs format-specific validation: `ParquetExporter` checks that all entities have string `id` fields and that metadata structures are consistent; `RDFExporter` runs namespace conflict resolution and RDF syntax validation through `RDFValidator`; `LPGExporter` validates that relationship source and target IDs exist in the entity set. Validation failures raise `ExportValidationError` with detailed messages before any file write occurs.