Skip to content

Instantly share code, notes, and snippets.

@taniki
Created May 22, 2012 14:07
Show Gist options
  • Select an option

  • Save taniki/2769308 to your computer and use it in GitHub Desktop.

Select an option

Save taniki/2769308 to your computer and use it in GitHub Desktop.
merge of birthdate and birthyear when birthdate not available
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?person ?birthdate
WHERE {
?person rdf:type dbo:Philosopher .
{
?person dbo:birthDate ?birthdate .
FILTER( datatype(?birthdate) != xsd:gMonthDay ).
}
UNION {
?person dbo:birthYear ?birthdate .
OPTIONAL {
?person dbo:birthDate ?b .
FILTER( datatype(?b) != xsd:gMonthDay ).
}
FILTER( !bound(?b) )
}
}
ORDER BY ?birthdate
@taniki

taniki commented May 23, 2012

Copy link
Copy Markdown
Author

if someone knows why the following query does not work, I'll be happy to think that SPARQL is simple.

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?person ?birthdate
WHERE { 
    ?person rdf:type dbo:Philosopher .

    OPTIONAL { ?person dbo:birthDate ?birthdate . }
    OPTIONAL { ?person dbo:birthYear ?birthdate . }
}
ORDER BY ?birthdate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment