query-90c132be031c21447147bb817610547d
TODO
Use at
- https://query.wikidata.org/sparql
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 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#>
#Credit: Mahir256
#Map showing sex ratio in districts of India according to 2011 census
#defaultView:Map{"hide": "?rgb"}
SELECT ?d ?dLabel ?shape ?ratio ?rgb WHERE {
?d wdt:P31 wd:Q1149652; p:P1540 ?malepopstmt ; p:P1539 ?femalepopstmt ; wdt:P3896 ?shape.
?malepopstmt ps:P1540 ?malepop ; pq:P585 "+2011-01-01T00:00:00Z"^^xsd:dateTime.
?femalepopstmt ps:P1539 ?femalepop ; pq:P585 "+2011-01-01T00:00:00Z"^^xsd:dateTime.
BIND (xsd:integer(?malepop)/xsd:integer(?femalepop) AS ?ratio)
BIND (IF(?ratio < 0.8, "008000", IF(?ratio < 0.9, "32cd32", IF(?ratio < 1, "7fff00", IF(?ratio < 1.1, "ffa500", IF(?ratio < 1.2, "ff6347", "ff0000"))))) AS ?rgb)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?d"):::projected
v6("?femalepop")
v3("?femalepopstmt")
v5("?malepop")
v2("?malepopstmt")
v7("?ratio"):::projected
v8("?rgb"):::projected
v4("?shape"):::projected
c13(["en"]):::literal
c8(["+2011-01-01T00:00:00Z^^xsd:dateTime"]):::literal
c11(["bd:serviceParam"]):::iri
c2(["wd:Q1149652"]):::iri
v1 --"p:direct/P31"--> c2
v1 --"p:P1540"--> v2
v1 --"p:P1539"--> v3
v1 --"p:direct/P3896"--> v4
v2 --"p:statement/P1540"--> v5
v2 --"p:qualifier/P585"--> c8
v3 --"p:statement/P1539"--> v6
v3 --"p:qualifier/P585"--> c8
bind0[/"http://www.w3.org/2001/XMLSchema#integer(?malepop) / http://www.w3.org/2001/XMLSchema#integer(?femalepop)"/]
v5 --o bind0
v6 --o bind0
bind0 --as--o v7
bind1[/"if(?ratio < '0.8^^xsd:decimal','008000',if(?ratio < '0.9^^xsd:decimal','32cd32',if(?ratio < '1^^xsd:integer','7fff00',if(?ratio < '1.1^^xsd:decimal','ffa500',if(?ratio < '1.2^^xsd:decimal','ff6347','ff0000')))))"/]
v7 --o bind1
bind1 --as--o v8
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c11 --"wikibase:language"--> c13
end