Search code examples
sparqlsemantic-webdbpedia

Why does this SPARQL query give wrong results?


I tried doing some sparql requests on http://dbpedia.org/sparql.

My sparql-request is this:

PREFIX : <http://dbpedia.org/resource/> 
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?Name ?Todestag ?person 
WHERE {
  ?person dbo:deathPlace :Hamburg .
  ?person foaf:name ?Name .
  ?person dbo:deathDate ?Todestag .
  FILTER ( ?Todestag > "2016-01-01"^^xsd:date ) . 
} ORDER BY ?Todestag

The problem: Somehow this FILTER doesn’t work. The SPARQL request gives me all people who died on every day since the start of time in DBpedia. However, I just want people who died after 2016. Can anyone spot the mistake in the query or the syntax?


Solution

  • Okay, I figured it out myself. The problem is definitely the filter. I have now changed the filter and the desired result appears. The filter must be: FILTER (str(?Todestag) >= "2016") .

    Completely, it would look like this:

    PREFIX : <http://dbpedia.org/resource/> 
    PREFIX dbo: <http://dbpedia.org/ontology/> 
    
    SELECT ?Name ?Todestag ?person  
    WHERE {       
    ?person dbo:deathPlace :Hamburg . 
    ?person foaf:name ?Name . 
    ?person dbo:deathDate ?Todestag .
    FILTER (str(?Todestag) >= "2016") .   
    } ORDER BY ?Todestag