Files
KaifAhmad1 7a6f1d0417 docs: add citation section and fix stale org references
Add a Cite Us section to the README with BibTeX citation info, and
align it with docs/citation.md (author/organization: Semantica, 2026).
Update LICENSE and docs/project-license.md copyright holder to
Semantica, and replace the stale Hawksight-AI GitHub org slug with
semantica-agi across READMEs, plugin manifests, cookbook notebooks,
and GitHub templates.
2026-08-24 16:07:22 +05:30

13 KiB

Open In Colab

Export Module - Comprehensive Guide

Overview

This notebook provides a comprehensive guide to Semantica's Export Module, which enables exporting knowledge graphs, entities, relationships, and data to multiple formats. The module supports 8 export formats (RDF, JSON, CSV, Graph, YAML, OWL, Vector, LPG) plus report generation capabilities.

Documentation: API Reference

Export Module Architecture

The Export Module consists of:

Core Exporter Classes (9 classes)

  • RDFExporter - RDF format export (Turtle, RDF/XML, JSON-LD, N-Triples, N3)
  • JSONExporter - JSON and JSON-LD format export
  • CSVExporter - CSV format export for tabular data
  • GraphExporter - Graph format export (GraphML, GEXF, DOT)
  • SemanticNetworkYAMLExporter - Semantic network YAML export
  • YAMLSchemaExporter - Schema YAML export
  • OWLExporter - OWL format export for ontologies
  • VectorExporter - Vector embedding export for vector stores
  • LPGExporter - LPG format export for Neo4j, Memgraph, and similar databases

Supporting Classes (4 classes)

  • RDFSerializer - RDF serialization engine for format conversion
  • RDFValidator - RDF validation engine for syntax checking
  • NamespaceManager - RDF namespace management and conflict resolution
  • ReportGenerator - Report generation (HTML, Markdown, JSON, Text)

Registry & Configuration (2 classes + 2 instances)

  • MethodRegistry - Registry for custom export methods
  • method_registry - Global registry instance
  • ExportConfig - Configuration manager for export module
  • export_config - Global configuration instance

Learning Objectives

By the end of this notebook, you will be able to:

  • Export knowledge graphs to all supported formats (RDF, JSON, CSV, Graph, YAML, OWL, Vector, LPG)
  • Use exporter classes directly for fine-grained control
  • Generate professional reports in multiple formats
  • Register and use custom export methods
  • Configure export settings via environment variables or config files
  • Use RDF serialization, validation, and namespace management

Installation

Install Semantica from PyPI:

pip install semantica
# Or with all optional dependencies:
pip install semantica[all]

Step 1: JSON Export

Export knowledge graph to JSON format using JSONExporter class.

JSONExporter Methods:

  • export() - Export any data to JSON
  • export_knowledge_graph() - Export knowledge graph to JSON/JSON-LD
  • export_entities() - Export entities to JSON
  • export_relationships() - Export relationships to JSON
In [ ]:
!pip install semantica
In [ ]:
from semantica.export import JSONExporter
from semantica.kg import GraphBuilder

# Create exporter and builder
json_exporter = JSONExporter()
builder = GraphBuilder()

# Create sample knowledge graph
entities = [{"id": "e1", "type": "Organization", "name": "Apple Inc.", "properties": {}}]
relationships = []

kg = builder.build(entities + relationships)

# Export to JSON
json_exporter.export_knowledge_graph(kg, "output.json")

Step 2: CSV Export

Export entities and relationships to CSV format using CSVExporter class.

CSVExporter Methods:

  • export() - Export knowledge graph to CSV
  • export_entities() - Export entities to CSV file
  • export_relationships() - Export relationships to CSV file
  • export_knowledge_graph() - Export complete knowledge graph to CSV
In [ ]:
from semantica.export import CSVExporter

# Create CSV exporter
csv_exporter = CSVExporter()

# Export entities to CSV
csv_exporter.export_entities(entities, "entities.csv")

Step 3: RDF Export

Export knowledge graph to RDF format using RDFExporter class.

RDFExporter Methods:

  • export() - Export to RDF (supports multiple formats)
  • export_knowledge_graph() - Export knowledge graph to RDF
  • export_entities() - Export entities to RDF
  • export_relationships() - Export relationships to RDF

Supported RDF Formats:

  • turtle - Turtle format (human-readable)
  • rdfxml - RDF/XML format
  • jsonld - JSON-LD format
  • ntriples - N-Triples format
  • n3 - N3 format

Additional RDF Classes:

  • RDFSerializer - Serialize RDF data between formats
  • RDFValidator - Validate RDF syntax and consistency
  • NamespaceManager - Manage RDF namespaces
In [ ]:
from semantica.export import RDFExporter

# Create RDF exporter
rdf_exporter = RDFExporter()

# Export to RDF format (Turtle by default)
rdf_exporter.export(kg, "output.ttl", format="turtle")
In [ ]:
# TTL alias: format="ttl" is equivalent to format="turtle"
rdf_data = {
    "entities": [
        {"id": "e1", "text": "Apple Inc.", "type": "ORG", "confidence": 0.95},
        {"id": "e2", "text": "Steve Jobs", "type": "PERSON", "confidence": 0.97},
    ],
    "relationships": [
        {"source_id": "e2", "target_id": "e1", "type": "founded_by", "confidence": 0.91},
    ],
}

rdf_exporter.export(rdf_data, "output.ttl", format="ttl")

result = rdf_exporter.validate_rdf(rdf_data)
print(f"Valid: {result['overall_valid']}")

Step 4: Graph Export

Export to graph formats using GraphExporter class for visualization tools.

GraphExporter Methods:

  • export() - Export to graph format
  • export_knowledge_graph() - Export knowledge graph to graph format

Supported Graph Formats:

  • graphml - GraphML format (for Cytoscape, yEd, etc.)
  • gexf - GEXF format (for Gephi)
  • dot - Graphviz DOT format
In [ ]:
from semantica.export import GraphExporter

# Create graph exporter
graph_exporter = GraphExporter()

# Export to GraphML format
graph_exporter.export_knowledge_graph(kg, "output.graphml", format="graphml")

Step 5: OWL Export

Export ontologies to OWL format using OWLExporter class.

OWLExporter Methods:

  • export() - Export ontology to OWL
  • export_ontology() - Export complete ontology
  • export_classes() - Export class definitions only
  • export_properties() - Export property definitions only

Supported OWL Formats:

  • owl-xml - OWL/XML format (default)
  • turtle - OWL in Turtle format

Note: OWLExporter expects an ontology structure (with classes, properties), not a knowledge graph. Use OntologyGenerator to convert a knowledge graph to an ontology first.

In [ ]:
from semantica.export import OWLExporter
from semantica.ontology import OntologyGenerator

# Create OWL exporter and ontology generator
owl_exporter = OWLExporter()
generator = OntologyGenerator()

# Generate ontology from entities and relationships
# Note: Pass data as a dictionary to generate_ontology
ontology = generator.generate_ontology({
    "entities": entities,
    "relationships": relationships
})

# Export ontology to OWL
owl_exporter.export(ontology, "output.owl")

Step 6: Additional Export Formats

YAML Export

Export to YAML format using YAML exporters:

YAML Exporter Classes:

  • SemanticNetworkYAMLExporter - Export semantic networks to YAML
  • YAMLSchemaExporter - Export ontology schemas to YAML

Vector Export

Export vector embeddings using VectorExporter:

VectorExporter Methods:

  • export() - Export vectors to various formats

Supported Vector Formats:

  • json - JSON format
  • numpy - NumPy format
  • binary - Binary format
  • faiss - FAISS format

LPG Export

Export to Labeled Property Graph format using LPGExporter:

LPGExporter Methods:

  • export() - Export to LPG format
  • export_knowledge_graph() - Export knowledge graph to LPG

Supported LPG Formats:

  • cypher - Cypher query format (for Neo4j, Memgraph)
  • lpg - Labeled Property Graph format

Report Generation

Generate professional reports using ReportGenerator:

ReportGenerator Methods:

  • generate_report() - Generate report in various formats

Supported Report Formats:

  • html - HTML report
  • markdown - Markdown report
  • json - JSON report
  • text - Plain text report

Summary

You've learned how to export data using Semantica's Export Module:

Core Exporter Classes:

  • JSONExporter: Export to JSON/JSON-LD format
  • CSVExporter: Export to CSV format
  • RDFExporter: Export to RDF format (Turtle, RDF/XML, JSON-LD, N-Triples, N3)
  • GraphExporter: Export to graph formats (GraphML, GEXF, DOT)
  • OWLExporter: Export ontologies to OWL
  • VectorExporter: Export vectors to multiple formats
  • LPGExporter: Export to Labeled Property Graph format
  • SemanticNetworkYAMLExporter: Export semantic networks to YAML
  • YAMLSchemaExporter: Export schemas to YAML

Supporting Classes:

  • RDFSerializer: RDF format conversion
  • RDFValidator: RDF validation
  • NamespaceManager: RDF namespace management
  • ReportGenerator: Generate professional reports

Registry & Configuration:

  • MethodRegistry: Register custom export methods
  • ExportConfig: Configure export settings
  • method_registry: Global registry instance for accessing registered methods
  • export_config: Global configuration instance for export settings

Next Steps: