Project:SPARQL/examples

From Beyond Notability
Revision as of 15:21, 1 October 2021 by Jwbaker (talk | contribs) (add graph)

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". } 
}

Try it!


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". }
}

Try it!


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". } 
}

Try it!


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!

Try it!


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!

Try it!