Project:SPARQL/examples: Difference between revisions

From Beyond Notability
Line 2,627: Line 2,627:
               }  
               }  
       }   
       }   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
order by ?itemLabel
</sparql>
==== And which are owned/operated by English Heritage/National Trust ====
<sparql tryit="1">
# archaeological site or historic house.
# pull together via Wikidata which ones are owned/operated by 1) English Heritage 2) National Trust 
# and then 3) affiliated to Historic Houses association
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT distinct ?item ?itemLabel ?instanceLabel ?wikidata ?wd_owner_label ?wd_operator_label ?wd_member_label  #?wd_owner ?wd_operator
WHERE { 
 
  { ?item bnwdt:P12 bnwd:Q86 . }
  union
  { ?item bnwdt:P12 bnwd:Q2961 . }
 
  ?item bnwdt:P12 ?instance .
  filter ( ?instance in (bnwd:Q86, bnwd:Q2961) ) .
  ?item bnwdt:P117 ?wikidata_id .
    bind(iri(concat("http://www.wikidata.org/entity/", str(?wikidata_id))) as ?wikidata) .
               
    SERVICE <https://query.wikidata.org/sparql> {
      optional { ?wikidata wdt:P127 ?wd_owner .}
      optional { ?wikidata wdt:P137 ?wd_operator . }
     
        # filter: owner or operator = EH/NT
        filter ( ?wd_owner in (wd:Q936287, wd:Q333515) || ?wd_operator in (wd:Q936287, wd:Q333515)  ) .
      # member of P463 is the property for HHA
      optional { ?wikidata wdt:P463 ?wd_member . }
      ## owned by P127 / operator P137 
      ## ENglish Heritage Q936287  National Trust (Q333515)
      ## member of P463  Historic Houses Association (Q5773523)
           
      SERVICE wikibase:label {
              bd:serviceParam wikibase:language "en".
              ?wd_owner rdfs:label ?wd_owner_label.
              ?wd_operator rdfs:label ?wd_operator_label.
              ?wd_member rdfs:label ?wd_member_label.
              }
      } 
           
  #} # /optional for wikidata ID
 
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
}
}
3,427

edits