Project:SPARQL/examples: Difference between revisions
From Beyond Notability
No edit summary |
|||
Line 82: | Line 82: | ||
</sparql> | </sparql> | ||
===People whose elections were proposed to SAL linked in a graph to those who signed their nomination for election=== | ===People whose elections were proposed to SAL linked in a graph to those who signed their nomination for election based on personal knoweledge=== | ||
<sparql tryit="1"> | <sparql tryit="1"> |
Revision as of 14:58, 14 January 2022
Examples
Women in the wiki (excluding the project team) and their corresponding IDs - where they exist - on wikidata and the Archaeology Data Service
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 ?wikiurl ?ADSid ?ADSurl
WHERE {
?person bnwdt:P3 bnwd:Q3 . #select women
FILTER NOT EXISTS {?person bnwdt:P4 bnwd:Q12 .} #filter out project team
OPTIONAL {?person bnwdt:P14 ?wikiurl . #look for wikidata URL on person page
FILTER regex(?wikiurl, "wikidata", "i")} #filter just in case P14 used to point to non-wikidata service
OPTIONAL {?person bnp:P34 ?ADSstatement . #look for Archaeology Data Service ID on person page
?ADSstatement bnps:P34 ?ADSid . #return ADS id
?ADSstatement bnpq:P14 ?ADSurl .} #return ADS url
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
ORDER BY ?personLabel
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 based on personal knoweledge
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 not in London linked by a county at which they were once resident
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 ?resident ?residentLabel ?county ?countyLabel
WHERE {
?resident bnwdt:P29 ?residence .
FILTER NOT EXISTS {?resident bnwdt:P29 bnwd:Q39 .}
?residence bnwdt:P33 ?district .
?district bnwdt:P33 ?county .
?county bnwdt:P33 ?region .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
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". }
}
Where women in our data are in wikidata, their spouses, fathers, and mothers 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!