Project:SPARQL/examples: Difference between revisions

add ppa count
(add ppa count)
Line 232: Line 232:
</sparql>
</sparql>


==IDs==
==People==


===Women in the wiki (excluding the project team) and their corresponding IDs - where they exist - on wikidata, viaf, WorldCat Identities, and the Archaeology Data Service===
===Where women in our data are in wikidata, their spouses, fathers, and mothers according to wikidata===


<sparql tryit="1">
<sparql tryit="1">
Line 247: Line 247:
PREFIX wd:  <http://www.wikidata.org/entity/>
PREFIX wd:  <http://www.wikidata.org/entity/>


SELECT ?person ?personLabel ?wikidata_ID ?viaf_ID ?ads_ID ?worldcat_ID
SELECT ?person ?personLabel ?item ?WD_spouse ?WD_father ?WD_mother
WHERE {   
WHERE {   
   ?person bnwdt:P3 bnwd:Q3 .                                 #select women
   ?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
    OPTIONAL {?person bnwdt:P117 ?wikidata_ID .}            #return wikidata ID
  ?person bnp:P117 ?wikidata_ID . #look for wikidata ID on person page
    OPTIONAL {?person bnwdt:P119 ?viaf_ID .}                 #return VIAF ID
  ?wikidata_ID bnpq:P14 ?wikidata_url .
    OPTIONAL {?person bnwdt:P34 ?ads_ID .}                   #return Archaeological Data Service ID
  BIND(IRI(REPLACE(?wikidata_url,"https://www.wikidata.org/wiki/","http://www.wikidata.org/entity/")) as ?item )
    OPTIONAL {?person bnwdt:P118 ?worldcat_ID .}             #return WorldCat Identities ID
 
  SERVICE <https://query.wikidata.org/sparql> {
        ?item wdt:P21 ?WD_gender. #get gender of person
        OPTIONAL {?item wdt:P22 ?WD_father . } #recall father
        OPTIONAL {?item wdt:P25 ?WD_mother . } #recall mother
        OPTIONAL {?item wdt:P26 ?WD_spouse . } #recall spouse
      }
 
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
}
}
ORDER BY ?personLabel
ORDER BY ?personLabel
# with thanks to @tagishsimon for writing this one initially!
</sparql>
</sparql>


===Where women in our data are in wikidata, their spouses, fathers, and mothers according to wikidata===
===Women in our data alongside counts of their public and professional activities===
 
<sparql tryit="1">
## Women in our data alongside counts of their public and professional activities (https://beyond-notability.wikibase.cloud/wiki/Item:Q151)
 
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 ?person ?personLabel
(count(distinct ?exhibitor) as ?exhibitions)
(count(distinct ?position) as ?positions)
(count(distinct ?speaker) as ?spoke)
(count(distinct ?attended) as ?attendance)
(count(distinct ?donorof) as ?donated)
(count(distinct ?wasdelegate) as ?delegate)
(count(distinct ?correspondent) as ?correspondents)
(count(distinct ?fellow) as ?fellowships)
(count(distinct ?collab) as ?collaborations)
(count(distinct ?found) as ?founded)
(count(distinct ?loaned) as ?loans)
(count(distinct ?illustrated) as ?illustrations)
(count(distinct ?sold) as ?sales)
(count(distinct ?served) as ?service)
(count(distinct ?job) as ?employed)
(count(distinct ?fundraiser) as ?fundraisers)
(count(distinct ?publish) as ?published)
(count(distinct ?benefact) as ?benefactor)
(count(distinct ?donor) as ?donor_to)
(count(distinct ?collect) as ?collected)
(count(distinct ?performance) as ?performances)
 
where
{
  ?person bnwdt:P3 bnwd:Q3 .
  optional { ?person bnp:P13 ?exhibitor }
  optional { ?person bnp:P17 ?position }
  optional { ?person bnp:P23 ?speaker }
  optional { ?person bnp:P24 ?attended }
  optional { ?person bnp:P65 ?donorof }
  optional { ?person bnp:P71 ?wasdelegate }
  optional { ?person bnp:P73 ?correspondent }
  optional { ?person bnp:P75 ?fellow }
  optional { ?person bnp:P83 ?collab }
  optional { ?person bnp:P85 ?found }
  optional { ?person bnp:P87 ?loaned }
  optional { ?person bnp:P89 ?illustrated }
  optional { ?person bnp:P99 ?sold }
  optional { ?person bnp:P102 ?served }
  optional { ?person bnp:P105 ?job }
  optional { ?person bnp:P106 ?fundraiser }
  optional { ?person bnp:P107 ?publish }
  optional { ?person bnp:P110 ?benefact }
  optional { ?person bnp:P111 ?donor }
  optional { ?person bnp:P114 ?collect }
  optional { ?person bnp:P120 ?performance }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }
}
group by ?person ?personLabel
ORDER BY ?personLabel
</sparql>
 
==IDs==
 
===Women in the wiki (excluding the project team) and their corresponding IDs - where they exist - on wikidata, viaf, WorldCat Identities, and the Archaeology Data Service===


<sparql tryit="1">
<sparql tryit="1">
Line 273: Line 349:
PREFIX wd:  <http://www.wikidata.org/entity/>
PREFIX wd:  <http://www.wikidata.org/entity/>


SELECT ?person ?personLabel ?item ?WD_spouse ?WD_father ?WD_mother
SELECT ?person ?personLabel ?wikidata_ID ?viaf_ID ?ads_ID ?worldcat_ID
WHERE {   
WHERE {   
   ?person bnwdt:P3 bnwd:Q3 . #select women
   ?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
  ?person bnp:P117 ?wikidata_ID . #look for wikidata ID on person page
    OPTIONAL {?person bnwdt:P117 ?wikidata_ID .}            #return wikidata ID
  ?wikidata_ID bnpq:P14 ?wikidata_url .
    OPTIONAL {?person bnwdt:P119 ?viaf_ID .}                 #return VIAF ID
  BIND(IRI(REPLACE(?wikidata_url,"https://www.wikidata.org/wiki/","http://www.wikidata.org/entity/")) as ?item )
    OPTIONAL {?person bnwdt:P34 ?ads_ID .}                   #return Archaeological Data Service ID
 
    OPTIONAL {?person bnwdt:P118 ?worldcat_ID .}             #return WorldCat Identities ID
  SERVICE <https://query.wikidata.org/sparql> {
        ?item wdt:P21 ?WD_gender. #get gender of person
        OPTIONAL {?item wdt:P22 ?WD_father . } #recall father
        OPTIONAL {?item wdt:P25 ?WD_mother . } #recall mother
        OPTIONAL {?item wdt:P26 ?WD_spouse . } #recall spouse
      }
 
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
}
}
ORDER BY ?personLabel
ORDER BY ?personLabel
# with thanks to @tagishsimon for writing this one initially!
</sparql>
</sparql>