query-3ef06132a3313f84cab8642afd2b15ef

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 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/>
#defaultView:Map
SELECT ?item ?itemLabel ?area ?geoshape ?layer ?rgb (CONCAT("neighbours: ", GROUP_CONCAT(DISTINCT(?neighbour_label); separator=', ')) AS ?neighbours) 


WHERE {
   {
  SELECT ?item ?itemLabel ?area WHERE {
    ?item p:P463 ?UN_stmt . 
    ?UN_stmt ps:P463 wd:Q1065 .
    ?UN_stmt a wikibase:BestRank .
    MINUS {?UN_stmt pq:P582 []} .
    MINUS {?item wdt:P576 []} .
    ?item wdt:P2046 ?area .
    ?item rdfs:label ?itemLabel FILTER(lang(?itemLabel) = 'en') .
  }
}.
  OPTIONAL {
    FILTER NOT EXISTS {
      ?item wdt:P527?/wdt:P47/wdt:P17? ?neighbour0 .
      FILTER(?item != ?neighbour0) .
    }
    BIND("n/a" AS ?layer) .
    BIND("777777" AS ?rgb) .
  }
  OPTIONAL {
    ?item wdt:P47 [] .
    FILTER NOT EXISTS {
      ?item wdt:P527?/wdt:P47/wdt:P17? ?neighbour1 .
      ?item wdt:P2046 ?area1 .
      { 
        SELECT (?item AS ?neighbour1) (?area AS ?neighbour1_area) WHERE {
           {
  SELECT ?item ?itemLabel ?area WHERE {
    ?item p:P463 ?UN_stmt . 
    ?UN_stmt ps:P463 wd:Q1065 .
    ?UN_stmt a wikibase:BestRank .
    MINUS {?UN_stmt pq:P582 []} .
    MINUS {?item wdt:P576 []} .
    ?item wdt:P2046 ?area .
    ?item rdfs:label ?itemLabel FILTER(lang(?itemLabel) = 'en') .
  }
}.
        }
      }
      FILTER (?area1 > ?neighbour1_area) .
    }
    BIND("smaller" AS ?layer) .
    BIND("CC3333" AS ?rgb) .
  }
  OPTIONAL {
    FILTER NOT EXISTS {
      ?item wdt:P527?/wdt:P47/wdt:P17? ?neighbour2 .
      ?item wdt:P2046 ?area2 .
      { 
        SELECT (?item AS ?neighbour2) (?area AS ?neighbour2_area) WHERE {
           {
  SELECT ?item ?itemLabel ?area WHERE {
    ?item p:P463 ?UN_stmt . 
    ?UN_stmt ps:P463 wd:Q1065 .
    ?UN_stmt a wikibase:BestRank .
    MINUS {?UN_stmt pq:P582 []} .
    MINUS {?item wdt:P576 []} .
    ?item wdt:P2046 ?area .
    ?item rdfs:label ?itemLabel FILTER(lang(?itemLabel) = 'en') .
  }
}.
        }
      }
      FILTER (?area2 < ?neighbour2_area) .
    }
    BIND("larger" AS ?layer) .
    BIND("88AAFF" AS ?rgb) .

  }
  OPTIONAL {?item wdt:P3896 ?geoshape} .
  OPTIONAL {?item wdt:P527/wdt:P3896 ?geoshape} .
  OPTIONAL {?item ^wdt:P361/wdt:P3896 ?geoshape} .
  OPTIONAL {
    BIND("neither" AS ?layer) .
    BIND("DDDDDD" AS ?rgb) .

  }
  OPTIONAL {
    ?item wdt:P527?/wdt:P47/wdt:P17? ?neighbour .
    {
      SELECT (?item AS ?neighbour) (?itemLabel AS ?neighbour_label )WHERE {
           {
  SELECT ?item ?itemLabel ?area WHERE {
    ?item p:P463 ?UN_stmt . 
    ?UN_stmt ps:P463 wd:Q1065 .
    ?UN_stmt a wikibase:BestRank .
    MINUS {?UN_stmt pq:P582 []} .
    MINUS {?item wdt:P576 []} .
    ?item wdt:P2046 ?area .
    ?item rdfs:label ?itemLabel FILTER(lang(?itemLabel) = 'en') .
  }
}.
      }
    }
  }
} GROUP BY ?item ?itemLabel ?area ?geoshape ?layer ?rgb
ORDER BY ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?UN_stmt") v7("?area"):::projected v8("?area1") v2("?area2") v14("?geoshape"):::projected v4("?item"):::projected v1("?itemLabel"):::projected v15("?layer"):::projected v16("?neighbour") v11("?neighbour0") v11("?neighbour1") v11("?neighbour1_area") v8("?neighbour2") v8("?neighbour2_area") v16("?neighbour_label") v17("?neighbours") v15("?rgb"):::projected a11((" ")) a12((" ")) a13((" ")) a7((" ")) a8((" ")) a3((" ")) a4((" ")) a18((" ")) a19((" ")) a9((" ")) a10((" ")) a5((" ")) a6((" ")) a1((" ")) a2((" ")) a14((" ")) a15((" ")) a16((" ")) a17((" ")) c10(["wikibase:BestRank"]):::iri c8(["wd:Q1065"]):::iri f0[["?itemLabel = 'en'"]] f0 --> v1 v4 --"p:P463"--> v6 v6 --"p:statement/P463"--> c8 v6 --"a"--> c10 subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; v6 --"p:qualifier/P582"--> a11 end subgraph minus2["MINUS"] style minus2 stroke-width:6px,fill:pink,stroke:red; v4 --"p:direct/P576"--> a12 end v4 --"p:direct/P2046"--> v7 v4 --"rdfs:label"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; bind3[/"'n/a'"/] bind3 --as--o v15 bind4[/"'777777'"/] bind4 --as--o v15 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P47".-> a13 bind5[/"'smaller'"/] bind5 --as--o v15 bind6[/"'CC3333'"/] bind6 --as--o v15 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; bind7[/"'larger'"/] bind7 --as--o v15 bind8[/"'88AAFF'"/] bind8 --as--o v15 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P3896".-> v14 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P527".-> a14 a14 --"p:direct/P3896"--> v14 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; a15 -."p:direct/P361".-> v4 a15 --"p:direct/P3896"--> v14 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; bind9[/"'neither'"/] bind9 --as--o v15 bind10[/"'DDDDDD'"/] bind10 --as--o v15 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v4 -."p:direct/P527".-> a16 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; end union0r <== or ==> union0l end a16 --"p:direct/P47"--> a17 subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; a17 --"p:direct/P17"--> v16 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; end union1r <== or ==> union1l end f11[["?itemLabel = 'en'"]] f11 --> v1 v4 --"p:P463"--> v6 v6 --"p:statement/P463"--> c8 v6 --"a"--> c10 subgraph minus12["MINUS"] style minus12 stroke-width:6px,fill:pink,stroke:red; v6 --"p:qualifier/P582"--> a18 end subgraph minus13["MINUS"] style minus13 stroke-width:6px,fill:pink,stroke:red; v4 --"p:direct/P576"--> a19 end v4 --"p:direct/P2046"--> v7 v4 --"rdfs:label"--> v1 bind14[/"?item"/] v4 --o bind14 bind14 --as--o v16 bind15[/"?itemLabel"/] v1 --o bind15 bind15 --as--o v16 end bind17[/"concat('neighbours: ',)"/] null --o bind17 bind17 --as--o v17