Paul Rusu
Paul Rusu

Reputation: 233

simple sparql query not working, dates comparison

I get "SR171: Transaction timed out" on the dbpedia sparql endpoint, for the following simple query: Why do I get this error? I don't set any timeout - it's on 0.

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>

PREFIX ont: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?date (bif:substring(STR(?date), 1, 4) AS ?year) WHERE {
   ?person ont:birthDate ?date .
   ?person foaf:name ?name   

   . FILTER ( (fn:string-length(STR(?date)) = 10) && (bif:substring(STR(?date), 9, 2) = '05') && (bif:substring(STR(?date), 6, 2) = '02') && (?date > "1868-01-01"^^xsd:date) && (?date < "2005-01-01"^^xsd:date) )

Upvotes: 1

Views: 1062

Answers (1)

RobV
RobV

Reputation: 28646

It's because your query is too hard for the DBPedia endpoint to answer without adversely impacting other users of the service.

As DBPedia is a well known public SPARQL endpoint it gets very heavily used so the people who host it have it configured to impose strict limits on how long a query can run for so that rogue users don't make the service unusable for others.

In your case your query will take a long time because you ask something that has a lot of initial results (592299 to be precise) and then apply a FILTER over it. FILTER is quite expensive in SPARQL especially when doing string manipulation and date comparison. AFAIK the DBPedia timeout is something fairly low like a few seconds and the endpoint simply cannot finish your query within that time because it takes too long to apply the FILTER.

Note - Here's the query I used to see how many results the first portion of your query was returning:

PREFIX ont: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT COUNT(*) 
WHERE 
{
   ?person ont:birthDate ?date .
   ?person foaf:name ?name   
}

Upvotes: 8

Related Questions