INSERT / DELETE / UPDATE query using SPARQLWrapper

Although I looked at many examples on the Internet explaining the use of python SPARQLWrapper with SELECT statements to retrieve data from a three-site repository, I'm not sure how we can use INSERT / DELETE / UPDATE statements in sesame. Can any of you please be guided in this regard.

thanks

+4
source share
2 answers

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

sparql.method = 'POST' 

In addition, the update URL is different from the request. The update is based on a workbench, not a sesame URL. For example, if the request URL is:

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

or

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

then the update url will be:

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

Therefore, the UPDATE / INSERT query should look like this:

 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() 
+7
source

This is not particularly clear from the docs, but I think you can just execute the update statement just like you are doing the request:

 queryString = "DELETE WHERE { ?s ?p ?o. }" sparql = SPARQLWrapper("http://localhost:8080/openrdf-sesame/repositories/test/statements") sparql.setQuery(queryString) ret = sparql.query() 

In the case of Sesame, keep in mind that the URL of the update endpoint ( repositories/<repId>/statements ) does not match the URL of the request endpoint ( repositories/<repId> ). See Sesame Protocol Documents for more information.

+1
source

All Articles