query-5287004f062d8c4d7a51cfd6fdf72a47

rq turtle/ttl

Query to Obtain City of the Airport [SOLVED]) However I am having difficulties trying to get the city where the airport is located. https://w.wiki/jxoI am interested in learning which airport is located in which city. With a little bit of work I had the code of looking up the airport from its ICAO code working.( looks promising, but a few attempts reveals that it would not only return the city of the airport, but also the province, the state, the municipality, etc. For example, RJAA (Narita International Airport near Tokyo, Japan) has both Narita (the city) and Chiba Perfecture listed there, KUNV (University Park Airport in State College, Pennsylvania, USA) only has Pensylvania listed, and ZSQD (Qingdao Liuting International Airport in Qingdao, Shandong, China) only has Chengyang District (one level lower than city) listed. (P131)located in the administrative territorial entity I came with two solutions but failed to put the codes together. and set up a filter to remove anything that is not a city. wdt:P131The first solution is to keep using the

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?airport ?airportLabel ?airportIn ?airportInLabel ?airportInType ?airportInTypeLabel WHERE {
  ?airport wdt:P239 "RJAA".
  { ?airport wdt:P131 ?airportIn. }
  { ?airportIn wdt:P31 ?airportInType. }
  FILTER(EXISTS { ?airportInType wdt:P279 wd:Q515. })
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?airport"):::projected v3("?airportIn"):::projected v1("?airportInType"):::projected c8(["bd:serviceParam"]):::iri c2(["wd:Q515"]):::iri c10(["en"]):::literal c4(["RJAA"]):::literal f0[[" "]] subgraph f0e0["Exists Clause"] e0v1 --"wdt:P279"--> e0c2 e0v1("?airportInType"):::projected e0c2(["wd:Q515"]):::iri end f0--EXISTS--> f0e0 f0 --> v1 f0 --> c1 f0 --> c2 v1 --"wdt:P279"--> c2 v2 --"wdt:P239"--> c4 v2 --"wdt:P131"--> v3 v3 --"wdt:P31"--> v1 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end