sparqlwikidata

Wikidata SPARQL cannot give me birthdates for January 1


All I'm doing is I want to use wikiservice sparql to get famous people by birthdate. Every other day in the year works, except January 1. When I researched this, I found out it had something to do with time precision and the way wikidata stores dates. If it sees January 1980 for example, it automatically returns January 1 1980. If I query January 1 without precision I get back people who's birthdate are NOT January 1 (ie Joy Reid who was born Decemeber 8). If I add precision, I get nothing back. Is it just literally impossible to get birth dates back for January 1 in wikidata sparql?

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?person ?personLabel ?birthdate ?followers ?uniqueImage ?countryLabel (GROUP_CONCAT(DISTINCT ?occupationLabel; separator=", ") as ?occupations)
WHERE {
  VALUES ?country {wd:Q30 wd:Q145}
  ?person wdt:P31 wd:Q5 ;  # Instance of human
    wdt:P569 ?birthdate ;  # Date of birth
    wdt:P27 ?country ;  # Citizenship
    wdt:P8687 ?followers; # Social Media Followers 
    wdt:P106 ?occupation ;  # Occupation
    wdt:P18 ?uniqueImage .  # Image;

  FILTER(MONTH(?birthdate) = 1  && DAY(?birthdate) = 1)
  FILTER(LANG(?occupationLabel) = "en")
  ?occupation rdfs:label ?occupationLabel .

  ?birthdate wikibase:timePrecision "12"^^xsd:integer .  #remove this to have results come back (though wrong like Joy Reid)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?person ?personLabel ?birthdate ?followers ?uniqueImage ?countryLabel
ORDER BY DESC(?followers)
LIMIT 40

You can run it here: SPARQL Wikidata


Solution

  • Precision is an attribute of full values, not of simple values (by the way, literals cannot be subjects in RDF). See RDF Dump Format.

    Instead of

    ?person wdt:P569 ?birthday .
    ?birthday wikibase:timePrecision 12 .
    

    it should be something like

    ?person p:P569 ?statement .
    ?statement a wikibase:BestRank ;
               ps:P569 ?birthdate ;
               psv:P569/wikibase:timePrecision 11 .
    

    See also T57755.