query-a47869445d9061132147dd981995b1e9

rq turtle/ttl

Monuments (1080 results)Technical notes User:Valerio Bozzolan Query operator User:Superchilum Query requesterThis query uses a simple regional flat-query, with a COALESCE-trick to filter elements with at least one important identifier (instead of doing an avalanche of UNIONs for each important identifier). Since we are GROUP-ing results by item (to show, for each result, their multiple instances), we activated the automatic label-service from a parent query, since it cannot work otherwise. The instance-of labels are manually queried, since otherwise they cannot be grouped successfully. The SAMPLE() function does nothing special, it is just to have a working selection after the GROUP BY ?item. Think of it as just your column (in this specific case).

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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?itemLabel ?itemDescription ?istanze ?designazione_del_patrimonioLabel ?comuneLabel ?provinciaLabel ?indirizzo ?coordinate ?coordinateCount ?proprietarioLabel ?gestoreLabel ?item ?wikipedia ?commons ?cat_commons ?immagine ?wlmid ?approvatoLabel ?data_inizio ?data_fine ?data_unica ?applicaLabel ?mibactid ?vincoli_in_rete ?ICCD_S ?ICCD_CF ?ICCD_CG ?ICCD_sito ?ICCD_BC WHERE {
  {
    # sub-query without any automatic label (only manual labels)
    SELECT
      ?item
      (GROUP_CONCAT(DISTINCT ?istanza_diNome; SEPARATOR = "; ") AS ?istanze)
      (SAMPLE( ?designazione_del_patrimonio ) AS ?designazione_del_patrimonio )
      (SAMPLE( ?comune )          AS ?comune )
      (SAMPLE( ?provincia )       AS ?provincia )
      (SAMPLE( ?indirizzo )       AS ?indirizzo )
      (COUNT(DISTINCT ?coordinate)AS ?coordinateCount )
      (SAMPLE( ?coordinate )      AS ?coordinate )
      (SAMPLE( ?proprietario )    AS ?proprietario )
      (SAMPLE( ?gestore )         AS ?gestore )
      (SAMPLE( ?wikipedia )       AS ?wikipedia )
      (SAMPLE( ?commons )         AS ?commons )
      (SAMPLE( ?cat_commons )     AS ?cat_commons )
      (SAMPLE( ?immagine )        AS ?immagine )
      (SAMPLE( ?wlmid )           AS ?wlmid )
      (SAMPLE( ?approvato )       AS ?approvato )
      (SAMPLE( ?data_inizio )     AS ?data_inizio )
      (SAMPLE( ?data_fine )       AS ?data_fine )
      (SAMPLE( ?data_unica )      AS ?data_unica )
      (SAMPLE( ?applica )         AS ?applica )
      (SAMPLE( ?mibactid )        AS ?mibactid )
      (SAMPLE( ?vincoli_in_rete ) AS ?vincoli_in_rete )
      (SAMPLE( ?ICCD_S )          AS ?ICCD_S )
      (SAMPLE( ?ICCD_CF )         AS ?ICCD_CF )
      (SAMPLE( ?ICCD_CG )         AS ?ICCD_CG )
      (SAMPLE( ?ICCD_sito )       AS ?ICCD_sito )
      (SAMPLE( ?ICCD_BC )         AS ?ICCD_BC )
    WHERE {

      # only requirement: stuff in Liguria
      ?item (wdt:P131*) wd:Q1256.

      # remove some unuseful stuff
      MINUS {
        VALUES ?denylist {
          wd:Q3914     # school
          wd:Q2824645  # administrative divisions of Italy
          wd:Q26907166 # temporal entity
        }
        ?item (wdt:P31/(wdt:P279*)) ?denylist.
      }

      # basically everything is optional
      OPTIONAL {
        ?item p:P2186 ?wlmst.
        ?wlmst ps:P2186 ?wlmid.
        OPTIONAL {
          ?wlmst pqv:P580 _:b48.
          _:b48 wikibase:timeValue ?data_inizio.
        }
        OPTIONAL {
          ?wlmst pqv:P582 _:b49.
          _:b49 wikibase:timeValue ?data_fine.
        }
        OPTIONAL {
          ?wlmst pqv:P585 _:b50.
          _:b50 wikibase:timeValue ?data_unica.
        }
        OPTIONAL { ?wlmst pq:P518 ?applica. }
        OPTIONAL { ?wlmst pq:P790 ?approvato. }
      }
      OPTIONAL {
        ?item wdt:P31 ?istanza_di.
        ?istanza_di rdfs:label ?istanza_diNome.
        FILTER(LANGMATCHES(LANG(?istanza_diNome), "it"))
      }
      OPTIONAL { ?item wdt:P5782 ?mibactid. }
      OPTIONAL { ?item wdt:P4249 ?vincoli_in_rete. }
      OPTIONAL { ?item wdt:P6286 ?ICCD_S. }
      OPTIONAL { ?item wdt:P6287 ?ICCD_CF. }
      OPTIONAL { ?item wdt:P6288 ?ICCD_CG. }
      OPTIONAL { ?item wdt:P9050 ?ICCD_sito. }
      OPTIONAL { ?item wdt:P9051 ?ICCD_BC. }
      OPTIONAL { ?item wdt:P1435 ?designazione_del_patrimonio. }
      OPTIONAL { ?item wdt:P131  ?comune. }
      OPTIONAL {
        VALUES ?typeProvincia {
          wd:Q15089
          wd:Q15110
        }
        ?item     (wdt:P131*) ?provincia.
        ?provincia wdt:P31    ?typeProvincia.
      }
      OPTIONAL { ?item wdt:P6375 ?indirizzo. }
      OPTIONAL { ?item wdt:P625  ?coordinate. }
      OPTIONAL { ?item wdt:P127  ?proprietario. }
      OPTIONAL { ?item wdt:P126  ?gestore. }
      OPTIONAL {
        ?wikipedia schema:about ?item;
          schema:isPartOf <https://it.wikipedia.org/>.
      }
      OPTIONAL {
        ?commons schema:about ?item;
          schema:isPartOf <https://commons.wikimedia.org/>.
      }
      OPTIONAL { ?item wdt:P373 ?cat_commons. }
      OPTIONAL { ?item wdt:P18  ?immagine. }

      # and must have at least one of these important fields
      BIND( COALESCE(
        ?wlmid,
        ?mibactid,
        ?ICCD_S,
        ?ICCD_CF,
        ?ICCD_CG,
        ?ICCD_sito,
        ?ICCD_BC
      ) AS ?whatever_important_field )

      # no important field, no party
      FILTER( ?whatever_important_field != "" )
    }

    GROUP BY ?item
  }

  # apply the label service only after the subquery is resolved
  SERVICE wikibase:label { bd:serviceParam wikibase:language "it,en". }
}
ORDER BY ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v35("?ICCD_BC"):::projected v35("?ICCD_CF"):::projected v35("?ICCD_CG"):::projected v35("?ICCD_S"):::projected v35("?ICCD_sito"):::projected v35("?applica") v35("?approvato") v35("?cat_commons"):::projected v35("?commons"):::projected v34("?comune") v35("?coordinate"):::projected v34("?coordinateCount"):::projected v35("?data_fine"):::projected v35("?data_inizio"):::projected v35("?data_unica"):::projected v5("?denylist") v34("?designazione_del_patrimonio") v35("?gestore") v35("?immagine"):::projected v34("?indirizzo"):::projected v13("?istanza_di") v3("?istanza_diNome") v33("?istanze"):::projected v4("?item"):::projected v1("?itemLabel"):::projected v35("?mibactid"):::projected v35("?proprietario") v34("?provincia") v23("?typeProvincia") v35("?vincoli_in_rete"):::projected v33("?whatever_important_field") v35("?wikipedia"):::projected v35("?wlmid"):::projected v6("?wlmst") a2((" ")) a3((" ")) a4((" ")) a1((" ")) c30([https://it.wikipedia.org/]):::iri c35(["bd:serviceParam"]):::iri c31([https://commons.wikimedia.org/]):::iri c37(["it,en"]):::literal c4(["wd:Q1256"]):::iri f0[["?whatever_important_field != ''"]] f0 --> v33 v4 --"p:direct/P131"--> c4 subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; bind2[/VALUES ?denylist/] bind2-->v5 bind20(["wd:Q3914"]) bind20 --> bind2 bind21(["wd:Q2824645"]) bind21 --> bind2 bind22(["wd:Q26907166"]) bind22 --> bind2 v4 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> v5 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:P2186".-> v6 v6 --"p:statement/P2186"--> v35 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:qualifier/value/P580".-> a2 a2 --"wikibase:timeValue"--> v35 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:qualifier/value/P582".-> a3 a3 --"wikibase:timeValue"--> v35 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:qualifier/value/P585".-> a4 a4 --"wikibase:timeValue"--> v35 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:qualifier/P518".-> v35 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:qualifier/P790".-> v35 end end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P31".-> v13 v13 --"rdfs:label"--> v3 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P5782".-> v35 end subgraph optional8["(optional)"] style optional8 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P4249".-> v35 end subgraph optional9["(optional)"] style optional9 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P6286".-> v35 end subgraph optional10["(optional)"] style optional10 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P6287".-> v35 end subgraph optional11["(optional)"] style optional11 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P6288".-> v35 end subgraph optional12["(optional)"] style optional12 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P9050".-> v35 end subgraph optional13["(optional)"] style optional13 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P9051".-> v35 end subgraph optional14["(optional)"] style optional14 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P1435".-> v34 end subgraph optional15["(optional)"] style optional15 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P131".-> v34 end subgraph optional16["(optional)"] style optional16 fill:#bbf,stroke-dasharray: 5 5; bind3[/VALUES ?typeProvincia/] bind3-->v23 bind30(["wd:Q15089"]) bind30 --> bind3 bind31(["wd:Q15110"]) bind31 --> bind3 v4 -."p:direct/P131".-> v34 v34 --"p:direct/P31"--> v23 end subgraph optional17["(optional)"] style optional17 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P6375".-> v34 end subgraph optional18["(optional)"] style optional18 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P625".-> v35 end subgraph optional19["(optional)"] style optional19 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P127".-> v35 end subgraph optional20["(optional)"] style optional20 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P126".-> v35 end subgraph optional21["(optional)"] style optional21 fill:#bbf,stroke-dasharray: 5 5; v35 -."schema:about".-> v4 v35 --"schema:isPartOf"--> c30 end subgraph optional22["(optional)"] style optional22 fill:#bbf,stroke-dasharray: 5 5; v35 -."schema:about".-> v4 v35 --"schema:isPartOf"--> c31 end subgraph optional23["(optional)"] style optional23 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P373".-> v35 end subgraph optional24["(optional)"] style optional24 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P18".-> v35 end bind4[/"?wlmid?mibactid?ICCD_S?ICCD_CF?ICCD_CG?ICCD_sito?ICCD_BC"/] v35 --o bind4 v35 --o bind4 v35 --o bind4 v35 --o bind4 v35 --o bind4 v35 --o bind4 v35 --o bind4 bind4 --as--o v33 bind31[/"?istanza_diNome"/] v3 --o bind31 bind31 --as--o v33 bind32[/"sample(?designazione_del_patrimonio)"/] v34 --o bind32 bind32 --as--o v34 bind33[/"sample(?comune)"/] v34 --o bind33 bind33 --as--o v34 bind34[/"sample(?provincia)"/] v34 --o bind34 bind34 --as--o v34 bind35[/"sample(?indirizzo)"/] v34 --o bind35 bind35 --as--o v34 bind36[/"count(?coordinate)"/] v35 --o bind36 bind36 --as--o v34 bind37[/"sample(?coordinate)"/] v35 --o bind37 bind37 --as--o v35 bind38[/"sample(?proprietario)"/] v35 --o bind38 bind38 --as--o v35 bind39[/"sample(?gestore)"/] v35 --o bind39 bind39 --as--o v35 bind40[/"sample(?wikipedia)"/] v35 --o bind40 bind40 --as--o v35 bind41[/"sample(?commons)"/] v35 --o bind41 bind41 --as--o v35 bind42[/"sample(?cat_commons)"/] v35 --o bind42 bind42 --as--o v35 bind43[/"sample(?immagine)"/] v35 --o bind43 bind43 --as--o v35 bind44[/"sample(?wlmid)"/] v35 --o bind44 bind44 --as--o v35 bind45[/"sample(?approvato)"/] v35 --o bind45 bind45 --as--o v35 bind46[/"sample(?data_inizio)"/] v35 --o bind46 bind46 --as--o v35 bind47[/"sample(?data_fine)"/] v35 --o bind47 bind47 --as--o v35 bind48[/"sample(?data_unica)"/] v35 --o bind48 bind48 --as--o v35 bind49[/"sample(?applica)"/] v35 --o bind49 bind49 --as--o v35 bind50[/"sample(?mibactid)"/] v35 --o bind50 bind50 --as--o v35 bind51[/"sample(?vincoli_in_rete)"/] v35 --o bind51 bind51 --as--o v35 bind52[/"sample(?ICCD_S)"/] v35 --o bind52 bind52 --as--o v35 bind53[/"sample(?ICCD_CF)"/] v35 --o bind53 bind53 --as--o v35 bind54[/"sample(?ICCD_CG)"/] v35 --o bind54 bind54 --as--o v35 bind55[/"sample(?ICCD_sito)"/] v35 --o bind55 bind55 --as--o v35 bind56[/"sample(?ICCD_BC)"/] v35 --o bind56 bind56 --as--o v35 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c35 --"wikibase:language"--> c37 end