4

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?

trojek
  • 3,078
  • 2
  • 29
  • 52
  • That looks like a private method in a neo4j class: (link here)[http://grepcode.com/file/repo1.maven.org/maven2/com.impetus.client/kundera-neo4j/2.4/com/impetus/client/neo4j/GraphEntityMapper.java#GraphEntityMapper.getOrCreateNodeWithUniqueFactory%28java.lang.Object%2Cjava.lang.Object%2Ccom.impetus.kundera.metadata.model.EntityMetadata%2Corg.neo4j.graphdb.GraphDatabaseService%29]. I'm not sure you should be relying on this code, it's private code and to use it your code should be inside the GraphDatabaseService. Please show more of your code, or providing suggestions will be hard. – Ignazio Dec 17 '13 at 22:13
  • I think is not the method from link - it takes to many arguments. Please give me your email and I'll send you invitation to the repository. I'm almost sure that i have to create this method by myself. – trojek Dec 18 '13 at 09:37
  • Is it on GitHub? I'm ignazio1977 there – Ignazio Dec 18 '13 at 12:00

2 Answers2

2

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.

funglejunk
  • 288
  • 2
  • 9
2

I implemented method: getOrCreateNodeWithUniqueFactory

private static Node getOrCreateNodeWithUniqueFactory(String nodeName,
            GraphDatabaseService graphDb) {
        UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory(
                graphDb, "index") {
            @Override
            protected void initialize(Node created,
                    Map<String, Object> properties) {
                created.setProperty("name", properties.get("name"));
            }
        };

        return factory.getOrCreate("name", nodeName);
    }
trojek
  • 3,078
  • 2
  • 29
  • 52