简体   繁体   English

SPARQL DBpedia查询超时

[英]SPARQL DBpedia query times out

I'm trying to execute a fairly simple SPARQL query on DBPedia from Python, as follows: 我正在尝试从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()

I want to retrieve all entities that match a given city in the first part of their name. 我想检索名称第一部分中与给定城市匹配的所有实体。 I know that's a lot of entities but it executes fine in the DBPedia test browser here . 我知道有很多实体,但是在这里的DBPedia测试浏览器中可以很好地执行。

Whenever I try to run the above query in Python I end up with a timeout error: 每当我尝试在Python中运行以上查询时,我都会遇到超时错误:

EndPointInternalError: EndPointInternalError: endpoint returned code 500 and response. 

Response:
Virtuoso S1T00 Error SR171: Transaction timed out

Any advice on avoiding this timeout error? 关于避免此超时错误的任何建议? I realize that I might have to make my query more specific to tighten the bounds of the search. 我意识到我可能必须使查询更具体,以缩小搜索范围。

Do a full text search first with bif:contains , and filter that afterwards: 首先使用bif:contains全文搜索,然后进行过滤:

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

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

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