简体   繁体   English

使用rdflib python使用sparql DELETE查询时出错

[英]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. 我正在尝试使用python的rdflib库从RDF图中删除三元组,但没有成功。 My query is the follwong learned from http://www.w3.org/TR/sparql11-update/#delete . 我的查询是从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. 如上所述,您似乎正在尝试使用graph.query ,它确实只希望使用SPARQL查询的“ SELECT”版本。 In order to run any SPARQL Updates as defined here , you will need to use graph.processUpdate() instead. 为了运行此处定义的任何SPARQL更新,您将需要使用graph.processUpdate()代替。 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 . 您使用的查询是SPARQL更新 ,它是与SPARQL查询不同的标准。 Possibly the graph.query function expects only SPARQL Query? 可能graph.query函数只需要SPARQL查询吗? I can't see any mention of Sparql Update on the relevant rdflib pages . 在相关的rdflib页面上我看不到Sparql Update的任何提及。

Looking at this page , it looks like you may need to use the processUpdate() method of rdflib-sparql instead? 查看此页面 ,您可能似乎需要使用rdflib-sparqlprocessUpdate()方法代替?

The online validator agrees that this is not a valid SPARQL Query (though it looks like valid SPARQL Update to me) 在线验证器同意这不是有效的SPARQL查询 (尽管对我来说它看起来像是有效的SPARQL更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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