使用SPARQLWrapper进行INSERT/DELETE/UPDATE查询 [英] INSERT/DELETE/UPDATE query using SPARQLWrapper

查看:617
本文介绍了使用SPARQLWrapper进行INSERT/DELETE/UPDATE查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我在网络上浏览了许多示例,这些示例解释了如何使用SELECT语句从芝麻三重存储区中获取数据来使用python SPARQLWrapper,但不确定如何在使用芝麻的芝麻中进行INSERT/DELETE/UPDATE语句.你们中的任何一个都可以在这方面进行指导.

谢谢

解决方案

SPARQL查询作为GET请求发送,但是UPDATE(如INSERT,DELETE等)要求将查询作为POST请求发送.只需将以下行添加到sparql.query()

sparql.method = 'POST'

此外,用于更新的URL与查询不同.此更新基于工作台,而不是芝麻URL.例如,如果查询网址为:

http://localhost:8080/openrdf-sesame/repositories/test/

http://localhost:8080/openrdf-workbench/repositories/test/query

然后更新网址为:

http://localhost:8080/openrdf-workbench/repositories/test/update

因此,UPDATE/INSERT请求应类似于:

queryString = "INSERT DATA { GRAPH <http://example.com/> { "b" a "c". } }" 
sparql = SPARQLWrapper("http://localhost:8080/openrdf-workbench/repositories/test/update")

sparql.setQuery(queryString) 
sparql.method = 'POST'
sparql.query()

Although I have gone through lot of examples on the web explaining the use of python SPARQLWrapper using SELECT statements for fetching data from sesame triple store, but not sure how can we INSERT/DELETE/UPDATE statements in sesame using it. Can any of you please guide in this regard.

Thanks

解决方案

The SPARQL queries are send as GET request, but the UPDATE (like INSERT, DELETE, etc.) requires the query be send as a POST request. Just add the following line before sparql.query()

sparql.method = 'POST'

Also, the url for update is different from the query. The update is based on workbench and not sesame url. For example, if the query url is:

http://localhost:8080/openrdf-sesame/repositories/test/

or

http://localhost:8080/openrdf-workbench/repositories/test/query

then the update url would be:

http://localhost:8080/openrdf-workbench/repositories/test/update

Therefore, the UPDATE/INSERT request should look like:

queryString = "INSERT DATA { GRAPH <http://example.com/> { "b" a "c". } }" 
sparql = SPARQLWrapper("http://localhost:8080/openrdf-workbench/repositories/test/update")

sparql.setQuery(queryString) 
sparql.method = 'POST'
sparql.query()

这篇关于使用SPARQLWrapper进行INSERT/DELETE/UPDATE查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆