无法使用 pythons SPARQLWrapper 从 GraphDB 中删除任何三元组

Cannot delete any triple from GraphDB using pythons SPARQLWrapper

我正在尝试使用 python 的 SPARQLWrapper 和我在此处找到的代码片段从 GraphDB(版本 = GraphDB 免费)中删除一个简单的三元组:https://github.com/RDFLib/sparqlwrapper - 更新示例。我总是得到以下异常: SPARQLWrapper.SPARQLExceptions.QueryBadFormed: QueryBadFormed: 错误的请求已发送到端点,可能是 sparql 查询格式错误。

我的代码是:

    sparql = SPARQLWrapper('http://192.168.0.242:7200/repositories/DataCitation')
    sparql.setMethod(POST)

    sparql.setQuery("""
    PREFIX pub: <http://ontology.ontotext.com/taxonomy/>

    delete where {
        <http://ontology.ontotext.com/resource/tsk9hdnas934> pub:occupation "Cook".
    }
    """)

    results = sparql.query()
    print(results.response.read())

当我对同一端点执行 ask 或 select 语句时,我得到了有效结果。只有更新语句不起作用。

这是完整的堆栈跟踪

/home/filip/anaconda3/envs/TripleStoreCitationFramework/bin/python /home/filip/PycharmProjects/TripleStoreCitationFramework/GraphDB/Playground.py
Traceback (most recent call last):
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/site-packages/SPARQLWrapper/Wrapper.py", line 1073, in _query
    response = urlopener(request)
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/filip/PycharmProjects/TripleStoreCitationFramework/GraphDB/Playground.py", line 6, in <module>
    citing.delete_triples("s")
  File "/home/filip/PycharmProjects/TripleStoreCitationFramework/GraphDB/DataCiting.py", line 32, in delete_triples
    results = sparql.query()
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/site-packages/SPARQLWrapper/Wrapper.py", line 1107, in query
    return QueryResult(self._query())
  File "/home/filip/anaconda3/envs/TripleStoreCitationFramework/lib/python3.8/site-packages/SPARQLWrapper/Wrapper.py", line 1077, in _query
    raise QueryBadFormed(e.read())
SPARQLWrapper.SPARQLExceptions.QueryBadFormed: QueryBadFormed: a bad request has been sent to the endpoint, probably the sparql query is bad formed. 

回复: b'缺少参数:查询'

您需要插入语句的端点不是用于普通查询的简单 SPARQL 端点,而是专用的 /statements 端点:

http:///repositories//声明

此端点也用于 DELETE 语句。

您可以在 RDF4J 文档中查找一些示例。 此外,如果您使用查询字符串传递数据而不是将其作为请求主体的一部分,则需要注意它必须以“?update=”而不是“?query=”开头这一事实。反对