user10993283
user10993283

Reputation:

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?

Upvotes: 2

Views: 175

Answers (2)

Kingsley Uyi Idehen
Kingsley Uyi Idehen

Reputation: 925

Here is the correct solution to the query, note the casting applied to the FILTER CLAUSE ( i.e. xsd:date(?Todestag ) :

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 ( xsd:date(?Todestag) > "2016-01-01"^^xsd:date ) . 
} ORDER BY ?Todestag

Upvotes: 1

user10993283
user10993283

Reputation:

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

Upvotes: 0

Related Questions