Project:SPARQL/examples: Difference between revisions

(move admin/QC queries into a new page)
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Project:SPARQL/admin | Admin/batch tools queries]]
==SAL and RAI==
==SAL and RAI==


Line 168: Line 170:
</sparql>
</sparql>


===Women who are listed as Fellows of the Society of Antiquaries of London (FSAs) on our wikibase and who are on Wikidata, but are not listed as FSAs on Wikidata===


<sparql tryit="1">
# Women who are listed as Fellows of the Society of Antiquaries of London (FSAs) on our wikibase and who are on Wikidata, but are not listed as FSAs on 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/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd:  <http://www.wikidata.org/entity/>
SELECT ?person ?personLabel
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 . #select women
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
 
  ?person bnwdt:P75 bnwd:Q8. # find only BN subjects having a FSA (h/t @Tagishsimon)
  ?person bnwdt:P117 ?wikidata_ID . #look for wikidata ID on person page
  bind(iri(concat("http://www.wikidata.org/entity/", str(?wikidata_ID))) as ?item) .
  SERVICE <https://query.wikidata.org/sparql> {
        ?item wdt:P21 ?WD_gender. #get gender of person
        FILTER NOT EXISTS {?item wdt:P166 wd:Q26196499 . } #not FSA on Wikidata
      }
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb,en". }
}
ORDER BY ?personLabel
</sparql>


=== Women's interactions with SAL (Q1 and Q8)===
=== Women's interactions with SAL (Q1 and Q8)===


<sparql tryit="1">
<sparql tryit="1">
#title:Women's interactions with SAL (Q1 and Q8)
# CAVEAT: this query may overlook a significant number of interactions and should probably not be reference/archived in its current state
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
Line 213: Line 184:
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd:  <http://www.wikidata.org/entity/>


SELECT distinct ?person ?personLabel ?prop ?propLabel  ?pq_value ?qual_propLabel  ?sal
SELECT distinct ?person ?personLabel   ?propLabel  ?qual_value ?qual_propLabel  ?bnwdLabel # ?s ?prop ?qual_prop ?bnwd


WHERE {   
WHERE {   
Line 223: Line 192:


       ?prop wikibase:claim ?p;       
       ?prop wikibase:claim ?p;       
         wikibase:statementProperty ?ps
         wikibase:statementProperty ?ps.     
        wikibase:statementValue ?psv;
        wikibase:propertyType ?prop_type.     
      
      
       # union query to get both q8 and q1  
       # union query to get both q8 and q1  
       { ?s ?ps bnwd:Q8 . }  union { ?s ?ps bnwd:Q1 . }
       { ?s ?ps bnwd:Q8 . }  union { ?s ?ps bnwd:Q1 . }
       ?s ?ps ?sal.
       ?s ?ps ?bnwd. #which type
    
    
      optional {  
      optional {  
         ?s ?pq ?pq_value .   
         ?s ?pq ?qual_value .   
          
          
         ?qual_prop wikibase:qualifier ?pq .  
         ?qual_prop wikibase:qualifier ?pq .
        #?qual_prop rdfs:label ?qual_prop_label. filter(lang(?qual_prop_label)="en-gb") .
        #?qual_prop wikibase:propertyType ?qual_prop_type
          
          
       } # /qualifiers
       } # /qualifiers
Line 248: Line 213:


<sparql tryit="1">
<sparql tryit="1">
#title:Women's interactions with RAI (Q35 and Q29)
# CAVEAT: this query may overlook a significant number of interactions and should probably not be reference/archived in its current state
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
Line 255: Line 222:
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd:  <http://www.wikidata.org/entity/>


SELECT distinct ?person ?personLabel  ?prop ?propLabel ?prop_type ?pq_value ?pq_valueLabel ?qual_propLabel ?qual_prop_type ?rai ?s
SELECT distinct ?person ?personLabel  ?propLabel  ?qual_value ?qual_propLabel ?bnwdLabel # ?s ?prop ?qual_prop


WHERE {   
WHERE {   
Line 265: Line 230:


       ?prop wikibase:claim ?p;       
       ?prop wikibase:claim ?p;       
         wikibase:statementProperty ?ps
         wikibase:statementProperty ?ps.     
        wikibase:statementValue ?psv;
        wikibase:propertyType ?prop_type.     
      
      
       # to get both q35 and q29  
       # to get both q35 and q29  
       { ?s ?ps bnwd:Q35 . }  union { ?s ?ps bnwd:Q29 . }
       { ?s ?ps bnwd:Q35 . }  union { ?s ?ps bnwd:Q29 . }
       ?s ?ps ?rai.
       ?s ?ps ?bnwd.


       # qualifiers.  
       # qualifiers.  
       optional {  
       optional {  
         ?s ?pq ?pq_value .   
         ?s ?pq ?qual_value .   
          
          
         ?qual_prop wikibase:qualifier ?pq .   
         ?qual_prop wikibase:qualifier ?pq .   
        #?qual_prop rdfs:label ?qual_prop_label. filter(lang(?qual_prop_label)="en-gb") .
        ?qual_prop wikibase:propertyType ?qual_prop_type .
          
          
       } # /qualifiers
       } # /qualifiers
Line 294: Line 255:
#title: FSAs with no record of interacting with SAL in Q1 / Q8
#title: FSAs with no record of interacting with SAL in Q1 / Q8
# only active engagements like spoke at, corresponded with, etc, and excluding P75 "was fellow of" and P5 "archives at".
# only active engagements like spoke at, corresponded with, etc, and excluding P75 "was fellow of" and P5 "archives at".
# WIP: to update with other SAL records as I work through queries for them. Plus caveat that there may be other sources of interaction not recorded in the database!
# CAVEATS: I think this is not working as intended and it shouldn't be referenced or archived


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 342: Line 303:
#title: RAIs with no record of interacting with RAI in Q29/Q35
#title: RAIs with no record of interacting with RAI in Q29/Q35
# only active engagements like spoke at, corresponded with, etc, and excluding P67 "was member of"  
# only active engagements like spoke at, corresponded with, etc, and excluding P67 "was member of"  
# WIP: to update with other RAI records as I work through queries for them. Plus caveat that there may be other sources of interaction not recorded in the database.
# CAVEATS: I think this may not be working as intended and it shouldn't be referenced or archived in its current state


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 552: Line 513:
</sparql>
</sparql>


=== Lecturers ===


== Professional Activities and Organisations ==
<sparql tryit="1">
#title:lecturers
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/>
PREFIX bnpsv: <https://beyond-notability.wikibase.cloud/prop/statement/value/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>


=== Women's service on committees etc (P102) ===
SELECT distinct ?person ?personLabel  ?positionLabel
?organisedLabel ?ofLabel
?qual_propLabel ?qualLabel
#?position ?of  ?work ?organised  ?date_precision ?qual_prop ?date ?qual ?workLabel
?s
 
WHERE {
   
  ?person bnwdt:P3 bnwd:Q3 . # women
 
  # work activities: held position / held position (free text) /  employed as
  #?person ( bnp:P17|bnp:P48|bnp:P105 ) ?s . 
 
  ?person ?work_p ?s . # for activity type label
    ?work wikibase:claim ?work_p . 
 
    ?s ?bnps ?position . 
    # freelance and extension lecturing (q701 and q3021)
    { ?s ?bnps bnwd:Q701  . } union { ?s ?bnps bnwd:Q3021 .  }
 
    # employer / organised by / of (incl free text).
    OPTIONAL { ?s bnpq:P109 ?organised .}
    OPTIONAL { ?s ( bnpq:P78 | bnpq:P66 ) ?of .}
  # optional { ?s bnpq:P2 ?location . } # do locations separately.
   
  # dates with precision
#  optional {
#    ?s (bnpqv:P1 | bnpqv:P27 | bnpqv:P28  ) ?pqv.
#    ?s ?pqq ?pqv . # just gets the uri but doesnt seem to cause dups
#        ?pqv wikibase:timeValue ?date . 
#        ?pqv wikibase:timePrecision ?date_precision .
#    }
     
    # qualifiers
    optional {
      ?s ?pq ?qual . 
        ?qual_prop wikibase:qualifier ?pq . 
     
      } # /dates
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
 
} # /where
 
ORDER BY ?person ?s 
</sparql>
 
=== Excavations ===


<sparql tryit="1">
<sparql tryit="1">
 
#title:BN excavations
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
Line 567: Line 587:
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>


SELECT ?excavationLabel ?excavation ?locationLabel ?start ?end ?pit
?partLabel ?funderLabel ?organisedLabel ?facilitatedLabel ?directorLabel ?memberLabel
# ?member ?director  ?location ?part ?funder ?facilitated ?organised


SELECT distinct ?personLabel ?serviceLabel ?qual_propLabel  ?qualLabel  ?qual ?person ?s # ?service
WHERE {   
WHERE {   
   ?person bnwdt:P3 bnwd:Q3 . # select women
  # instance of excavation  128
  ?excavation bnwdt:P12 bnwd:Q38 .
 
    optional { ?excavation bnwdt:P2 ?location .}
 
    optional { ?excavation bnwdt:P27 ?start . }
 
    optional { ?excavation bnwdt:P28 ?end . }
 
    optional { ?excavation bnwdt:P1 ?pit. }
 
    optional { ?excavation bnwdt:P4 ?part . }
 
    optional { ?excavation bnwdt:P36 ?director . } 
 
    optional { ?excavation bnwdt:P37 ?member . }
 
    optional { ?excavation bnwdt:P109 ?organised .}
 
    optional { ?excavation bnwdt:P121 ?facilitated . }
 
    optional { ?excavation bnwdt:P145 ?funder . }
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
 
ORDER BY ?excavationLabel
</sparql>
 
== Professional Activities and Organisations ==
 
=== Women's service on committees etc (P102) ===
 
<sparql tryit="1">
 
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 ?personLabel ?serviceLabel ?qual_propLabel  ?qualLabel  ?qual ?person ?s # ?service
WHERE { 
   ?person bnwdt:P3 bnwd:Q3 . # select women
   FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
   FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
    
    
Line 782: Line 850:
       ?s ?ps ?ppa_value.
       ?s ?ps ?ppa_value.
    
    
     # note: it would be possible to write this to use ppa rather than ppa_label
     # note: it would be possible to write this to use ppa rather than ppa_label. there's a slight risk that property names might change.
     # BUT then it would be much more opaque and difficult to edit if (when!) we make any changes to the buckets.
     # BUT then it would be much more opaque and difficult to edit if (when!) we make any changes to the buckets.
     bind(
     bind(
Line 804: Line 872:
order by ?personLabel ?ppa_label
order by ?personLabel ?ppa_label
</sparql>
</sparql>


=== Suffrage-related activities ===
=== Suffrage-related activities ===
Line 879: Line 946:
==Place==
==Place==


===People not in London linked as a graph by a NUTS region or country (excluding England) at which they were once resident in the UK===
=== All the things in BN that can be mapped ===


<sparql tryit="1">
<sparql tryit="1">
# People not in London linked as a graph by a NUTS region or country (excluding England) at which they were once resident in the UK
#title:map of BN locations using wikidata P625
 
#defaultView:Map
#this will take a little while to run...
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
Line 892: Line 960:
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>


#defaultView:Graph
SELECT distinct ?locationLabel ?location ?wikidata ?wd_geo
SELECT ?resident ?residentLabel ?region ?regionLabel
 
WHERE { 
 
      ?location bnwdt:P117 ?ws .  # wikidata id       
       
        bind(iri(concat("http://www.wikidata.org/entity/", str(?ws))) as ?wikidata) .
        SERVICE <https://query.wikidata.org/sparql> {
            ?wikidata wdt:P625 ?wd_geo .  # does the wikidata page have geocoords?
        } # /wikidata service 
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?wikidata ?locationLabel
</sparql>
 
===People not in London linked as a graph by a NUTS region or country (excluding England) at which they were once resident in the UK===
 
<sparql tryit="1">
# People not in London linked as a graph by a NUTS region or country (excluding England) at which they were once resident in the UK
 
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/>
 
#defaultView:Graph
SELECT ?resident ?residentLabel ?region ?regionLabel
WHERE {   
WHERE {   
   ?resident bnwdt:P29 ?residence .
   ?resident bnwdt:P29 ?residence .
Line 1,247: Line 1,344:
#title:Counties of residence for women recorded in CAS Indexes of Archaeological Papers
#title:Counties of residence for women recorded in CAS Indexes of Archaeological Papers


SELECT distinct ?person ?personLabel ?county ?countyLabel ?wikidata ?geo   
SELECT distinct ?person ?personLabel ?residence ?residenceLabel ?county ?countyLabel ?wikidata ?geo   
WHERE {   
WHERE {   
   ?person bnwdt:P3 bnwd:Q3 . # select women
   ?person bnwdt:P3 bnwd:Q3 . # select women
Line 1,253: Line 1,350:
   FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
   FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
   ?person bnwdt:P29 ?residence . # select residences
   ?person bnwdt:P29 ?residence . # select residences
   ?residence bnwdt:P33 ?district . #select districts
 
   ?district bnwdt:P33 ?county . #select counties
   ?residence bnwdt:P33 ?district . #select p33 of residence
       optional { ?county bnwdt:P153 ?geo2 .  } # for geocoords added to BN
   ?district bnwdt:P33 ?next . #select p33 of district, mostly counties but a few region/outside uk
 
  optional {
    # is ?next a uk region?
    ?next bnwdt:P12 bnwd:Q4207 .
    BIND(BOUND(?next) AS ?region).
    }
  optional {
    # is ?next in the UK?
    ?next bnwdt:P33* bnwd:Q1741 .
    BIND(BOUND(?next) AS ?uk).
    }
 
  # if next=q4207 uk region, then use ?district for county, ifelse in uk use ?next, else not in uk use ?district.
  bind(
       if( bound(?region), ?district, # region first (because also uk)
        if( bound(?uk), ?next, # then rest of uk 
      ?district)) # then anything not in uk.
    as ?county).
 
    optional { ?county bnwdt:P153 ?geo2 .  } # for geocoords added to BN
    
    
      optional {     
    optional {     
       ?county bnp:P117 ?ws .  # wikidata id P117         
       ?county bnp:P117 ?ws .  # wikidata id P117         
         ?ws bnpq:P14 ?wikidata_url .
         ?ws bnpq:P14 ?wikidata_url .
Line 2,154: Line 2,271:
</sparql>
</sparql>


==People==
=== Wikidata categories for BN instance of locality in the UK ===
 
 
===Women with their family name at birth and family name after marriage===
<sparql tryit="1">
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/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>
#title: counts of WD instance of (P31) for BN localities (instance of Q2147) in the UK
 
select ?wd_io ?wd_io_label  (count(*) as ?count)
 
where {
  ?item bnwdt:P12 bnwd:Q2147 . # BN io locality
  ?item bnwdt:P33* bnwd:Q1741 . # in UK
 
  ?item bnwdt:P117 ?wd.
      bind(iri(concat("http://www.wikidata.org/entity/", str(?wd))) as ?wikidata) .
      SERVICE <https://query.wikidata.org/sparql> { 
          ?wikidata wdt:P31 ?wd_io.
              ## p31 Q48091 region of england.
            SERVICE wikibase:label { bd:serviceParam wikibase:language "en". 
                                    ?wikidata rdfs:label ?wd_label .
                                    ?wd_io rdfs:label ?wd_io_label .
                                  }       
        }
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
group by ?wd_io ?wd_io_label
order by ?wd_io_label
</sparql>
 
 
=== Localities not in the UK ===
 
<sparql tryit="1">
##admin_paths lists the linked P33 for the item. Unfortunately, they aren't reliably returned in ascending order.
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/>
#title:localities not in the UK
 
select  ?item ?itemLabel (group_concat(distinct ?admin_label; separator=", " ) as ?admin_path)
where {
  ?item bnwdt:P12 bnwd:Q2147 . # i/o locality
  ?item bnwdt:P33* ?admin.   
    ?admin rdfs:label ?admin_label. filter(lang(?admin_label)="en") .
 
  filter not exists { ?item bnwdt:P33* bnwd:Q1741.  } # filter out anything in the UK
  filter (?item not in (bnwd:Q619, bnwd:Q2961, bnwd:Q4207, bnwd:Q86) ). # and a few things that are not specific places
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
group by ?item ?itemLabel
order by ?itemLabel
</sparql>
 
==People==
 
===Women with their family name at birth and family name after marriage===


<sparql tryit="1">
<sparql tryit="1">
Line 3,437: Line 3,620:
   }  
   }  
    
    
   FILTER(LANG(?propertyLabel) = 'en-gb')  
   FILTER(LANG(?propertyLabel) = 'en')  
   # fix label language dups; but Q why doesn't SERVICE work?  
   # fix label language dups; but Q why doesn't SERVICE work?  
   # A: https://en.wikibooks.org/wiki/SPARQL/FILTER#FILTER_on_values_in_Labels
   # A: https://en.wikibooks.org/wiki/SPARQL/FILTER#FILTER_on_values_in_Labels
  # nb a few objects found with en-gb label missing


}
}
Line 3,447: Line 3,629:


</sparql>
</sparql>


=== All the Things for Organisations ===
=== All the Things for Organisations ===
Line 3,507: Line 3,688:
</sparql>
</sparql>


=== One woman ===
<sparql tryit="1">
#title:All About a Woman
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/>
PREFIX bnpsv: <https://beyond-notability.wikibase.cloud/prop/statement/value/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>
SELECT distinct ?propLabel ?spsLabel ?qual_propLabel ?pqsLabel ?link ?s
# ?main_date ?main_precision ?qual_date ?qual_precision   
# ?prop ?sps ?pqs ?pq
WHERE
{
  VALUES (?person) {(bnwd:Q569)}  # add (bnwd:Qxxx) if you want more than one person. 
  ?person ?p ?s . 
    ?prop wikibase:claim ?p;   
        wikibase:statementProperty ?ps;  #  simple value
        wikibase:statementValue ?psv. #  full value   
 
  # exclude external IDs
  # filter not exists { ?prop wikibase:propertyType wikibase:ExternalId . }
 
      ?s ?ps ?sps.
 
    # full date via ?psv
      OPTIONAL {
          ?s ?psv ?spsv .
              ?spsv wikibase:timeValue ?main_date .
              ?spsv wikibase:timePrecision ?main_precision .
      }
    # qualifiers.
 
      optional {
        ?s ?pq ?pqs .         
          ?qual_prop wikibase:qualifier ?pq . 
          ?qual_prop wikibase:qualifierValue ?pqp .
       
          optional {
            # full date via ?pqp
            ?s ?pqp ?qv .
            ?qv wikibase:timeValue ?qual_date.
            ?qv wikibase:timePrecision ?qual_precision.
          }
    }
 
  # direct link to property
        BIND (REPLACE(STR(?prop), "^.*/([^/]*)$", "$1") as ?pid).
        bind(iri(concat(str(?person), "#", ?pid)) as ?link ) .
 
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
       
}
order by ?propLabel ?s
</sparql>


===Working with property paths: organisations and locations===
===Working with property paths: organisations and locations===
Line 3,535: Line 3,782:
ORDER BY ?item ?distance
ORDER BY ?item ?distance
</sparql>
</sparql>
=== Traversing instance of with GAS ===
<sparql tryit="1">
#title:GAS
# The Gather, Apply, and Scatter (GAS) service provides graph traversal, graph mining, and similar classes of algorithms for SPARQL.
# In practical terms, it enables a series of relations to be followed through the graph; for instance the chain of father, grandfather, great-grandfather &c - tracing the father (P22) line - of a subject item
# https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/query_optimization#GAS_Service
# https://github.com/blazegraph/database/wiki/RDF_GAS_API
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 ?depth  ?ioLabel ?itemLabel ?io ?item
WHERE {
      SERVICE gas:service {
          gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.BFS" ;
                      gas:in bnwd:Q3099 ;
                      gas:linkType bnwdt:P12 ;
                      gas:traversalDirection "Reverse";
                      gas:out ?item ;
                      gas:out1 ?depth ;
                      gas:out2 ?io .
      }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
order by ?depth ?ioLabel ?itemLabel
</sparql>


=== Working with property paths: instance of [CAVEAT: experimental, probably wrong]===
=== Working with property paths: instance of [CAVEAT: experimental, probably wrong]===
Line 3,784: Line 4,065:
   UNION
   UNION
    
    
   { # qualifier dates
   { # FIXME? qualifier dates. hmm... how is this different from above? I think something is missing.
      
      
     ?person bnwdt:P3 bnwd:Q3 .   
     ?person bnwdt:P3 bnwd:Q3 .   
Line 3,977: Line 4,258:


order by ?person ?date_value
order by ?person ?date_value
</sparql>
=== Women who were adults in 1911 ===
<sparql tryit="1">
#title:Women who were adults in 1911 and their calculated ages
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 ?person ?personLabel ?statements ?dob ?dod ?age1911
WHERE {
  ?person bnwdt:P3 bnwd:Q3 ;
        wikibase:statements ?statements .
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .}
  ?person bnwdt:P26 ?dob . 
  #optional {
      ?person bnwdt:P15 ?dod . 
  #}
 
  filter(year(?dod) > 1911 && year(?dob) <=1893 ) .
  #if dod is made optional a more complex filter to include some women who were likely to still be alive in 1911. but doesnt add very many.
  #filter( ( year(?dob) <= 1893  && year(?dod) > 1911 ) || ( year(?dob) <= 1893 && year(?dob) >1870 ) ) .
 
  #Date literals can be written by adding ^^xsd:dateTime to an ISO 8601 date string: "2012-10-29"^^xsd:dateTime
 
  bind(year("1911-07-01"^^xsd:dateTime) - year(?dob) as ?age1911 ).
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?personLabel
</sparql>
</sparql>
664

edits