Here's the (nearly) equivalent query for the statements dump[1] loaded into Blazegraph:
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT DISTINCT ?city ?citylabel ?mayorlabel WHERE {
?city wd:P31s/wd:P31v wd:Q515 . # find instances of subclasses of city
?city wd:P6s ?statement . # with a P6 (head of goverment) statement
?statement wd:P6v ?mayor . # ... that has the value ?mayor
?mayor wd:P21s/wd:P21v wd:Q6581072 . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement wd:P582q ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (the number is reached through a chain of three properties)
?city wd:P1082s/wd:P1082v/<http://www.wikidata.org/ontology#numericValue> ?population .
# Optionally, find English labels for city and mayor:
OPTIONAL {
?city wd:P373s/wd:P373v ?citylabel .
# FILTER ( LANG(?citylabel) = "en" )
}
OPTIONAL {
?mayor wd:P373s/wd:P373v ?mayorlabel .
# FILTER ( LANG(?mayorlabel) = "en" )
}
} ORDER BY DESC(?population) LIMIT 100
Free beer to anyone who can figure out how to use those language filters. Would we need to also load property definitions[2]?