map owl file into neo4j - getOrCreateNodeWithUniqueFactory method

房东的猫 提交于 2019-12-04 09:00:48

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.

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