Project:SPARQL/examples: Difference between revisions

Line 2,798: Line 2,798:
order by ?bn_label
order by ?bn_label
</sparql>
</sparql>
=== Archaeological sites/Historic houses and their owners/operators in Wikidata ===
<sparql tryit="1">
#title:archaeological sites/historic houses in wikidata
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 . } # instance of archaeological site
  union
  { ?item bnwdt:P12 bnwd:Q2961 . } # instance of historic house
 
  ?item bnwdt:P12 ?instance .  # which instance of is it
  filter ( ?instance in (bnwd:Q86, bnwd:Q2961) ) . # (need filter as a few have multiple instance of)
 
    ?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  .} # can be individuals and multiple.
      optional { ?wikidata wdt:P137 ?wd_operator . }
     
      optional { ?wikidata wdt:P463 ?wd_member . }
     
      ## at least some had *both* owned by *and* operator, but not always the case.
      ## owned by P127 / operator P137 
      ## English Heritage Q936287  National Trust (Q333515)
      ## member of P463  Historic Houses Association (Q5773523)
     
      # automatic *Label doesn't work with a federated query; rdfs:label instead.     
        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.
              }
      } 
  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 or belong to Historic Houses Association ====
<sparql tryit="1">
# archaeological site or historic house.
# pull together via Wikidata which ones are owned/operated by 1) English Heritage 2) National Trust  or 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 . }
      optional { ?wikidata wdt:P463 ?wd_member . }
      # filter: owner or operator = EH/NT / member of HHA
        filter ( ?wd_owner in (wd:Q936287, wd:Q333515) ||
                ?wd_operator in (wd:Q936287, wd:Q333515) ||
                ?wd_member = wd:Q5773523 ) .
      ## 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". }
}
order by ?itemLabel
</sparql>
== Men ==


=== BN Men in Wikidata ===
=== BN Men in Wikidata ===
Line 3,039: Line 3,160:
</sparql>
</sparql>


=== Archaeological sites/Historic houses and their owners/operators in Wikidata ===
 
=== BN Men who proposed, seconded or signed for Women in SAL/RAI/RHS elections, with counts and wikidata IDs ===


<sparql tryit="1">
<sparql tryit="1">
#title:archaeological sites/historic houses in wikidata
#title:Men who supported women (at least twice) for SAL/RAI/RHS election with Wikidata IDs


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 3,052: Line 3,174:
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
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
# p155, p156 - signed rhs
 
# p32, p82 - signed sal|
WHERE { 
# p8 rai seconded
 
  { ?item bnwdt:P12 bnwd:Q86 . } # instance of archaeological site
  union
  { ?item bnwdt:P12 bnwd:Q2961 . } # instance of historic house
 
  ?item bnwdt:P12 ?instance .  # which instance of is it
  filter ( ?instance in (bnwd:Q86, bnwd:Q2961) ) . # (need filter as a few have multiple instance of)
 
    ?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  .} # can be individuals and multiple.
      optional { ?wikidata wdt:P137 ?wd_operator . }
     
      optional { ?wikidata wdt:P463 ?wd_member . }
     
      ## at least some had *both* owned by *and* operator, but not always the case.
      ## owned by P127 / operator P137 
      ## English Heritage Q936287 National Trust (Q333515)
      ## member of P463  Historic Houses Association (Q5773523)
     
      # automatic *Label doesn't work with a federated query; rdfs:label instead.     
        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.
              }
      } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
order by ?itemLabel


</sparql>
SELECT  ?supporterLabel ?supporter  ?wikidata (count(?supporter) as ?supported)


==== And which are owned/operated by English Heritage/National Trust or belong to Historic Houses Association ====
WHERE {
 
<sparql tryit="1">
 
# archaeological site or historic house.
# pull together via Wikidata which ones are owned/operated by 1) English Heritage 2) National Trust  or 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
  ?person bnwdt:P3 bnwd:Q3 .
 
WHERE { 
    
    
   { ?item bnwdt:P12 bnwd:Q86 . }
   {
    ?person (  bnp:P155 | bnp:P156 | bnp:P16 | bnp:P7 ) ?s .  #
      ?s ( bnps:P155 | bnps:P156 | bnps:P16 | bnps:P7 ) ?supporter  . # proposed SAL/RAI / signed RHS
      #?s ?prop ?supporter .  
    }
  #  union for qualifiers
   union
   union
   { ?item bnwdt:P12 bnwd:Q2961 . }
   {
  ?person ?p ?s .
    ?s (  bnpq:P156 | bnpq:P155 | bnpq:P32 | bnpq:P82 | bnpq:P8 ) ?supporter .
    #?s ?prop ?supporter .
  }
    
    
  ?item bnwdt:P12 ?instance .
    ?supporter bnwdt:P3 bnwd:Q10 .  # male
  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 . }
      optional { ?wikidata wdt:P463 ?wd_member . }
 
      # filter: owner or operator = EH/NT / member of HHA
        filter ( ?wd_owner in (wd:Q936287, wd:Q333515) ||
                ?wd_operator in (wd:Q936287, wd:Q333515) ||
                ?wd_member = wd:Q5773523 ) .
 
      ## 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". }  
    optional {
      ?supporter bnwdt:P117 ?wikidata_ID . #get wikidata ID
      bind(iri(concat("http://www.wikidata.org/entity/", str(?wikidata_ID))) as ?wikidata) .
      }
     
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en, en-gb". }  
}
}
 
group by ?supporterLabel ?supporter ?wikidata
order by ?itemLabel
having (?supported>2)
 
ORDER BY desc(?supported) desc(?wikidata)
</sparql>
</sparql>


579

edits