WolfgangFahl / pyOnlineSpreadSheetEditing

python Online SpreadSheet Editing tool with configurable enhancer/importer and check phase
Apache License 2.0
2 stars 0 forks source link

add SPARQL query support #7

Closed WolfgangFahl closed 2 years ago

WolfgangFahl commented 2 years ago

use an example from pyLodStorage such as:

 {
            "endpoint":"https://query.wikidata.org/sparql",
            "prefixes": ["http://www.wikidata.org/entity/"],
            "lang": "sparql",
            "name": "CityTop10",
            "title": "Ten largest cities of the world",
            "description": "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"""
            }
# 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
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
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")