Project:SPARQL/examples: Difference between revisions

add wikidata recall query
(add wikidata recall query)
Line 155: Line 155:
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
}
}
</sparql>
===Spouses, fathers, and mothers of women in the wiki according to wikidata===
<sparql tryit="1">
PREFIX bnwd: <http://beyond-notability.wiki.opencura.com/entity/>
PREFIX bnwds: <http://beyond-notability.wiki.opencura.com/entity/statement/>
PREFIX bnwdv: <http://beyond-notability.wiki.opencura.com/value/>
PREFIX bnwdt: <http://beyond-notability.wiki.opencura.com/prop/direct/>
PREFIX bnp: <http://beyond-notability.wiki.opencura.com/prop/>
PREFIX bnps: <http://beyond-notability.wiki.opencura.com/prop/statement/>
PREFIX bnpq: <http://beyond-notability.wiki.opencura.com/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd:  <http://www.wikidata.org/entity/>
SELECT ?person ?personLabel ?item ?WD_gender ?WD_spouse ?WD_father ?WD_mother
WHERE { 
  ?person bnwdt:P3 bnwd:Q3 . #select women
  FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
  ?person bnwdt:P14 ?url . #look for wikidata URL on person page
  BIND(IRI(REPLACE(?url,"https://www.wikidata.org/wiki/","http://www.wikidata.org/entity/")) as ?item )
 
  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". }
}
# with thanks to @tagishsimon for writing this one!
</sparql>
</sparql>
6,317

edits