在远程服务器中使用Neo4j作为Triple Store

时间:2015-01-21 09:47:37

标签: neo4j triplestore

我曾使用Tinkerpop和openrdf sail来连接当地的neo4j。

    String dB_DIR = "neo4j//data";

    Sail sail = new GraphSail(new Neo4jGraph(dB_DIR));

    sail.initialize();

我可以导入ttl或rdf文件然后查询0

但现在我想连接远程neo4j。

在这种情况下如何使用neo4j jdbc?

或者Tinkerpop蓝图有办法吗? (我做了一些搜索工作,但没有好的答案)

1 个答案:

答案 0 :(得分:0)

您应该使用Sesame Repository API来访问Sail对象。

具体来说,您需要做的是将Sail对象包装在Repository对象中:

Sail sail = new GraphSail(new Neo4jGraph(dB_DIR));
Repository rep = new SailRepository(sail);
rep.initialize();

在此之后,使用Repository对象连接到您的商店并执行操作,例如加载Turtle文件,然后进行查询:

RepositoryConnection conn = rep.getConnection();
try {
    // load data
    File file = new File("/path/to/file.tll");
    conn.add(file, file.getAbsolutePath(), RDFFormat.TURTLE);

    // do query and print result to STDOUT
    String query = "SELECT * WHERE {?s ?p ?o} LIMIT 10";
    TupleQueryResult result = 
        conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();

    while (result.hasNext()) { 
       System.out.println(result.next().toString());
    }
}
finally {
    conn.close();
}

有关如何使用Repository API的更多信息和示例,请参阅Sesame documentationJavadoc

(披露:我在芝麻开发团队)