query-1d58e15effa440594fc4937ded3492c0

rq turtle/ttl

TODO

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
select ?siège ?siègeLabel (sample(?whereLabel) as ?whereLabel2) ?start ?tp_end ?tv_end ?end ?days {
SELECT ?siège ?siègeLabel ?whereLabel ?start ?tp_end ?tv_end ?end ?days WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?siège wdt:P31 wd:Q188055.
OPTIONAL { ?siège wdt:P580 ?start. }
OPTIONAL { 
           ?siège p:P582/psv:P582 ?p582node . 
           ?p582node wikibase:timeValue ?tv_end .       # get the time value
           ?p582node wikibase:timePrecision ?tp_end .   # get the time precision
           values ?durationYear { "P1Y.000S"^^xsd:duration }
           values ?durationMonth { "P1M.000S"^^xsd:duration }
           values ?durationDay { "P1D.000S"^^xsd:duration }
           BIND(
             IF(?tp_end=9,?tv_end + ?durationYear - ?durationDay,# set end date to 31 December if time precision is "year" (9)
             IF(?tp_end=10,?tv_end + ?durationMonth - ?durationDay,# set end date to 28th if time precision is "month" (10)
             ?tv_end))
              AS ?end).
         }
OPTIONAL { ?siège wdt:P276 ?where. } 
OPTIONAL { ?siège p:P2047/psn:P2047/wikibase:quantityAmount ?lengthNorm.}
BIND(COALESCE(?lengthNorm/86400,(?end - ?start+1)) as ?days)
}
}
group by ?siège ?siègeLabel ?start ?tp_end ?tv_end ?end ?days
order by desc(year(?end)) ?whereLabel2

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v13("?days"):::projected v10("?durationDay") v9("?durationMonth") v8("?durationYear") v11("?end"):::projected v12("?lengthNorm") v5("?p582node") v3("?siège"):::projected v4("?start"):::projected v7("?tp_end"):::projected v6("?tv_end"):::projected v11("?where") v14("?whereLabel"):::projected v15("?whereLabel2") a1((" ")) a2((" ")) a3((" ")) c2(["bd:serviceParam"]):::iri c6(["wd:Q188055"]):::iri c4(["#91;AUTO_LANGUAGE#93;,en"]):::literal subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end v3 --"p:direct/P31"--> c6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P580".-> v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:P582".-> a1 a1 --"p:statement/value/P582"--> v5 v5 --"wikibase:timeValue"--> v6 v5 --"wikibase:timePrecision"--> v7 bind0[/VALUES ?durationYear/] bind0-->v8 bind00(["P1Y.000S^^xsd:duration"]) bind00 --> bind0 bind1[/VALUES ?durationMonth/] bind1-->v9 bind10(["P1M.000S^^xsd:duration"]) bind10 --> bind1 bind2[/VALUES ?durationDay/] bind2-->v10 bind20(["P1D.000S^^xsd:duration"]) bind20 --> bind2 bind3[/"if(?tp_end = '9^^xsd:integer',?tv_end + ?durationYear - ?durationDay,if(?tp_end = '10^^xsd:integer',?tv_end + ?durationMonth - ?durationDay,?tv_end))"/] v7 --o bind3 v6 --o bind3 v8 --o bind3 v10 --o bind3 v9 --o bind3 bind3 --as--o v11 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P276".-> v11 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:P2047".-> a2 a2 --"p:statement/value-normalized/P2047"--> a3 a3 --"wikibase:quantityAmount"--> v12 end bind4[/"?lengthNorm / '86400^^xsd:integer'?end - ?start + '+1^^xsd:integer'"/] v12 --o bind4 v11 --o bind4 v4 --o bind4 bind4 --as--o v13 bind6[/"sample(?whereLabel)"/] v14 --o bind6 bind6 --as--o v15