The Shœstring Foundation Weblog

The Shœstring Foundation Weblog, Miscellaneous Byproducts

Matthias Bauer
bauerm (at) shoestringfoundation · org
reop pubkey
Vignettes by George Herriman and a small program

Subscribe to a syndicated feed of my weblog, brought to you by the wonders of RSS.

Blosxom Logo

Mon, 21 Jan 2019

Sparql, Smarql, Omsk and Tomsk

Task: Use Wikidata to find all Russian or Ukrainian or Belorussian towns/cities/... with names ending in "sk" (old Tom Lehrer reference:
I have a friend in Minsk
who has a friend in Pinsk
whose friend in Omsk
has friend in Tomsk
with friend in Akmolinsk...

Turns out not to be so easy:
not every city (Q7930989) is a human settlement (Q486972), so take the UNION.

"Located in country" (P17) seemed the only reasonable relation of cities and countries, so iterate that over Russia (Q159), Belarussia (Q184) and Ukraina (Q212) but it turns out that at least Omsk (Q898) is not in the country of Russia (Q159) but instead is an "instance of" (P31) an "administrative territorial entity of Russia" (Q192287), so UNION over "administrative territorial entities" of Russia and Ukrainia.

Turns out that there is an "administrative territorial entity of Crimea", so who knows what other non-orthogonal classifications people used to enter ex-Soviet cities into WikiData. Not exactly promising.

SELECT DISTINCT ?city ?cityLabel WHERE {
  { ?city wdt:P31 wd:Q486972. }
  { ?city wdt:P31 wd:Q7930989. }
  { ?city wdt:P17 wd:Q159. }
  { ?city wdt:P17 wd:Q212. }
  { ?city wdt:P17 wd:Q184. }
  { ?city wdt:P31 wd:Q192287. }
  { ?city wdt:P31 wd:Q203323. }
  ?city rdfs:label ?cityLabel.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  FILTER(STRENDS(?cityLabel, "sk"))
(Click to run the query)

UPDATE: Omsk (Q898) is infact "in the country" (P17) of Russia (Q159), my oversight.

[/unsorted] permanent link