WolfgangFahl / pyLoDStorage

python List of Dict (Table) Storage library
Apache License 2.0
8 stars 3 forks source link

addQueryDocumentation #54

Closed WolfgangFahl closed 2 years ago

WolfgangFahl commented 2 years ago

refactor from test_queries as a standard function and fix: values table below while at it.

Ten largest cities of the world

Wikidata SPARQL query showing the 10 most populated cities of the world using the million city class Q1637706 for selection

query

# Ten Largest cities of the world 
# WF 2021-08-23
# see also http://wiki.bitplan.com/index.php/PyLoDStorage#Examples
# see also https://github.com/WolfgangFahl/pyLoDStorage/issues/46
SELECT DISTINCT ?city ?cityLabel ?population ?country ?countryLabel 
WHERE {
  VALUES ?cityClass { wd:Q1637706}.
  ?city wdt:P31 ?cityClass .
  ?city wdt:P1082 ?population .
  ?city wdt:P17 ?country .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}
ORDER BY DESC(?population)
LIMIT 10

try it!

result

city cityLabel population country countryLabel
Value(uri:'http://www.wikidata.org/entity/Q1353') Value(literal:'Delhi') Value(literal:'26495000') Value(uri:'http://www.wikidata.org/entity/Q668') Value(literal:'India')
Value(uri:'http://www.wikidata.org/entity/Q8686') Value(literal:'Shanghai') Value(literal:'24870895') Value(uri:'http://www.wikidata.org/entity/Q148') Value(literal:"People's Republic of China")
Value(uri:'http://www.wikidata.org/entity/Q956') Value(literal:'Beijing') Value(literal:'21710000') Value(uri:'http://www.wikidata.org/entity/Q148') Value(literal:"People's Republic of China")
Value(uri:'http://www.wikidata.org/entity/Q1354') Value(literal:'Dhaka') Value(literal:'16800000') Value(uri:'http://www.wikidata.org/entity/Q902') Value(literal:'Bangladesh')
Value(uri:'http://www.wikidata.org/entity/Q1156') Value(literal:'Mumbai') Value(literal:'15414288') Value(uri:'http://www.wikidata.org/entity/Q668') Value(literal:'India')
Value(uri:'http://www.wikidata.org/entity/Q8660') Value(literal:'Karachi') Value(literal:'14910352') Value(uri:'http://www.wikidata.org/entity/Q843') Value(literal:'Pakistan')
Value(uri:'http://www.wikidata.org/entity/Q8673') Value(literal:'Lagos') Value(literal:'14862000') Value(uri:'http://www.wikidata.org/entity/Q1033') Value(literal:'Nigeria')
Value(uri:'http://www.wikidata.org/entity/Q406') Value(literal:'Istanbul') Value(literal:'14657434') Value(uri:'http://www.wikidata.org/entity/Q43') Value(literal:'Turkey')
Value(uri:'http://www.wikidata.org/entity/Q1490') Value(literal:'Tokyo') Value(literal:'14049146') Value(uri:'http://www.wikidata.org/entity/Q17') Value(literal:'Japan')
Value(uri:'http://www.wikidata.org/entity/Q16572') Value(literal:'Guangzhou') Value(literal:'14043500') Value(uri:'http://www.wikidata.org/entity/Q148') Value(literal:"People's Republic of China")
WolfgangFahl commented 2 years ago

Ten largest cities of the world

Wikidata SPARQL query showing the 10 most populated cities of the world using the million city class Q1637706 for selection

query

# Ten Largest cities of the world 
# WF 2021-08-23
# see also http://wiki.bitplan.com/index.php/PyLoDStorage#Examples
# see also https://github.com/WolfgangFahl/pyLoDStorage/issues/46
SELECT DISTINCT ?city ?cityLabel ?population ?country ?countryLabel 
WHERE {
  VALUES ?cityClass { wd:Q1637706}.
  ?city wdt:P31 ?cityClass .
  ?city wdt:P1082 ?population .
  ?city wdt:P17 ?country .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}
ORDER BY DESC(?population)
LIMIT 10

try it!

result

city cityLabel population country countryLabel
http://www.wikidata.org/entity/Q1353 Delhi 26495000 http://www.wikidata.org/entity/Q668 India
http://www.wikidata.org/entity/Q8686 Shanghai 24870895 http://www.wikidata.org/entity/Q148 People's Republic of China
http://www.wikidata.org/entity/Q956 Beijing 21710000 http://www.wikidata.org/entity/Q148 People's Republic of China
http://www.wikidata.org/entity/Q1354 Dhaka 16800000 http://www.wikidata.org/entity/Q902 Bangladesh
http://www.wikidata.org/entity/Q1156 Mumbai 15414288 http://www.wikidata.org/entity/Q668 India
http://www.wikidata.org/entity/Q8660 Karachi 14910352 http://www.wikidata.org/entity/Q843 Pakistan
http://www.wikidata.org/entity/Q8673 Lagos 14862000 http://www.wikidata.org/entity/Q1033 Nigeria
http://www.wikidata.org/entity/Q406 Istanbul 14657434 http://www.wikidata.org/entity/Q43 Turkey
http://www.wikidata.org/entity/Q1490 Tokyo 14049146 http://www.wikidata.org/entity/Q17 Japan
http://www.wikidata.org/entity/Q16572 Guangzhou 14043500 http://www.wikidata.org/entity/Q148 People's Republic of China