Sparql Insert Exception : SPARQLWrapper.SPARQLExceptions.QueryBadFormed(SPARQL插入异常:SPARQLWrapper.SPARQLExceptions.QueryBadFormed)
本文介绍了SPARQL插入异常:SPARQLWrapper.SPARQLExceptions.QueryBadFormed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直有这个奇怪的问题,我试图使用python中的SPARQLWrapper库将其插入到Virtuoso图形中。
我可以通过基于浏览器的端点在localhost:8890sparql插入一个三元组,但是当我通过我的python SparqlWrapper尝试相同的查询时,它抛出以下错误:
SPARQLWrapper.SPARQLExceptions.QueryBadFormed:查询错误格式:A错误 请求已发送到端点,SPARQL查询可能是 格式不正确。
我觉得配置端有问题,但无法识别。
PREFIX dbpedia: <http://dbpedia.org/resource/> Insert Data { GRAPH <test> { <http://dbpedia.org/resource/life> <http://umbel.org/umbel/rc/Artist> '2' . } }
Traceback (most recent call last):
File "test.py", line 33, in <module>
sys.exit(process.run("1"))
File "test.py", line 27, in run
result = self.sparql.query().convert()
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SPARQLWrapper/Wrapper.py", line 390, in query
return QueryResult(self._query())
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SPARQLWrapper/Wrapper.py", line 363, in _query
raise QueryBadFormed()
SPARQLWrapper.SPARQLExceptions.QueryBadFormed: QueryBadFormed: a bad request has been sent to the endpoint, probably the sparql query is bad formed.
推荐答案
如果您将其带到parql.org的SPARQL update validator,它会立即告诉您这是错误的,语法错误在哪里:
当然,要了解如何做您正在尝试做的事情,您需要查看规范。SPARQL 1.1 Update是要查看的地方,虽然我建议您浏览一下,以便更好地了解其中的内容,但一个示例就足以显示您需要编写的内容:输入:
1 PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 2 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 3 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 4 PREFIX owl: <http://www.w3.org/2002/07/owl#> 5 PREFIX fn: <http://www.w3.org/2005/xpath-functions#> 6 PREFIX apf: <http://jena.hpl.hp.com/ARQ/property#> 7 8 PREFIX dbpedia: <http://dbpedia.org/resource/> 9 Insert Data Into GRAPH <test> { 10 <http://dbpedia.org/resource/life> <http://umbel.org/umbel/rc/Artist> '2'^^xsd:integer . 11 }语法错误:
Encountered " "into" "Into "" at line 9, column 13. Was expecting: "{" ...
示例2:
此SPARQL 1.1更新请求添加了一个三元组,以提供 书。与上一个示例相反,该示例影响了默认 图形,则请求的更改发生在由标识的命名图形中 IRIhttp://example/bookStore。PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX ns: <http://example.org/ns#> INSERT DATA { GRAPH <http://example/bookStore> { <http://example/book1> ns:price 42 } }
您的查询需要
PREFIX dbpedia: <http://dbpedia.org/resource/>
Insert Data
{ GRAPH <test> { <http://dbpedia.org/resource/life> <http://umbel.org/umbel/rc/Artist> '2'^^xsd:integer . } }
这篇关于SPARQL插入异常:SPARQLWrapper.SPARQLExceptions.QueryBadFormed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:SPARQL插入异常:SPARQLWrapper.SPARQLExceptions.QueryBadFormed
基础教程推荐
猜你喜欢
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
