map owl file into neo4j - getOrCreateNodeWithUniqueFactory method

血红的双手。 提交于 2019-12-06 04:19:32

问题


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?


回答1:


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.




回答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);
    }


来源:https://stackoverflow.com/questions/20631257/map-owl-file-into-neo4j-getorcreatenodewithuniquefactory-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!