map owl file into neo4j - getOrCreateNodeWithUniqueFactory method
Asked Answered
E

2

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?

Erlina answered 17/12, 2013 at 10:10 Comment(3)
That looks like a private method in a neo4j class: (link here)[grepcode.com/file/repo1.maven.org/maven2/com.impetus.client/…. 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.Rebba
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.Erlina
Is it on GitHub? I'm ignazio1977 thereRebba
D
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.

Divalent answered 20/12, 2013 at 15:22 Comment(1)
The first link which contains the tutorial doesn't work now. Can I get any other kind of help?Doormat
E
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);
    }
Erlina answered 19/3, 2014 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.