Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/jbarrasa/goingmeta/llms.txt

Use this file to discover all available pages before exploring further.

Session 18 of Going Meta, broadcast on July 4, 2023, tackles a question that arises whenever organisations evaluate Neo4j alongside existing RDF infrastructure: can you move a full knowledge graph — ontology, data, and all — out of a triple store and into Neo4j without losing fidelity? Jesus Barrasa walks through Python notebooks that do exactly this for three popular RDF stores: Stardog (Apache Jena-based), Ontotext GraphDB, and Amazon Neptune, using rdflib and neosemantics.

What You’ll Learn

  • How to extract a full RDF graph from Stardog, Ontotext GraphDB, or Amazon Neptune via their SPARQL endpoints
  • How to load the exported data into Neo4j using neosemantics (n10s)
  • How to verify that the migrated graph on the Neo4j side is identical to the source
  • How to cross-check data with equivalent SPARQL and Cypher queries

Migration Targets Covered

Stardog (Apache Jena)

The first part of the notebook demonstrates exporting data from a Stardog instance and importing it into Neo4j, using the music/Nirvana tutorial dataset.

Ontotext GraphDB

The second part covers migration from GraphDB using the Industry 4.0 Standards Ontology (I4.0KG), a production-grade semantic dataset.

Amazon Neptune

A companion notebook (neptune_migration.ipynb) demonstrates the same pattern against an Amazon Neptune SPARQL endpoint, using a CONSTRUCT query to extract all triples and load them into Neo4j via the Python driver.

Step-by-Step Walkthrough

1

Explore source data with SPARQL (Stardog)

Before migrating, verify the source data by running SPARQL queries directly against Stardog Studio. For example, to inspect all triples about Nirvana:
SELECT ?p ?o
WHERE {
  <http://stardog.com/tutorial/Nirvana_(band)>  ?p ?o
}
Then check everything related to a specific song:
SELECT ?s ?p ?o
WHERE {
  ?s ?p ?o
  FILTER (?s = <http://stardog.com/tutorial/Shake_It_Off>
       || ?o = <http://stardog.com/tutorial/Shake_It_Off>)
}
2

Run the migration notebook (Part 1 — Stardog)

Execute the first section of the Python notebook (Easy_full_graph_migration_from_triple_stores.ipynb). The notebook uses rdflib to pull the full graph from Stardog and neosemantics to insert it into Neo4j.
3

Verify the migration in Neo4j (Cypher)

After the migration, confirm the data landed correctly by querying for the same “Shake It Off” subgraph in Cypher:
MATCH subgraph = (:Resource { uri: "http://stardog.com/tutorial/Shake_It_Off" })--()
RETURN subgraph
You can also export the Neo4j data back as RDF N-Triples to compare with the source:
:post /rdf/neo4j/cypher
{
  "cypher": "MATCH (r:Resource {uri: 'http://stardog.com/tutorial/Shake_It_Off'})-[rel]-() RETURN r, rel",
  "format": "N-Triples"
}
4

Run the migration notebook (Part 2 — Ontotext)

Execute the second section of the notebook to migrate data from the Ontotext GraphDB I4.0KG endpoint. You can test the source with a SPARQL query on the public endpoint:
PREFIX sto: <https://w3id.org/i40/sto#>
SELECT DISTINCT ?s ?p ?o
WHERE {
  ?s ?p ?o
  FILTER (?s = sto:StandardOrganization)
}
5

Verify the Ontotext migration in Neo4j

After the Ontotext migration, use the neosemantics RDF endpoint to export the sto:StandardOrganization node and its outgoing relationships as N-Triples, then diff against the SPARQL results:
:post /rdf/i40kg/cypher
{
  "cypher": "MATCH (r:Resource {uri: 'https://w3id.org/i40/sto#StandardOrganization'})-[rel]->() RETURN r, rel",
  "format": "N-Triples"
}

Why This Matters

Full-Fidelity Migration

neosemantics preserves RDF semantics — classes, properties, and ontology axioms — so you don’t lose meaning when moving to Neo4j’s property graph model.

Bidirectional Verification

Exporting the Neo4j graph back as RDF N-Triples lets you byte-compare against the original triple store, giving high confidence in migration completeness.

Works Across Vendors

The same Python notebook pattern works with any SPARQL 1.1-compliant triple store — not just Stardog, Ontotext, and Amazon Neptune.

Preserves Ontology Structure

Class hierarchies, property domains/ranges, and OWL axioms are imported alongside data, so ontology-based reasoning remains possible in Neo4j.
The main Python notebook for this session is session18/Easy_full_graph_migration_from_triple_stores.ipynb — Part 1 covers Stardog, Part 2 covers Ontotext. A separate companion notebook session18/neptune_migration.ipynb covers Amazon Neptune.

Resources

Watch the Recording

Full session recording on YouTube — July 4, 2023.

Session Code

Python notebook and Cypher queries on GitHub.

Build docs developers (and LLMs) love