Project:SPARQL/examples: Difference between revisions
From Beyond Notability
(add wikidata recall query) |
|||
Line 159: | Line 159: | ||
===Spouses, fathers, and mothers of women in | ===Spouses, fathers, and mothers of women in our data according to wikidata=== | ||
<sparql tryit="1"> | <sparql tryit="1"> |
Revision as of 09:01, 30 October 2021
Examples
Women in the wiki, excluding the project team
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/>
SELECT ?person ?personLabel
WHERE {
?person bnwdt:P3 bnwd:Q3 .
FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
Women about whom we have recorded fewer than 3 pieces of information
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/>
SELECT ?person ?personLabel ?statements WHERE {
?person bnwdt:P3 bnwd:Q3 ;
wikibase:statements ?statements .
FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .}
FILTER (?statements <3)
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb".
}
}
People for whom their item records is given as 'Mrs'
SELECT ?id ?name
WHERE {
?id rdfs:label ?name .
FILTER regex(?name, "mrs *", "i") #this line uses regular expression syntax, described at https://regexper.com/#mrs%5Cs*
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
All triples in the wiki, limited to 1000
SELECT ?a ?aLabel ?b ?c WHERE {
?a ?b ?c
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
LIMIT 1000 #please don't make this number too big as it will slow down the site!
All triples in the wiki, represented as a crude graph
#defaultView:Graph
SELECT ?a ?aLabel ?c ?cLabel WHERE {
?a ?b ?c
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
#note query returns every connection in the wikibase so it may fall over!
People whose elections were proposed to SAL linked in a graph to those who signed their nomination for election
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/>
#defaultView:Graph
SELECT ?person ?personLabel ?SALsignatory ?SALsignatoryLabel WHERE {
?person bnp:P16 ?SALstatement .
?SALstatement bnps:P16 ?SALproposed .
?SALstatement bnpq:P32 ?SALsignatory .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb".
}
}
# I don't know how to use 'edgeLabel' to show the types of interaction, but if you have an idea suggest an edit!
People whose elections were proposed to SAL or RAI, including who proposed, seconded, or signed their proposal for election (seperated by type) and the date the proposals were made
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/>
SELECT ?person ?personLabel ?SALproposedLabel ?SALsignatoryLabel ?RAIproposedLabel ?RAIsecondedLabel ?date WHERE
{
{
?person bnwdt:P3 bnwd:Q3 .
?person bnp:P16 ?SALstatement .
?SALstatement bnps:P16 ?SALproposed .
?SALstatement bnpq:P32 ?SALsignatory .
?SALstatement bnpq:P1 ?date .
}
UNION
{
?person bnwdt:P3 bnwd:Q3 .
?person bnp:P7 ?RAIstatement .
?RAIstatement bnps:P7 ?RAIproposed .
OPTIONAL {?RAIstatement bnpq:P8 ?RAIseconded .}
?RAIstatement bnpq:P1 ?date .
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb".
}
}
ORDER BY ?date
# I only got how to do this when I read https://wdqs-tutorial.toolforge.org/index.php/category/simple-queries/qualifiers/ Huge thanks to @Tagishsimon for pointing out my error and forcing me to do it properly :)
People whose residence was at one time in the east or south east of England, excluding London
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/>
SELECT ?resident ?residentLabel ?residenceLabel ?districtLabel ?countyLabel ?regionLabel
WHERE {
?resident bnwdt:P29 ?residence .
?residence bnwdt:P33 ?district .
?district bnwdt:P33 ?county .
?county bnwdt:P33 ?region .
{?county bnwdt:P33 bnwd:Q67 .}
UNION
{?county bnwdt:P33 bnwd:Q85 .}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
Spouses, fathers, and mothers of women in our data according to wikidata
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!