wikidata

Wikidata is a free and open knowledge base that can be read and edited by both humans and machines.

Wikidata acts as central storage for the structured data of its Wikimedia sister projects including Wikipedia, Wikivoyage, Wiktionary, Wikisource, and others.

Items are uniquely identified by a Q followed by a number. Properties in Wikidata have a P followed by a number

A triple can be read like a sentence (which is why it ends with a period), with a subject, a predicate, and an object: In fact, it’s possible to express the same abbreviation in SPARQL as well: if you end a triple with a semicolon (;) instead of a period, you can add another predicate-object pair. (And statement).

Query ICAO codes

SELECT ?item ?itemLabel ?id WHERE {
  ?item wdt:P239 ?id
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

SELECT DISTINCT ?id WHERE {
  ?item wdt:P239 ?id
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?id 

Query IATA codes

SELECT ?item ?itemLabel ?id WHERE {
  ?item wdt:P238 ?id
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

SELECT DISTINCT ?id WHERE {
  ?item wdt:P238 ?id
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?id 

Get items that are instances of cities of Portugal

SELECT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q15647906
  SERVICE wikibase:label { bd:serviceParam wikibase:language "pt". }
}

Get Portugal cities and their freguesias

SELECT ?item ?itemLabel ?itemDescription ?freguesia ?freguesiaLabel WHERE {
  ?item wdt:P31 wd:Q15647906 . ?item wdt:P150 ?freguesia.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "pt". }
}

SELECT ?item ?itemLabel ?itemDescription ?otherItem ?otherItemLabel ?otherItemDescription WHERE {
  # items that are instances of portuguese cities
  ?item wdt:P31 wd:Q15647906 . 
  # items that contains administrative territorial entities
  ?item wdt:P150 ?otherItem .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "pt". }
}

Get portuguese airports

SELECT ?item ?itemLabel ?itemDescription ?iataCode ?icaoCode ?coords WHERE {  
  ?item wdt:P31 wd:Q1248784 ; wdt:P17 wd:Q45 ; wdt:P238 ?iataCode; wdt:P239 ?icaoCode; wdt:P625 ?coords.  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "pt". }
}

Get portuguese international airports

SELECT ?item ?itemLabel ?itemDescription ?iataCode ?icaoCode ?coords WHERE {  
  ?item wdt:P31 wd:Q644371 ; wdt:P17 wd:Q45 ; wdt:P238 ?iataCode; wdt:P239 ?icaoCode; wdt:P625 ?coords. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "pt". }
}

Get international airports

SELECT ?item ?itemLabel ?iataCode ?icaoCode ?coords ?countryLabel WHERE {  
  ?item wdt:P31 wd:Q644371 ;  wdt:P238 ?iataCode; wdt:P239 ?icaoCode; wdt:P625 ?coords; wdt:P17 ?country  .  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Get UK airports

SELECT ?item ?itemLabel ?iataCode ?icaoCode ?coords WHERE {  
  ?item wdt:P31 wd:Q644371 ;  wdt:P238 ?iataCode; wdt:P239 ?icaoCode; wdt:P625 ?coords; wdt:P17 wd:Q145  .  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

wikidata (last edited 2022-10-07 17:09:18 by localhost)