简体   繁体   中英

SPARQL DBpedia query times out

I'm trying to execute a fairly simple SPARQL query on DBPedia from Python, as follows:

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 .

Whenever I try to run the above query in Python I end up with a timeout error:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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