Difference between revisions of "Geograpy"

From BITPlan Wiki
Jump to navigation Jump to search
Line 44: Line 44:
 
</source>
 
</source>
 
[https://query.wikidata.org/#%23%20get%20a%20list%20of%20human%20settlements%20having%20a%20geoName%20identifier%0A%23%20to%20add%20to%20geograpy3%20library%0A%23%20see%20https%3A%2F%2Fgithub.com%2Fsomnathrakshit%2Fgeograpy3%2Fissues%2F15%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0ASELECT%20%3Fcity%20%3FcityLabel%20%3FcityPop%20%3FgeoNameId%20%3Fcountry%20%3FcountryLabel%20%3FcountryIsoCode%20%3FcountryPopulation%0AWHERE%20%7B%0A%20%20%23%20geoName%20Identifier%0A%20%20%3Fcity%20wdt%3AP1566%20%3FgeoNameId.%0A%20%20%23%20instance%20of%20human%20settlement%20https%3A%2F%2Fwww.wikidata.org%2Fwiki%2FQ486972%0A%20%20%3Fcity%20wdt%3AP31%2Fwdt%3AP279%2a%20wd%3AQ486972%20.%0A%20%20%23%20population%20of%20city%0A%20%20OPTIONAL%20%7B%20%3Fcity%20wdt%3AP1082%20%3FcityPop.%7D%0A%0A%20%20%23%20label%20of%20the%20City%0A%20%20%3Fcity%20rdfs%3Alabel%20%3FcityLabel%20filter%20%28lang%28%3FcityLabel%29%20%3D%20%22en%22%29.%0A%20%20%23%20country%20this%20city%20belongs%20to%0A%20%20%3Fcity%20wdt%3AP17%20%3Fcountry%20.%0A%20%20%23%20label%20for%20the%20country%0A%20%20%3Fcountry%20rdfs%3Alabel%20%3FcountryLabel%20filter%20%28lang%28%3FcountryLabel%29%20%3D%20%22en%22%29.%0A%20%20%23%20https%3A%2F%2Fwww.wikidata.org%2Fwiki%2FProperty%3AP297%20ISO%203166-1%20alpha-2%20code%0A%20%20%3Fcountry%20wdt%3AP297%20%3FcountryIsoCode.%0A%20%20%23%20population%20of%20country%0A%20%20%3Fcountry%20wdt%3AP1082%20%3FcountryPopulation.%0A%20%20OPTIONAL%20%7B%0A%20%20%20%20%20%3Fcountry%20wdt%3AP2132%20%3FcountryGdpPerCapita.%0A%20%20%7D%0A%7D try it!] - you may probably experience a timeout on this query. It takes about 1 min on a local wikidata copy based on blazegraph
 
[https://query.wikidata.org/#%23%20get%20a%20list%20of%20human%20settlements%20having%20a%20geoName%20identifier%0A%23%20to%20add%20to%20geograpy3%20library%0A%23%20see%20https%3A%2F%2Fgithub.com%2Fsomnathrakshit%2Fgeograpy3%2Fissues%2F15%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0ASELECT%20%3Fcity%20%3FcityLabel%20%3FcityPop%20%3FgeoNameId%20%3Fcountry%20%3FcountryLabel%20%3FcountryIsoCode%20%3FcountryPopulation%0AWHERE%20%7B%0A%20%20%23%20geoName%20Identifier%0A%20%20%3Fcity%20wdt%3AP1566%20%3FgeoNameId.%0A%20%20%23%20instance%20of%20human%20settlement%20https%3A%2F%2Fwww.wikidata.org%2Fwiki%2FQ486972%0A%20%20%3Fcity%20wdt%3AP31%2Fwdt%3AP279%2a%20wd%3AQ486972%20.%0A%20%20%23%20population%20of%20city%0A%20%20OPTIONAL%20%7B%20%3Fcity%20wdt%3AP1082%20%3FcityPop.%7D%0A%0A%20%20%23%20label%20of%20the%20City%0A%20%20%3Fcity%20rdfs%3Alabel%20%3FcityLabel%20filter%20%28lang%28%3FcityLabel%29%20%3D%20%22en%22%29.%0A%20%20%23%20country%20this%20city%20belongs%20to%0A%20%20%3Fcity%20wdt%3AP17%20%3Fcountry%20.%0A%20%20%23%20label%20for%20the%20country%0A%20%20%3Fcountry%20rdfs%3Alabel%20%3FcountryLabel%20filter%20%28lang%28%3FcountryLabel%29%20%3D%20%22en%22%29.%0A%20%20%23%20https%3A%2F%2Fwww.wikidata.org%2Fwiki%2FProperty%3AP297%20ISO%203166-1%20alpha-2%20code%0A%20%20%3Fcountry%20wdt%3AP297%20%3FcountryIsoCode.%0A%20%20%23%20population%20of%20country%0A%20%20%3Fcountry%20wdt%3AP1082%20%3FcountryPopulation.%0A%20%20OPTIONAL%20%7B%0A%20%20%20%20%20%3Fcountry%20wdt%3AP2132%20%3FcountryGdpPerCapita.%0A%20%20%7D%0A%7D try it!] - you may probably experience a timeout on this query. It takes about 1 min on a local wikidata copy based on blazegraph
 +
 +
If your are intested in the result you can download the
 +
[http://wiki.bitplan.com/images/confident/city_wikidata_population.db Sqlite version of query result]
 +
and e.g. inspect it with the [https://sqlitebrowser.org/ DB Browser for SQLite]

Revision as of 07:55, 26 September 2020

OsProject

OsProject
edit
id  geograpy3
state  
owner  somnathrakshit
title  geograpy
url  https://github.com/somnathrakshit/geograpy3
version  0.1.15
description  
date  2020/09/26
since  
until  

Adding city details from Wikidata

Query

# get a list of human settlements having a geoName identifier
# to add to geograpy3 library
# see https://github.com/somnathrakshit/geograpy3/issues/15
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?city ?cityLabel ?cityPop ?geoNameId ?country ?countryLabel ?countryIsoCode ?countryPopulation
WHERE {
  # geoName Identifier
  ?city wdt:P1566 ?geoNameId.
  # instance of human settlement https://www.wikidata.org/wiki/Q486972
  ?city wdt:P31/wdt:P279* wd:Q486972 .
  # population of city
  OPTIONAL { ?city wdt:P1082 ?cityPop.}

  # label of the City
  ?city rdfs:label ?cityLabel filter (lang(?cityLabel) = "en").
  # country this city belongs to
  ?city wdt:P17 ?country .
  # label for the country
  ?country rdfs:label ?countryLabel filter (lang(?countryLabel) = "en").
  # https://www.wikidata.org/wiki/Property:P297 ISO 3166-1 alpha-2 code
  ?country wdt:P297 ?countryIsoCode.
  # population of country
  ?country wdt:P1082 ?countryPopulation.
  OPTIONAL {
     ?country wdt:P2132 ?countryGdpPerCapita.
  }
}

try it! - you may probably experience a timeout on this query. It takes about 1 min on a local wikidata copy based on blazegraph

If your are intested in the result you can download the Sqlite version of query result and e.g. inspect it with the DB Browser for SQLite