1

I try to find a city based on a part of its name (typically https://en.wikipedia.org/wiki/Lavo%C3%BBte-sur-Loire, a French city)

The only way I found is to first request for "Lavoute" (without accent) through the following request.

https://fr.wikipedia.org/w/api.php?action=opensearch&generator=links&format=xml&search=lavoute&prop=pageprops&gpllimit=50&ppprop=wikibase_item&format=json

It returns 5 links and then use this information to request through all the results having something like this at the end with the good value (having property P281 means it is a city)

https://www.wikidata.org/w/api.php?action=wbgetentities&titles=Lavo%C3%BBte-sur-Loire&sites=enwiki|frwiki&format=json

Is there an easier way to do?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
William R
  • 37
  • 12
  • Try also [this](https://tools.wmflabs.org/openrefine-wikidata/en/api?query={%22query%22:%22Lavoute%22,%20%22type%22:%22Q484170%22}) – Stanislav Kralin Apr 26 '18 at 11:58

1 Answers1

5

As you said that you want to find a city based on a part of its name, here is the solution for your question:

SELECT ?location ?locationLabel WHERE {
 ?location wdt:P17 wd:Q142.
 ?location wdt:P31 ?settlement .
 ?settlement wdt:P279 wd:Q3266850 .
 ?location rdfs:label ?de_label .
 FILTER (lang(?de_label) = "en") .
 FILTER (regex((?de_label), "Lavoûte")).

 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
 }

Refer to this link, you might also get some ideas regarding your question : https://opendata.stackexchange.com/questions/11675/most-efficient-way-to-get-the-wikidata-entity-for-a-city-given-as-a-string

Coder
  • 389
  • 5
  • 15
  • Minor comment: `REGEX` is not very efficient. It is possible to invoke Wikidata API from SPARQL, see e. g. here: https://opendata.stackexchange.com/a/12502/16193, and there are other ways to emulate text search capabilities. – Stanislav Kralin Apr 27 '18 at 07:17