Project:SPARQL/admin: Difference between revisions

m
Line 1: Line 1:
==Admin==
== Other queries ==


[[Project:SPARQL/examples|main queries page]]
[[Project:SPARQL/examples|main queries page]]
==Admin==


===Women about whom we have recorded fewer than 3 pieces of information===
===Women about whom we have recorded fewer than 3 pieces of information===
Line 152: Line 154:
</sparql>
</sparql>


=== Compare uses of item v free text ===
 
 
=== Missing language labels ===


<sparql tryit="1">
<sparql tryit="1">
# A number of properties have "item" and "free text" versions; a query to fetches both versions in each case to facilitate comparison of their uses.
 
# query to check for any items/properties which don't have "en" labels. [currently not an issue but retained for reference.]


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 167: Line 172:
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>


SELECT distinct ?itemLabel ?prop_label ?qual_label ?qual_value ?qual_valueLabel ?item ?qual_prop
SELECT  
  ?item  ?itemLabel
  (group_concat(distinct ?language) as ?languages)
  (count(distinct ?rdfs_label) as ?count) # TIL: where you put distinct matters! 


# most of these are used in qualifiers - only P72, P71 and P88 found in main (and only a handful of uses of free text?)
WHERE {
#?item (  bnp:P88|bnp:P91 | bnp:P72|bnp:P71) ?s .


## the pairs
  ?item ?p ?s.
#P21 evidence (free text) / P20 evidence (item)
  ?item rdfs:label ?rdfs_label .  # rdfs item label (1 per language).
#P79 item exhibited / P80 item exhibited (free text)
 
#P78 of / P66 of (free text)
  BIND(LANG(?rdfs_label) as ?language) # get 2 letter language codes
#P91 specific reference information / P88 specific reference information (free text)
#P31 street address (free text) / P100 street address (item)
#P72 was delegate at (free text) / P71 was delegate at (item)


WHERE {
  #optional { ?item rdfs:label ?engb . filter(lang(?engb)="en-gb").  }
  #optional { ?item rdfs:label ?en . filter(lang(?en)="en").  } 
    
    
   ?item ?p ?s .  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en-gb, en". }
}
group by ?item  ?itemLabel
HAVING (?count<2)
order by ?item
 
</sparql>
 
 
=== Places of residence that lack instance of locality===
 
<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 ?residence ?residenceLabel ?inst ?instLabel
WHERE { 
  ?resident bnwdt:P29 ?residence . # resided at
  filter not exists { ?residence bnwdt:P12 bnwd:Q2147 . } # that doesn't have instance of locality
 
  optional {?residence bnwdt:P12 ?inst .} # does it have instance of anything? 
      ## Note: some have Q618 territory of the British Empire, which also lacks any instance of at present
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?residenceLabel
</sparql>
 
 
=== Archaeological sites that don't have National Heritage England list numbers ===
 
<sparql tryit="1">
#title:archaeological sites without National Heritage numbers
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 ?item ?itemLabel ?location ?locationLabel
(if(bound(?locEngland), "yes", "") as ?inEngland)
 
WHERE { 
  ?item bnwdt:P12 bnwd:Q86 . # item instance of archaeological site
    
    
   ?prop wikibase:claim ?p;     
   filter not exists {?item bnwdt:P129 ?thing } # without NH list number
        rdfs:label ?prop_label. filter(lang(?prop_label)="en-gb") . 
   
  ?s ( bnpq:P21|bnpq:P20 | bnpq:P80|bnpq:P79 | bnpq:P66|bnpq:P78 | bnpq:P88|bnpq:P91 | bnpq:P31|bnpq:P100 | bnpq:P72|bnpq:P71 ) ?qual_value .
    
    
   ?s ?qual_p ?qual_value .  
   optional { ?item bnwdt:P2 ?location .  } # location if it has one
    ?qual_prop wikibase:qualifier ?qual_p;
  optional { ?item bnwdt:P2 ?locEngland .
           wikibase:propertyType ?qual_prop_type ;
              ?locEngland bnwdt:P33+ bnwd:Q617.
          rdfs:label ?qual_label. filter(lang(?qual_label)='en-gb') .
           } # is the location in England
    
 
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
 
order by ?itemLabel
 
</sparql>
 
 
 
=== Date of latest edit for every item, according to WQS ===
 
<sparql tryit="1">
#title:latest edits dates for wikibase items
 
## because of WQS disappearing data bugs this may not always match the latest edit in the page history
 
SELECT ?item ?date ?dateLabel
WHERE {
  ?item wikibase:timestamp ?date .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
}
order by ?qual_label ?prop_label ?itemLabel
order by ?date


</sparql>
</sparql>


=== Missing language labels ===
 
 
 
 
=== Questions ===


<sparql tryit="1">
<sparql tryit="1">


# query to check for any items/properties which don't have "en" labels. [currently not an issue but retained for reference.]
#title:asking questions


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 216: Line 291:
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>


SELECT
  ?item  ?itemLabel
  (group_concat(distinct ?language) as ?languages)
  (count(distinct ?rdfs_label) as ?count) # TIL: where you put distinct matters! 


WHERE {
SELECT ?personLabel ?propLabel ?link ?question


   ?item ?p ?s.  
WHERE { 
  ?item rdfs:label ?rdfs_label . # rdfs item label (1 per language).  
  ?person bnwdt:P3 bnwd:Q3 .
 
   ?person ?p ?s .
      ?prop wikibase:claim ?p;     
        wikibase:statementProperty ?ps.    
         
  # direct link to relevant part of page
        BIND (REPLACE(STR(?prop), "^.*/([^/]*)$", "$1") as ?pid).
        bind(iri(concat(str(?person), "#", ?pid)) as ?link ) .  
    
    
   BIND(LANG(?rdfs_label) as ?language) . # get 2 letter language codes
   # the question
    ?s bnpq:P157 ?question .  


  #optional { ?item rdfs:label ?engb . filter(lang(?engb)="en-gb").  }
       
  #optional { ?item rdfs:label ?en . filter(lang(?en)="en").  } 
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
 
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en-gb, en". }  
}
}
group by ?item  ?itemLabel
HAVING (?count<2)
order by ?item


order by ?personLabel
</sparql>
</sparql>
== Dates ==


=== Statements that contain both a date *and* an unknown value date===
=== Statements that contain both a date *and* an unknown value date===
Line 422: Line 501:
}
}
order by ?personLabel
order by ?personLabel
</sparql>
=== Places of residence that lack instance of locality===
<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 ?residence ?residenceLabel ?inst ?instLabel
WHERE { 
  ?resident bnwdt:P29 ?residence . # resided at
  filter not exists { ?residence bnwdt:P12 bnwd:Q2147 . } # that doesn't have instance of locality
  optional {?residence bnwdt:P12 ?inst .} # does it have instance of anything? 
      ## Note: some have Q618 territory of the British Empire, which also lacks any instance of at present
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
ORDER BY ?residenceLabel
</sparql>
=== Archaeological sites that don't have National Heritage England list numbers ===
<sparql tryit="1">
#title:archaeological sites without National Heritage numbers
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 ?item ?itemLabel ?location ?locationLabel
(if(bound(?locEngland), "yes", "") as ?inEngland)
WHERE { 
  ?item bnwdt:P12 bnwd:Q86 . # item instance of archaeological site
 
  filter not exists {?item bnwdt:P129 ?thing .  } # without NH list number
 
  optional { ?item bnwdt:P2 ?location .  } # location if it has one
  optional { ?item bnwdt:P2 ?locEngland .
              ?locEngland bnwdt:P33+ bnwd:Q617.
          } # is the location in England
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
order by ?itemLabel
</sparql>
=== Date of latest edit for every item, according to WQS ===
<sparql tryit="1">
#title:latest edits dates for wikibase items
## because of WQS disappearing data bugs this may not always match the latest edit in the page history
SELECT ?item ?date ?dateLabel
WHERE {
  ?item wikibase:timestamp ?date .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
order by ?date


</sparql>
</sparql>
Line 597: Line 603:
order by ?personLabel ?date ?degreeLabel
order by ?personLabel ?date ?degreeLabel
</sparql>
</sparql>
== Item / free text ==
=== Compare uses of item v free text ===
<sparql tryit="1">
# A number of properties have "item" and "free text" versions; a query to fetches both versions in each case to facilitate comparison of their uses.
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 ?itemLabel ?prop_label ?qual_label ?qual_value ?qual_valueLabel ?item ?qual_prop
# most of these are used in qualifiers - only P72, P71 and P88 found in main (and only a handful of uses of free text?)
#?item (  bnp:P88|bnp:P91 | bnp:P72|bnp:P71) ?s .
## the pairs
#P21 evidence (free text) / P20 evidence (item)
#P79 item exhibited / P80 item exhibited (free text)
#P78 of / P66 of (free text)
#P91 specific reference information / P88 specific reference information (free text)
#P31 street address (free text) / P100 street address (item)
#P72 was delegate at (free text) / P71 was delegate at (item)
WHERE {
 
  ?item ?p ?s .
 
  ?prop wikibase:claim ?p;     
        rdfs:label ?prop_label. filter(lang(?prop_label)="en-gb") . 
   
  ?s ( bnpq:P21|bnpq:P20 | bnpq:P80|bnpq:P79 | bnpq:P66|bnpq:P78 | bnpq:P88|bnpq:P91 | bnpq:P31|bnpq:P100 | bnpq:P72|bnpq:P71 ) ?qual_value .
 
  ?s ?qual_p ?qual_value . 
    ?qual_prop wikibase:qualifier ?qual_p;
          wikibase:propertyType ?qual_prop_type ;
          rdfs:label ?qual_label. filter(lang(?qual_label)='en-gb') .
 
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
order by ?qual_label ?prop_label ?itemLabel
</sparql>


=== Position held: item v free text ===
=== Position held: item v free text ===
Line 638: Line 696:
</sparql>
</sparql>


==== Women with position held free text ====
=== Women with position held free text ===


<sparql tryit="1">
<sparql tryit="1">
Line 664: Line 722:
}
}
order by ?personLabel ?positionLabel
order by ?personLabel ?positionLabel
</sparql>
=== Questions ===
<sparql tryit="1">
#title:asking questions
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 ?personLabel ?propLabel ?link ?question
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 .
 
  ?person ?p ?s .
      ?prop wikibase:claim ?p;     
        wikibase:statementProperty ?ps.     
         
  # direct link to relevant part of page
        BIND (REPLACE(STR(?prop), "^.*/([^/]*)$", "$1") as ?pid).
        bind(iri(concat(str(?person), "#", ?pid)) as ?link ) .
 
  # the question
    ?s bnpq:P157 ?question . 
       
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
order by ?personLabel
</sparql>
</sparql>


582

edits