query-c8022a8313ff554bc25b6a00c0a054b5
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.
BIND(wd:Q11794876 AS ?siège) #use this filter to see the problem of preferred rank
OPTIONAL { ?siège wdt:P580 ?start. }
OPTIONAL {
?siège p:P582 ?déclaration_siège .
?déclaration_siège psv:P582 ?p582node
; a wikibase:BestRank
.
?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))