Importing Ontologies

Ontologies are serialised as RDF, so they can be imported using plain n10s.rdf.import.fetch but the n10s.onto.import.fetch method will give us a higher level of control over how an RDFS or OWL ontology is imported into Neo4j. It’s important to note that this procedure exclusively imports the following:

  1. Named class (category) declarations with both rdfs:Class and owl:Class.

  2. Explicit class hierarchies defined with rdf:subClassOf statements.

  3. Property definitions with owl:ObjectProperty, owl:DatatypeProperty and rdfs:Property

  4. Explicit property hierarchies defined with rdfs:subPropertyOf statements.

  5. Domain and range information for properties described as rdfs:domain and rdfs:range statements.

All other elements will be ignored by this loader.

The n10s.onto.import.fetch procedure takes the same generic params described in Common Parameters at the beginning of the Import section, so we will invoke it with a URL and a serialisation format. In the following example we will import the ontology in this file.

CALL n10s.onto.import.fetch("","Turtle");
VW ontology imported in Neo4j

We can see in the ingested graph that by default, classes are persisted as nodes with label Class with two properties: uri and name and rdf:subClassOf statements are stored as relationships of type SCO between Class nodes. Similarly, relationships will be persisted as nodes with name and uri and labels Relationship or Property for owl:ObjectProperty and owl:DatatypeProperty respectively. Statements with rdf:subPropertyOf as predicate are stored as relationships of type SPO between Relationship or Property nodes.

These graph model elements can be overridden by using the following configuration params in the Graph Config:

  • classLabel: Label to be used for Ontology Classes (categories). Default is Class.

  • subClassOfRel: Relationship to be used for rdfs:subClassOf hierarchies. Default is SCO.

  • dataTypePropertyLabel: Label to be used for DataType properties in the Ontology. Default is Property.

  • objectPropertyLabel: Label to be used for Object properties in the Ontology. Default is Relationship.

  • subPropertyOfRel: Relationship to be used for rdfs:subPropertyOf hierarchies. Default is SPO.

  • domainRel: Relationship to be used for rdfs:domain. Default is DOMAIN.

  • rangeRel: Relationship to be used for rdfs:range. Default is RANGE.

Here’s an example of how to load an ontology using some of these parameters:

CALL n10s.graphconfig.init({
  classLabel : 'Category',
  objectPropertyLabel: 'Rel',
  dataTypePropertyLabel: 'Prop'

CALL n10s.onto.import.fetch("","Turtle");

Just like we saw when importing RDF, it is possible to pass the ontology as text instead of by reference (url), the n10s.onto.import.inline procedure works in this mode. Here’s an example:

We first import a public vocabulary…​

CALL n10s.onto.import.fetch("","Turtle");

and then we extend it with some additiona statements (triples) passed as text to the n10s.onto.import.inline procedure

CALL n10s.onto.import.inline("<> <> <> .","N-Triples");

Check Reference for a complete list of available parameters.

Importing SKOS concept schemes

SKOS (Simple Knowledge Organization System) provides a model for expressing the basic structure and content of concept schemes such as thesauri, classification schemes, subject heading lists, taxonomies, folksonomies, and other similar types of controlled vocabulary. Neosemantics also provides methods (skos.import) to import SKOS concept schemes.

These methods follow the same structure and implement the same behavior as the ones for importing ontologies here is an example of inline importing a skos fragment of a taxonomy:

call n10s.skos.import.inline('

@prefix skos: <> .
@prefix rdf: <> .
@prefix ex: <> .

ex:cat rdf:type skos:Concept;
skos:prefLabel "cat"@en;
skos:prefLabel "Katze"@de;
skos:altLabel "kitten"@en;
skos:narrower ex:wildcat;
skos:broader ex:animal .

ex:wildcat rdf:type skos:Concept;
skos:prefLabel "wildcat"@en;
skos:broader ex:cat.

ex:animal rdf:type skos:Concept;
skos:prefLabel "animal"@en .


producing the following summary of execution:

│"terminationStatus"│"triplesLoaded"│"triplesParsed"│"namespaces"│"extraInfo"│"callParams"                │
│"OK"               │11             │11             │null        │""         │{"handleVocabUris":"IGNORE"}│

and on running this cypher query: MATCH p=(:Class)-[r:SCO]→() RETURN p produces the following result:

Small concept hierarchy imported in SKOS

Similarly, the .fetch version of the method can be use to retrieve a larger dataset like in the following example:

call n10s.skos.import.fetch("",
   "Turtle", { languageFilter: "es" })
│"terminationStatus"│"triplesLoaded"│"triplesParsed"│"namespaces"│"extraInfo"│"callParams"                │
│"OK"               │68519          │87191          │null        │""         │{"handleVocabUris":"IGNORE"}│

The resulting graph can be queried using cypher now. The following query shows how to find the concepts related to "Social Problems" (concept uri:

MATCH p = (:Resource { uri: ""})-[*..5]->() RETURN p limit 80
UNESCO Thesaurus in Spanish imported as SKOS