0

I am trying to get the country of a Wikidata item using SPARQL. I am quite new and I am not able to obtain only the property country (P17) and its label.

I used this example and I am able to obtain all properties. Link.

In this case using the output of a previous query, for example, I get the item Q1492 corresponding to Barcelona. How can I obtain its country, Spain?

Javi Rando
  • 13
  • 3
  • 1
    spoiler: `SELECT ?country WHERE { wd:Q1492 wdt:P17 ?country }` is the most basic query to achieve what you want – UninformedUser Aug 11 '19 at 11:33
  • not sure why my first comment was deleted, but fair enough SO mods – UninformedUser Aug 11 '19 at 13:23
  • @AKSW Yeah! That's exactly it but is there a way to obtain the name directly and not the wikidata ID? – Javi Rando Aug 11 '19 at 15:21
  • Of course: `SELECT ?countryLabel WHERE { wd:Q1492 wdt:P17 ?country SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }}` - or with standard SPARQL to understand what the label service does: `SELECT ?countryLabel WHERE { wd:Q1492 wdt:P17 ?country. ?country rdfs:label ?countryLabel filter(lang(?countryLabel) = "en") }` – UninformedUser Aug 11 '19 at 16:00

0 Answers0