Import Individuals and relate to Classes in Neo4j


I am trying to import Individuals into Neo4j and relate them to their corresponding Class. See the following figure that represents the result I am aiming to achieve.

In this case the Ontology file is an RDF where the Individuals are defined as follows:


In order to import the Ontology I am using the following Cypher query (plugin version

CALL semantics.importRDF("file:/...","RDF/XML", { handleVocabUris: "IGNORE" })

With this, the Individuals are imported into the database with the corresponding URI and new neo4j-labels. Among these new labels there is one for the element type ('NamedIndividual') and another one for the Class it corresponds to (e.g: 'Car' for 'Car1'). However, they are not related to any other element of the main Ontology.

Any suggestion or comment will be much appreciated,

Thank you


Kaixo Itziar!
By default all rdf:type triples are transformed into labels when imported into Neo4j but you can change this behaviour using the typesToLabels parameter. Let me show it to you with an example.
You will need to import your ontology and your instance data separately.

Let's say this is your ontology vehicle-classes.owl:

@prefix : <> .

:Automobile rdf:type owl:Class ;
            rdfs:label "Automobile" .

:Compact rdf:type owl:Class ;
       rdfs:subClassOf :Automobile ;
       rdfs:label "Compact" .           

:Convertible rdf:type owl:Class ;
             rdfs:subClassOf :Automobile ;
       		 rdfs:label "Convertible" .     

:Wagon rdf:type owl:Class ;
       rdfs:subClassOf :Automobile ;
       rdfs:label "Wagon" .      

You can import it just like you were doing:

CALL semantics.importRDF('file:///...vehicle-classes.owl',"Turtle", { handleVocabUris: "IGNORE" })

which will import something like this in your graph:

Now your instances (individuals) could look something like this (vehicle-individuals.rdf):

@prefix voc: <> .
@prefix ind: <> .       

ind:Golf_GTI_Autobahn rdf:type owl:NamedIndividual ,
                            voc:Compact ;
                   voc:hasEngine ind:2.0L_Turbo ;
                   rdfs:label "Golf GTI Autobahn" .         		 

ind:Golf_GTI_Rabbit_Edition rdf:type owl:NamedIndividual ,
                                  voc:Compact ;
                         voc:hasEngine ind:2.0L_Turbo ;
                         rdfs:label "Golf GTI Rabbit Edition" .                   

ind:Beetle_Convertible rdf:type owl:NamedIndividual ,
                                  voc:Convertible ;
                         voc:hasEngine ind:1.4L ;
                         rdfs:label "Beetle Convertible" .       

You need to import them by adding the additional config parameter typesToLabels: false to indicate that you don't want the rdf:type triples to be transformed into labels but rather imported as relationships connecting the individuals to their class:

CALL semantics.importRDF('file:///...vehicle-individuals.rdf',"Turtle", { handleVocabUris: "IGNORE" , typesToLabels: false })

Which will create the individuals and attach them to the previously imported classes.

You will notice that the other types (owl:NamedIndividual in this case) are also imported as relationships but you can delete these post-import if they're not needed.

I hope this helps. Let me know if there is anything unclear.