Project:SPARQL/examples: Difference between revisions
From Beyond Notability
Line 1: | Line 1: | ||
==Examples== | ==Examples== | ||
=== | ===Women in the wiki, excluding the project team=== | ||
<sparql tryit="1"> | <sparql tryit="1"> | ||
Line 12: | Line 12: | ||
PREFIX bnpq: <http://beyond-notability.wiki.opencura.com/prop/qualifier/> | PREFIX bnpq: <http://beyond-notability.wiki.opencura.com/prop/qualifier/> | ||
SELECT ? | SELECT ?person ?personLabel | ||
WHERE { | WHERE { | ||
? | ?person bnwdt:P3 bnwd:Q3 . | ||
FILTER NOT EXISTS {?id bnwdt:P4 bnwd:Q12 .} | FILTER NOT EXISTS {?id bnwdt:P4 bnwd:Q12 .} | ||
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". } | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". } |
Revision as of 12:29, 28 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 {?id bnwdt:P4 bnwd:Q12 .}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }
}
People whose elections were proposed by men
PREFIX a: <http://beyond-notability.wiki.opencura.com/entity/>
PREFIX b: <http://beyond-notability.wiki.opencura.com/prop/direct/>
SELECT ?personLabel ?persongenderLabel ?electorLabel ?Date
WHERE {
?person b:P7 ?elector ;
b:P3 ?persongender .
?elector b:P3 a:Q10 .
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 ?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 ?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". }
}