简体   繁体   中英

Error in using sparql DELETE query using rdflib python

I am trying to DELETE triples from RDF graph using rdflib library of python, but not succeeding in doing so. My query is the follwong learned from http://www.w3.org/TR/sparql11-update/#delete .

plugin.register(
    'sparql', rdflib.query.Processor,
    'rdfextras.sparql.processor', 'Processor')
plugin.register(
    'sparql', rdflib.query.Result,
    'rdfextras.sparql.query', 'SPARQLQueryResult')

bdel= graph.query(""" 
PREFIX bibo: <http://purl.org/ontology/bibo/>                       
DELETE  {?s ?p ?o}
WHERE { 
         ?s bibo:reproducedIn ?o. 
      }""")

It is giving following error, any clue to solve this problem. Thanks in advance.

pyparsing.ParseException: Expected "SELECT" (at char 116), (line:4, col:17)

As mentioned above, it looks like you are trying to use graph.query which does indeed expect only 'SELECT' versions of SPARQL Queries. In order to run any SPARQL Updates as defined here , you will need to use graph.processUpdate() instead. For your example, something along the lines of:

processUpdate(graph, """ 
PREFIX bibo: <http://purl.org/ontology/bibo/>                       
DELETE  {?s ?p ?o}
WHERE { 
?s bibo:reproducedIn ?o. 
}""")

Hope this helps!

The query you are using is a SPARQL Update , which is a distinct standard from SPARQL Query . Possibly the graph.query function expects only SPARQL Query? I can't see any mention of Sparql Update on the relevant rdflib pages .

Looking at this page , it looks like you may need to use the processUpdate() method of rdflib-sparql instead?

The online validator agrees that this is not a valid SPARQL Query (though it looks like valid SPARQL Update to me)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM