query-1f131598ab5626a21506e15f8ebeff85
TODO
Use at
- https://query.wikidata.org/sparql
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#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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
BIND(
IF(?tp_end=9,?tv_end + "P1Y"^^xsd:duration - "P1D"^^xsd:duration,# set end date to 31 December if time precision is "year" (9)
IF(?tp_end=10,?tv_end + "P1M"^^xsd:duration - "P1D"^^xsd:duration,# 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 ?whereLabel2 desc(year(?end))
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v10("?days"):::projected
v8("?end"):::projected
v9("?lengthNorm")
v5("?p582node")
v3("?siège"):::projected
v4("?start"):::projected
v7("?tp_end"):::projected
v6("?tv_end"):::projected
v8("?where")
v11("?whereLabel"):::projected
v12("?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[/"if(?tp_end = '9^^xsd:integer',?tv_end + 'P1Y^^xsd:duration' - 'P1D^^xsd:duration',if(?tp_end = '10^^xsd:integer',?tv_end + 'P1M^^xsd:duration' - 'P1D^^xsd:duration',?tv_end))"/]
v7 --o bind0
v6 --o bind0
bind0 --as--o v8
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P276".-> v8
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"--> v9
end
bind1[/"?lengthNorm / '86400^^xsd:integer'?end - ?start + '+1^^xsd:integer'"/]
v9 --o bind1
v8 --o bind1
v4 --o bind1
bind1 --as--o v10
bind3[/"sample(?whereLabel)"/]
v11 --o bind3
bind3 --as--o v12