Project:SPARQL/examples: Difference between revisions
From Beyond Notability
(add some logic) |
|||
Line 81: | Line 81: | ||
<sparql tryit="1"> | <sparql tryit="1"> | ||
PREFIX | PREFIX bn: <http://beyond-notability.wiki.opencura.com/entity/> | ||
PREFIX | PREFIX bnwdt: <http://beyond-notability.wiki.opencura.com/prop/direct/> | ||
PREFIX | PREFIX bnps: <http://beyond-notability.wiki.opencura.com/prop/statement/> | ||
PREFIX | PREFIX bnpq: <http://beyond-notability.wiki.opencura.com/prop/qualifier/> | ||
Line 90: | Line 90: | ||
{ | { | ||
?person ?y ?z . | ?person ?y ?z . | ||
?person | ?person bnwdt:P3 ?gender . #this line is a crude hack for 'is person' | ||
?z | ?z bnpq:P1 ?date . | ||
{?person | {?person bnwdt:P7 ?RAIproposed .} | ||
UNION | UNION | ||
{?person | {?person bnwdt:P8 ?RAIseconded .} | ||
UNION | UNION | ||
{?person | {?person bnwdt:P16 ?SALproposed .} | ||
SERVICE wikibase:label { | SERVICE wikibase:label { | ||
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". | bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". | ||
Line 102: | Line 102: | ||
} | } | ||
ORDER BY ?person | ORDER BY ?person | ||
# per https://twitter.com/Tagishsimon/status/1445127301306490891, I (James) and aawre that this is a hack of the datamodel that isn't using the datamodel to full effect. | |||
</sparql> | </sparql> |
Revision as of 06:58, 5 October 2021
Examples
People in the wiki, excluding the project team
PREFIX a: <http://beyond-notability.wiki.opencura.com/entity/>
PREFIX b: <http://beyond-notability.wiki.opencura.com/prop/direct/>
SELECT ?id ?name
WHERE {
?id rdfs:label ?name .
?id b:P3 ?idGender . #this line assumes that items for people have a gender value
FILTER NOT EXISTS {?id b:P4 a: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 whose name in the records begin with '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 elected to SAL or RAI linked in a graph to those who proposed their election
PREFIX a: <http://beyond-notability.wiki.opencura.com/entity/>
PREFIX b: <http://beyond-notability.wiki.opencura.com/prop/direct/>
#defaultView:Graph
SELECT ?person ?personLabel ?elector ?electorLabel WHERE {
?person b:P7|b:P8|b:P16 ?elector .
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 elected to SAL or RAI, including who proposed or seconded them (seperated by type) and date proposals made
PREFIX bn: <http://beyond-notability.wiki.opencura.com/entity/>
PREFIX bnwdt: <http://beyond-notability.wiki.opencura.com/prop/direct/>
PREFIX bnps: <http://beyond-notability.wiki.opencura.com/prop/statement/>
PREFIX bnpq: <http://beyond-notability.wiki.opencura.com/prop/qualifier/>
SELECT ?personLabel ?RAIproposedLabel ?RAIsecondedLabel ?SALproposedLabel ?date WHERE
{
?person ?y ?z .
?person bnwdt:P3 ?gender . #this line is a crude hack for 'is person'
?z bnpq:P1 ?date .
{?person bnwdt:P7 ?RAIproposed .}
UNION
{?person bnwdt:P8 ?RAIseconded .}
UNION
{?person bnwdt:P16 ?SALproposed .}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb".
}
}
ORDER BY ?person
# per https://twitter.com/Tagishsimon/status/1445127301306490891, I (James) and aawre that this is a hack of the datamodel that isn't using the datamodel to full effect.