query-da874ffb7fd912d4428de901665c6cf9
TODO
Use at
- https://query.wikidata.org/sparql
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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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 ?item ?itemLabel ?sitelink (group_concat(distinct ?serve;separator=", ") as ?serves) (group_concat(distinct ?iata_c;separator=", ") as ?iata) (group_concat(distinct ?icao_c;separator=", ") as ?icao) ?end_date
WHERE {
  VALUES ?type {wd:Q1248784 wd:Q695850 wd:Q62447 }         # define a list of airport / military airbase / aerodrome 
  ?item p:P31 ?statement.                                  # item has a P31 property
  ?statement ps:P31 ?type.                                 # which resolves to something in the list above
  ?statement pq:P582 ?end_date.                            # and which has an end time qualifier
  optional {?item wdt:P238 ?iata_c .}                      # item may have a P238 (IATA) value
  optional {?item wdt:P239 ?icao_c .}                      # item may have has a P239 (ICAO) value         
  optional {?item wdt:P931 ?place_served .                 # item may have a value for P931  
           ?place_served rdfs:label ?serve.                # and if so, we get the label for the value directly (so group_concat will work)
           filter(lang(?serve)="en")}                      # but we only get the english language label
  ?sitelink schema:about ?item;                            # item has a sitelink
            schema:isPartOf <https://en.wikipedia.org/>.   # the sitelink points to en.wikipedia
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } . #this bit gets labels for Qid values
} group by ?item ?itemLabel ?sitelink ?end_date order by ?itemLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?end_date"):::projected 
  v12("?iata")
  v7("?iata_c"):::projected 
  v13("?icao")
  v8("?icao_c"):::projected 
  v4("?item"):::projected 
  v1("?itemLabel"):::projected 
  v9("?place_served")
  v2("?serve"):::projected 
  v11("?serves")
  v10("?sitelink"):::projected 
  v5("?statement")
  v3("?type")
  c11([https://en.wikipedia.org/]):::iri 
  c13(["bd:serviceParam"]):::iri 
  c15(["#91;AUTO_LANGUAGE#93;,en"]):::literal 
  bind0[/VALUES ?type/]
  bind0-->v3
  bind00(["wd:Q1248784"])
  bind00 --> bind0
  bind01(["wd:Q695850"])
  bind01 --> bind0
  bind02(["wd:Q62447"])
  bind02 --> bind0
  v4 --"p:P31"-->  v5
  v5 --"p:statement/P31"-->  v3
  v5 --"p:qualifier/P582"-->  v6
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v4 -."p:direct/P238".->  v7
  end
  subgraph optional1["(optional)"]
  style optional1 fill:#bbf,stroke-dasharray: 5 5;
    v4 -."p:direct/P239".->  v8
  end
  subgraph optional2["(optional)"]
  style optional2 fill:#bbf,stroke-dasharray: 5 5;
    v4 -."p:direct/P931".->  v9
    v9 --"rdfs:label"-->  v2
  end
  v10 --"schema:about"-->  v4
  v10 --"schema:isPartOf"-->  c11
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c13 --"wikibase:language"-->  c15
  end
  bind4[/"?serve"/]
  v2 --o bind4
  bind4 --as--o v11
  bind5[/"?iata_c"/]
  v7 --o bind5
  bind5 --as--o v12
  bind6[/"?icao_c"/]
  v8 --o bind6
  bind6 --as--o v13