使用 Python 的 SPARQLwrapper 对 DBPedia 端点进行 SPARQL 查询时出现 HTTP 错误 500
我正在尝试接收标签包含特定字符串的所有属性。我使用以下查询:
SELECT ?p ?l count(?p) as ?count WHERE {
?someobj ?p ?s .
?p a <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
?p <http://www.w3.org/2000/01/rdf-schema#label> ?l .
?l bif:contains "string" .
FILTER (lang(?l) = 'en').
FILTER (!isLiteral(?someobj)).
} ORDER BY DESC(?count) LIMIT 5
通过公共 DBPedia 端点 @ http://dbpedia.org/sparql 发出查询时,它有效,并返回我想要的内容。然而,当我在 Python 脚本中通过 SPARQLWrapper 执行相同操作时,我不断收到:
File "E:\thesis\sem_web21.py", line 254, in findWord
results = sparql.query().convert()
File "build/bdist.linux-i686/egg/SPARQLWrapper/Wrapper.py", line 355, in query
return QueryResult(self._query())
File "build/bdist.linux-i686/egg/SPARQLWrapper/Wrapper.py", line 334, in _query
raise e
HTTPError: HTTP Error 500: SPARQL Request Failed
我尝试了查询的变体,有或没有计数和排序,有或没有限制。我不断收到 HTTP 500。我不认为端点不稳定,因为我对同一脚本中的其他查询没有问题,它只会因该查询而停止。
检索对象的类似查询工作正常(都在公共端点通过我的脚本):
SELECT ?s ?l count(?s) as ?count WHERE {
?someobj ?p ?s .
?s <http://www.w3.org/2000/01/rdf-schema#label> ?l .
?l bif:contains "computer" .
FILTER (!regex(str(?s), '^http://dbpedia.org/resource/Category:')).
FILTER (!regex(str(?s), '^http://dbpedia.org/resource/List')).
FILTER (!regex(str(?s), '^http://sw.opencyc.org/')).
FILTER (lang(?l) = 'en').
FILTER (!isLiteral(?someobj)).
} ORDER BY DESC(?count) LIMIT 20
知道是什么原因造成的吗?或者知道如何检索更具体的错误?提前致谢。
I am trying to receive all properties whose labels contain a certain string. I use the following query:
SELECT ?p ?l count(?p) as ?count WHERE {
?someobj ?p ?s .
?p a <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
?p <http://www.w3.org/2000/01/rdf-schema#label> ?l .
?l bif:contains "string" .
FILTER (lang(?l) = 'en').
FILTER (!isLiteral(?someobj)).
} ORDER BY DESC(?count) LIMIT 5
When issueing the query through the public DBPedia endpoint @ http://dbpedia.org/sparql, it works, and returns what I want. However when I do the same through the SPARQLWrapper in my Python script, I keep getting:
File "E:\thesis\sem_web21.py", line 254, in findWord
results = sparql.query().convert()
File "build/bdist.linux-i686/egg/SPARQLWrapper/Wrapper.py", line 355, in query
return QueryResult(self._query())
File "build/bdist.linux-i686/egg/SPARQLWrapper/Wrapper.py", line 334, in _query
raise e
HTTPError: HTTP Error 500: SPARQL Request Failed
I have tried variations on the query, with and without counting and sorting, with and without limiting. I keep getting HTTP 500s. I don't think it's the endpoint being instable, as I have no problem with other queries in the same script, it only stops with this query.
Similar queries to retrieve objects work fine (both at the public endpoint as through my script):
SELECT ?s ?l count(?s) as ?count WHERE {
?someobj ?p ?s .
?s <http://www.w3.org/2000/01/rdf-schema#label> ?l .
?l bif:contains "computer" .
FILTER (!regex(str(?s), '^http://dbpedia.org/resource/Category:')).
FILTER (!regex(str(?s), '^http://dbpedia.org/resource/List')).
FILTER (!regex(str(?s), '^http://sw.opencyc.org/')).
FILTER (lang(?l) = 'en').
FILTER (!isLiteral(?someobj)).
} ORDER BY DESC(?count) LIMIT 20
Any idea what could be causing this? Or any idea how I could retrieve a more specific error? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是 dbpedia 的超时错误,因为它在不同的图表中查找它。当您通过 dbpedia Web 界面尝试它时,它始终包含您正在查询的图表的 uri。因此,请尝试将其添加到您的查询中:
然后再试一次。
使用以下 python 脚本进行了尝试:
I think it's a time out error on dbpedia's part because it looks it up in different graphs. When you are trying it through the dbpedia web interface it always includes the uri of the graph you are querying. So try adding that to your query:
and try it again.
Tried it using the following python script:
COUNT 表达式应为
(count(?p) as ?count)
,并带有方括号。不确定这就是这里的问题,但我想我应该指出来。
The COUNT expression should be
(count(?p) as ?count)
, with the brackets.Not sure that's the problem here, but thought I should point it out.