query-0a80d2e698972f5491e05850d95c0758

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT distinct ?item ?itemLabel ?countryLabel ?fr_article ?Wfr ?en_article ?Wen ?iata ?icao WHERE {
  ?item wdt:P31/wdt:P279* wd:Q1248784.                     # item must be an instance of an airport, or an instance that is a subclass of an airport
  optional {?item wdt:P17 ?country .                        # ?item may have a country 
           filter not exists {?country pq:P582 [].} }        # ?country that still exists              
  optional {?item p:P238 ?node .                           # item may have a P238 (IATA) node
           ?node ps:P238 ?iata.                            # and the node has a P238 (IATA) value
           filter not exists {?node pq:P582 [].}   }       # but the value is ignored if it has an end-date
  optional {?item p:P239 ?node2. 
            ?node2 ps:P239 ?icao .                         # item may have a P239 (ICAO) value  
           filter not exists {?node2 pq:P582 [].}   }      # P239 that still exists        
  optional {?Wen schema:about ?item;                       # item may have a sitelink
            schema:isPartOf <https://en.wikipedia.org/>;   # the sitelink points to en.wikipedia
            schema:name ?en_article.}                      # and has an article name
  optional {?Wfr schema:about ?item;                       # item may have a sitelink
            schema:isPartOf <https://fr.wikipedia.org/>;   # the sitelink points to fr.wikipedia 
            schema:name ?fr_article.}                      # and has an article name
  minus {?item wdt:P31/wdt:P279* wd:Q695850.}              # exclude items having instances that are military airports & subclasses thereof
  bind(coalesce(?en_article,?fr_article) as ?article)      # create ?article if there is an EN or FR wikipedia article
  minus {?item wdt:P31/wdt:P279* wd:Q695850.}      # exclude military airports
  minus {?item wdt:P31/wdt:P279* wd:Q1311670.}     # exclude railways stations
  minus {?item wdt:P31/wdt:P279* wd:Q7373622.}     # exclude Royal Air Force
  minus {?item wdt:P31/wdt:P279* wd:Q502074.}      # exclude héliports
  minus {?item wdt:P576 ?date}                     # exclude destructed airports
  minus {?item wdt:P31/wdt:P279* wd:Q44665966.}    # exclude  airports being build
  filter(bound(?article))                                  # select only if there is an ?article
  bind(coalesce(?iata,?icao) as ?code)                     # create ?code if there is an ICAO or IATA code 
  filter(bound(?code))                                     # select only if there is an ?code
  minus {?item wdt:P576 [].}                               # remove items with P576 (dissolved, abolished or demolished) as a main property
  minus {?item wdt:P582 [].}                               # remove items with P582 (end date) as a main property
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } . #this bit gets labels for Qid values
} order by ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v10("?Wen"):::projected v12("?Wfr"):::projected v14("?article") v15("?code") v6("?country") v14("?date") v11("?en_article"):::projected v13("?fr_article"):::projected v8("?iata"):::projected v9("?icao"):::projected v7("?item"):::projected v1("?itemLabel"):::projected v5("?node") v4("?node2") a3((" ")) a2((" ")) a1((" ")) a11((" ")) a12((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) a8((" ")) a9((" ")) a10((" ")) c17(["wd:Q7373622"]):::iri c12([https://en.wikipedia.org/]):::iri c23(["bd:serviceParam"]):::iri c16(["wd:Q1311670"]):::iri c15(["wd:Q695850"]):::iri c18(["wd:Q502074"]):::iri c14([https://fr.wikipedia.org/]):::iri c4(["wd:Q1248784"]):::iri c20(["wd:Q44665966"]):::iri c25(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["bound(?code)"]] f0 --> v15 f1[["bound(?article)"]] f1 --> v14 v7 --"p:direct/P31"--> a4 a4 --"p:direct/P279"--> c4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."p:direct/P17".-> v6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v7 -."p:P238".-> v5 v5 --"p:statement/P238"--> v8 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v7 -."p:P239".-> v4 v4 --"p:statement/P239"--> v9 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v10 -."schema:about".-> v7 v10 --"schema:isPartOf"--> c12 v10 --"schema:name"--> v11 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v12 -."schema:about".-> v7 v12 --"schema:isPartOf"--> c14 v12 --"schema:name"--> v13 end subgraph minus2["MINUS"] style minus2 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P31"--> a5 a5 --"p:direct/P279"--> c15 end bind3[/"?en_article?fr_article"/] v11 --o bind3 v13 --o bind3 bind3 --as--o v14 subgraph minus4["MINUS"] style minus4 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P31"--> a6 a6 --"p:direct/P279"--> c15 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P31"--> a7 a7 --"p:direct/P279"--> c16 end subgraph minus6["MINUS"] style minus6 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P31"--> a8 a8 --"p:direct/P279"--> c17 end subgraph minus7["MINUS"] style minus7 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P31"--> a9 a9 --"p:direct/P279"--> c18 end subgraph minus8["MINUS"] style minus8 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P576"--> v14 end subgraph minus9["MINUS"] style minus9 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P31"--> a10 a10 --"p:direct/P279"--> c20 end bind10[/"?iata?icao"/] v8 --o bind10 v9 --o bind10 bind10 --as--o v15 subgraph minus11["MINUS"] style minus11 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P576"--> a11 end subgraph minus12["MINUS"] style minus12 stroke-width:6px,fill:pink,stroke:red; v7 --"p:direct/P582"--> a12 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c23 --"wikibase:language"--> c25 end