【问题标题】:How to execute a SPARQL update in SailGraph by TinkerpopTinkerpop 如何在 SailGraph 中执行 SPARQL 更新
【发布时间】:2013-07-18 13:22:36
【问题描述】:

我的问题基本上是如何使用 Tinkerpop 创建的 SailGraph 正确执行 SPARQL 更新。

DELETE { ?i_id_iri rdfs:label "BII-I-1" }
INSERT { ?i_id_iri rdfs:label "BII-I-4" }
WHERE
  { 
    ?investigation rdf:type obi:0000011.
    ?i_id_iri rdf:type iao:0000577.
    ?i_id_iri iao:0000219 ?investigation.
  } 

到目前为止,我有这个查询,前缀是从另一个文件添加到顶部的,但它不起作用。 我运行的代码如下

query = parser.parseUpdate(queryString, baseURI);
UpdateExpr expr = query.getUpdateExprs().get(0);
Dataset dataset = query.getDatasetMapping().get(expr);
GraphDatabase.getSailConnection().executeUpdate(expr, dataset, new EmptyBindingSet(), false);

【问题讨论】:

  • 在什么意义上它不起作用?错误,数据未按预期修改,还有什么?
  • 查询已成功执行,但是当我尝试使用应该已替换的旧 id 检索时,它仍然存在
  • 底层数据库是Neo4J,并从中初始化帆图
  • 你有显示这个的小测试用例,所以我可以在本地测试吗?

标签: neo4j rdf sparql owl tinkerpop


【解决方案1】:

我对 Tinkerpop GraphSail 不是特别熟悉,但假设它正确实现了 Sesame SAIL API,如果您将其包装在 SailRepository 中,执行 SPARQL 查询会容易得多,如下所示:

 TinkerGraph graph = new TinkerGraph();
 Sail sail = new GraphSail(graph);    

 Repository rep = new SailRepository(sail);
 rep.initialize();

然后您可以使用 Sesame 的 Repository API,这比尝试直接在 SAIL 上进行操作(不是为此目的而设计的)更加用户友好。

例如,要打开连接并执行 SPARQL 更新,您可以:

RepositoryConnection conn = rep.getConnection();
try {
      String sparql = "INSERT {?s a <foo:example> . } WHERE {?s ?p ?o } ";

      Update update = conn.prepareUpdate(QueryLanguage.SPARQL, sparql);
      update.execute();
}
finally {
  conn.close();
}

有关 Sesame 存储库 API 的更多详细信息,请参阅上面的链接,或查看Javadoc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多