query-1f92da0102dc2fa6a90d4f73fea86e0f
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map{"hide": ["?rgb", "?shape"]}
SELECT ?dep ?INSEE ?depLabel ?itemCount ?withCoord ?shape ?rgb
WHERE {
{
SELECT ?dep (COUNT(DISTINCT ?item) AS ?itemCount) {
{
SELECT DISTINCT ?dep ?item WHERE {
?item wdt:P131+ wd:Q142;
wdt:P31/wdt:P279* wd:Q16970;
wdt:P131 ?commune .
?commune p:P131 ?stmt .
?stmt ps:P131 ?dep .
MINUS { ?stmt pq:P582 [] } .
?dep wdt:P2586 [] .
}
}.
} GROUP BY ?dep
}.
{
SELECT ?dep (COUNT(DISTINCT ?item) AS ?_withCoord) {
{
SELECT DISTINCT ?dep ?item WHERE {
?item wdt:P131+ wd:Q142;
wdt:P31/wdt:P279* wd:Q16970;
wdt:P131 ?commune .
?commune p:P131 ?stmt .
?stmt ps:P131 ?dep .
MINUS { ?stmt pq:P582 [] } .
?dep wdt:P2586 [] .
}
}.
?item wdt:P625 [] .
} GROUP BY ?dep
}.
?dep wdt:P2586 ?INSEE .
OPTIONAL { ?dep wdt:P3896 ?shape } .
BIND( ROUND((?_withCoord / ?itemCount) * 100 * 100) / 100 AS ?withCoord ) .
BIND( IF( ?withCoord > 50, IF( ?withCoord > 75, '0000FF', '00FF00' ), 'FF0000' ) AS ?rgb ) .
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" } .
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v7("?INSEE"):::projected
v6("?_withCoord")
v2("?commune")
v4("?dep"):::projected
v1("?item")
v5("?itemCount"):::projected
v10("?rgb"):::projected
v8("?shape"):::projected
v3("?stmt")
v9("?withCoord"):::projected
a2((" "))
a3((" "))
a5((" "))
a6((" "))
a1((" "))
a4((" "))
a7((" "))
c15(["fr"]):::literal
c13(["bd:serviceParam"]):::iri
c5(["wd:Q16970"]):::iri
c2(["wd:Q142"]):::iri
v1 --"p:direct/P131"--> c2
v1 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c5
v1 --"p:direct/P131"--> v2
v2 --"p:P131"--> v3
v3 --"p:statement/P131"--> v4
subgraph minus0["MINUS"]
style minus0 stroke-width:6px,fill:pink,stroke:red;
v3 --"p:qualifier/P582"--> a2
end
v4 --"p:direct/P2586"--> a3
bind2[/"count(?item)"/]
v1 --o bind2
bind2 --as--o v5
v1 --"p:direct/P131"--> c2
v1 --"p:direct/P31"--> a4
a4 --"p:direct/P279"--> c5
v1 --"p:direct/P131"--> v2
v2 --"p:P131"--> v3
v3 --"p:statement/P131"--> v4
subgraph minus3["MINUS"]
style minus3 stroke-width:6px,fill:pink,stroke:red;
v3 --"p:qualifier/P582"--> a5
end
v4 --"p:direct/P2586"--> a6
v1 --"p:direct/P625"--> a7
bind5[/"count(?item)"/]
v1 --o bind5
bind5 --as--o v6
v4 --"p:direct/P2586"--> v7
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:direct/P3896".-> v8
end
bind6[/"numeric-round(?_withCoord / ?itemCount * '100^^xsd:integer' * '100^^xsd:integer') / '100^^xsd:integer'"/]
v6 --o bind6
v5 --o bind6
bind6 --as--o v9
bind7[/"if(?withCoord > '50^^xsd:integer',if(?withCoord > '75^^xsd:integer','0000FF','00FF00'),'FF0000')"/]
v9 --o bind7
bind7 --as--o v10
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c13 --"wikibase:language"--> c15
end