query-f5dffd745c2cbdde93b5a2452ff494fe

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?nameLabel ?itemLabel ?itemDescription  ?datebirth ?datebirth_alt ?precDoB ?datedeath ?precDoD
WHERE
{
    ?item wdt:P119 wd:Q1457377 .
    OPTIONAL {?item wdt:P734 ?name }
    OPTIONAL {?item p:P569 [ps:P569 ?birthdate; psv:P569 [wikibase:timePrecision ?precDoB] ] .
    BIND(IF(?precDoB=11,concat(str(year(?birthdate))," ",if(strlen(str(month(?birthdate)))=1,concat("0",str(month(?birthdate))),str(month(?birthdate)))," ",if(strlen(str(day(?birthdate)))=1,concat("0",str(day(?birthdate))),str(day(?birthdate)))),
             if(?precDoB=10,concat(str(year(?birthdate))," ",if(strlen(str(month(?birthdate)))=1,concat("0",str(month(?birthdate))),str(month(?birthdate)))),
               if(?precDoB=9,year(?birthdate),""))) as ?datebirth)

 # --- alternative format for birth date, similar can be done for death date            
      ?month wdt:P31 wd:Q47018901; wdt:P279 wd:Q18602249; wdt:P1545 ?monthnumber .  FILTER(?monthnumber=STR(MONTH(?birthdate)))
      ?month rdfs:label ?monthname . FILTER(lang(?monthname)='en')
      BIND(IF(?precDoB=11,?birthdate,IF(?precDoB=10,CONCAT(STR(?monthname),' ',STR(YEAR(?birthdate))),YEAR(?birthdate))) AS ?datebirth_alt)             
 # ---   

             } 
    OPTIONAL {?item wdt:P19 ?birthplace }
    OPTIONAL {?item wdt:P570 ?deathdate }
    OPTIONAL {?item p:P570 [ps:P570 ?deathdate; psv:P570 [wikibase:timePrecision ?precDoD] ] .
      BIND(IF(?precDoD=11,concat(str(year(?deathdate))," ",if(strlen(str(month(?deathdate)))=1,concat("0",str(month(?deathdate))),str(month(?deathdate)))," ",if(strlen(str(day(?deathdate)))=1,concat("0",str(day(?deathdate))),str(day(?deathdate)))),
             if(?precDoD=10,concat(str(year(?deathdate))," ",if(strlen(str(month(?deathdate)))=1,concat("0",str(month(?deathdate))),str(month(?deathdate)))),
               if(?precDoD=9,year(?deathdate),""))) as ?datedeath)
             } 
    OPTIONAL {?item wdt:P20 ?deathplace }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY ?precDoD ?nameLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?birthdate") v12("?birthplace") v9("?datebirth"):::projected v11("?datebirth_alt"):::projected v14("?datedeath"):::projected v13("?deathdate") v15("?deathplace") v6("?item"):::projected v10("?month") v5("?monthname") v3("?monthnumber") v7("?name") v2("?nameLabel"):::projected v8("?precDoB"):::projected v1("?precDoD"):::projected a1((" ")) a2((" ")) a3((" ")) a4((" ")) c3(["wd:Q1457377"]):::iri c12(["wd:Q18602249"]):::iri c22(["bd:serviceParam"]):::iri c10(["wd:Q47018901"]):::iri c24(["#91;AUTO_LANGUAGE#93;,en"]):::literal v6 --"p:direct/P119"--> c3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P734".-> v7 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; a1 -."p:statement/P569".-> v4 a2 --"wikibase:timePrecision"--> v8 a1 --"p:statement/value/P569"--> a2 v6 --"p:P569"--> a1 bind0[/"if(?precDoB = '11^^xsd:integer',concat(str(year-from-dateTime(?birthdate)),' ',if(string-length(str(month-from-dateTime(?birthdate))) = '1^^xsd:integer',concat('0',str(month-from-dateTime(?birthdate))),str(month-from-dateTime(?birthdate))),' ',if(string-length(str(day-from-dateTime(?birthdate))) = '1^^xsd:integer',concat('0',str(day-from-dateTime(?birthdate))),str(day-from-dateTime(?birthdate)))),if(?precDoB = '10^^xsd:integer',concat(str(year-from-dateTime(?birthdate)),' ',if(string-length(str(month-from-dateTime(?birthdate))) = '1^^xsd:integer',concat('0',str(month-from-dateTime(?birthdate))),str(month-from-dateTime(?birthdate)))),if(?precDoB = '9^^xsd:integer',year-from-dateTime(?birthdate),'')))"/] v8 --o bind0 v4 --o bind0 bind0 --as--o v9 v10 --"p:direct/P31"--> c10 v10 --"p:direct/P279"--> c12 v10 --"p:direct/P1545"--> v3 v10 --"rdfs:label"--> v5 bind1[/"if(?precDoB = '11^^xsd:integer',?birthdate,if(?precDoB = '10^^xsd:integer',concat(str(?monthname),' ',str(year-from-dateTime(?birthdate))),year-from-dateTime(?birthdate)))"/] v8 --o bind1 v4 --o bind1 v5 --o bind1 bind1 --as--o v11 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P19".-> v12 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P570".-> v13 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; a3 -."p:statement/P570".-> v13 a4 --"wikibase:timePrecision"--> v1 a3 --"p:statement/value/P570"--> a4 v6 --"p:P570"--> a3 bind2[/"if(?precDoD = '11^^xsd:integer',concat(str(year-from-dateTime(?deathdate)),' ',if(string-length(str(month-from-dateTime(?deathdate))) = '1^^xsd:integer',concat('0',str(month-from-dateTime(?deathdate))),str(month-from-dateTime(?deathdate))),' ',if(string-length(str(day-from-dateTime(?deathdate))) = '1^^xsd:integer',concat('0',str(day-from-dateTime(?deathdate))),str(day-from-dateTime(?deathdate)))),if(?precDoD = '10^^xsd:integer',concat(str(year-from-dateTime(?deathdate)),' ',if(string-length(str(month-from-dateTime(?deathdate))) = '1^^xsd:integer',concat('0',str(month-from-dateTime(?deathdate))),str(month-from-dateTime(?deathdate)))),if(?precDoD = '9^^xsd:integer',year-from-dateTime(?deathdate),'')))"/] v1 --o bind2 v13 --o bind2 bind2 --as--o v14 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P20".-> v15 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c22 --"wikibase:language"--> c24 end