【问题标题】:SPARQL DBpedia query times outSPARQL DBpedia 查询超时
【发布时间】:2017-09-28 05:28:04
【问题描述】:

我正在尝试从 Python 对 DBPedia 执行一个相当简单的 SPARQL 查询,如下所示:

from SPARQLWrapper import SPARQLWrapper, JSON
city_name = 'Manhattan'
query = """select * 
               where {
               ?URI rdfs:label ?name.
               filter(regex(str(?name), "^%s"))
           }"""%(city_name)
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setReturnFormat(JSON)
sparql.setQuery(query)
result = sparql.query().convert()

我想检索在名称的第一部分与给定城市匹配的所有实体。我知道有很多实体,但它在 DBPedia 测试浏览器 here 中执行得很好。

每当我尝试在 Python 中运行上述查询时,都会出现超时错误:

EndPointInternalError: EndPointInternalError: endpoint returned code 500 and response. 

Response:
Virtuoso S1T00 Error SR171: Transaction timed out

关于避免此超时错误的任何建议?我意识到我可能必须使我的查询更具体以收紧搜索范围。

【问题讨论】:

  • 在Web界面中,查询不会超时,因为通常会设置提前终止值30000ms,因此,它会返回给定时间内找到的所有结果。如果您从远程应用程序运行查询,则不会设置此值。 (但可以通过在 HTTP 请求中添加 timeout=30000 来设置)确实,这样的随时功能可能会导致结果不完整

标签: python sparql dbpedia


【解决方案1】:

首先使用bif:contains 进行全文搜索,然后过滤:

SELECT * {
  ?uri rdfs:label ?name .
  ?name bif:contains "Manhattan" . # Or "'Manhattan*'"
  FILTER(STRSTARTS(?name, "Manhattan"))
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多