CoreNoob
CoreNoob

Reputation: 115

SPARQL query all persons who lived through the 20th century in DBPedia

I want to query all persons who lived through the entire 20th century in DBPedia. Im using https://dbpedia.org/sparql/ to process my query. I have limited the output to 20.

The query I've tried is the following:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?personName ?birthDate ?deathDate
WHERE {
    FILTER (?birthDate < "1900-01-01"^^xsd:date AND ?deathDate > "1999-12-31"^^xsd:date).
    ?p rdf:type dbo:Person.
    ?p dbp:name ?personName.
    ?p dbp:birthDate ?birthDate.
    ?p dbp:deathDate ?deathDate.
}
LIMIT 20.

In the output all person died after 1999-12-31 but they weren't born before 1900-01-01. Why is my query wrong? How can I fix it?

Thanks in advance for you time.

Upvotes: 1

Views: 254

Answers (1)

danielhm
danielhm

Reputation: 1

This issue is due to integer values being included in the query results, and can be resolved using the DATATYPE() function in the same or a new FILTER() section.

For example:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?personName ?birthDate ?deathDate
WHERE 
    {
        ?person rdf:type dbo:Person;
        dbp:name ?personName;
        dbp:birthDate ?birthDate;
        dbp:deathDate ?deathDate.
    
        #This FILTER ensures that only xsd:date values are returned
        FILTER(DATATYPE(?birthDate) = xsd:date && DATATYPE(?deathDate) = xsd:date).
    
        FILTER (?birthDate < "1900-01-01"^^xsd:date && ?deathDate > "1999-12-31"^^xsd:date).
    
    }
LIMIT 20

Live Query Definition

Live Query Result

DATATYPE() Documentation

Upvotes: 0

Related Questions