Search code examples
javaneo4jowl

map owl file into neo4j - getOrCreateNodeWithUniqueFactory method


I try to move an ontology (*.owl file) into neo4j to do queries on it. I found some helpful information here but I am facing with issues in this line:

Node thingNode = getOrCreateNodeWithUniqueFactory("owl:Thing");

I don't know to which class the "getOrCreateNodeWithUniqueFactory" belongs. Is this available in some library or should I implement it by myself?

What am I missing here?


Solution

  • There are several ways to create unique nodes. The probably easiest is to use the UniqueFactory as seen in the Neo4j docs under http://docs.neo4j.org/chunked/milestone/tutorials-java-embedded-unique-nodes.html#tutorials-java-embedded-unique-get-or-create-with-factory. Another one would be using cypher constraints (see: http://components.neo4j.org/neo4j/2.0.0/apidocs/org/neo4j/graphdb/event/TransactionEventHandler.html). Finally there's the possibility to store your created nodes in a map (via a TransactionEventHandler) and look it up there before creating a new one. With owl it would make sense to enter the IRI as key and the id of the created node as value. This way would be faster but more sensible than the unique factory.