query-7a092ed82ffba0959bda617e82f689c6
Les plus grosses villes avec une femme maire
added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel?mayorLabel ?cityPopulation WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c) BIND(wd:Q16 AS ?Canada)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city wdt:P17 ?Canada. # Only cities in Canada
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Ville du Québec
OPTIONAL { ?city wdt:P3856 ?idQC }
FILTER(# code géographique des municipalités du Québec
BOUND(?idQC)
)
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city p:P1082 ?populationStatement . ?populationStatement ps:P1082 ?cityPopulation. ?populationStatement pq:P585 ?date FILTER NOT EXISTS { ?city p:P1082/pq:P585 ?date_ . FILTER (?date_ > ?date) }
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "fr" .
}
} ORDER BY DESC(?cityPopulation) LIMIT 20
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#>
#Les plus grosses villes avec une femme maire
#added before 2016-10
#TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel?mayorLabel ?cityPopulation
WHERE
{
BIND(wd:Q6581072 AS ?sex)
BIND(wd:Q515 AS ?c)
BIND(wd:Q16 AS ?Canada)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city wdt:P17 ?Canada. # Only cities in Canada
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Ville du Québec
OPTIONAL { ?city wdt:P3856 ?idQC }
FILTER(# code géographique des municipalités du Québec
BOUND(?idQC)
)
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city p:P1082 ?populationStatement .
?populationStatement ps:P1082 ?cityPopulation.
?populationStatement pq:P585 ?date
FILTER NOT EXISTS { ?city p:P1082/pq:P585 ?date_ . FILTER (?date_ > ?date) }
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "fr" .
}
}
ORDER BY DESC(?cityPopulation)
LIMIT 20
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v10("?Canada")
v9("?c")
v4("?city"):::projected
v1("?cityPopulation"):::projected
v3("?date")
v2("?date_")
v5("?idQC")
v11("?mayor")
v12("?populationStatement")
v8("?sex")
v6("?statement")
v7("?x")
a2((" "))
a1((" "))
c15(["fr"]):::literal
c13(["bd:serviceParam"]):::iri
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0f0[["?date_ > ?date"]]
e0f0 --> e0v1
e0f0 --> e0v2
e0v3 --"p:P1082"--> e0a1
e0a1 --"p:qualifier/P585"--> e0v1
e0v3("?city"):::projected
e0v2("?date"):::projected
e0v1("?date_"):::projected
e0a1((" ")):::projected
end
f0--EXISTS--> f0e0
f0 --> v2
f0 --> v3
f0 --> v4
f0 --> c1
f0 --> a1
f0 --> c2
f1[["?date_ > ?date"]]
f1 --> v2
f1 --> v3
v4 --"p:P1082"--> a1
a1 --"p:qualifier/P585"--> v2
f2[["bound(?idQC)"]]
f2 --> v5
f3[["not "]]
subgraph f3e1["Exists Clause"]
e1v1 --"p:qualifier/P582"--> e1v2
e1v1("?statement"):::projected
e1v2("?x"):::projected
end
f3--EXISTS--> f3e1
f3 --> v6
f3 --> c3
f3 --> v7
v6 --"p:qualifier/P582"--> v7
bind4[/"'wd:Q6581072'"/]
bind4 --as--o v8
bind5[/"'wd:Q515'"/]
bind5 --as--o v9
bind6[/"'wd:Q16'"/]
bind6 --as--o v10
v4 --"p:direct/P31"--> a2
a2 --"p:direct/P279"--> v9
v4 --"p:direct/P17"--> v10
v4 --"p:P6"--> v6
v6 --"p:statement/P6"--> v11
v11 --"p:direct/P21"--> v8
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:direct/P3856".-> v5
end
v4 --"p:P1082"--> v12
v12 --"p:statement/P1082"--> v1
v12 --"p:qualifier/P585"--> v3
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c13 --"wikibase:language"--> c15
end