Skip to content

Instantly share code, notes, and snippets.

@ostephens
ostephens / gist:7633423
Created November 24, 2013 22:40
Simplest SPARQL query using single letter variables
SELECT *
WHERE {
?s ?p ?o
}
LIMIT 10
@ostephens
ostephens / gist:7633608
Created November 24, 2013 22:57
SPARQL Query with 2 patterns - finds titles for books where Jane Austen is the dc:creator
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?title
WHERE {
?book dct:creator <http://bnb.data.bl.uk/id/person/AustenJane1775-1817> .
?book dct:title ?title
}
LIMIT 10
@ostephens
ostephens / gist:7633750
Created November 24, 2013 23:13
Find all people that BNB believes to have the same year of birth as Jane Austen (based on her VIAF URI)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX bio: <http://purl.org/vocab/bio/0.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?name
WHERE {
?person owl:sameAs <http://viaf.org/viaf/102333412> .
?person bio:event ?event .
?event rdf:type bio:Birth .
@ostephens
ostephens / gist:7633907
Created November 24, 2013 23:27
SPARQL query to find titles of books authored by person identified by http://viaf.org/viaf/102333412 (Jane Austen)
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT ?title
WHERE {
?person owl:sameAs <http://viaf.org/viaf/102333412> .
?book dct:creator ?person .
?book dct:title ?title
}
LIMIT 10
@ostephens
ostephens / gist:7639241
Created November 25, 2013 10:15
Basic SPARQL Query using a literal I
SELECT *
WHERE {
?subject ?predicate "Austen, Jane"
}
LIMIT 10
@ostephens
ostephens / gist:7639249
Created November 25, 2013 10:16
Basic SPARQL query using a literal II
SELECT *
WHERE {
?subject ?predicate "Austen, Jane, 1775-1817"
}
LIMIT 10
@ostephens
ostephens / gist:c6ef3999e1b6da9634ce
Created May 14, 2014 09:27
SPARQL for books by Jane Austen from RLUK LOD
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?s ?o
WHERE {
?s <http://rdaregistry.info/Elements/u/P60447> ?b .
@ostephens
ostephens / gist:43e7d7a967a147ed4e8f
Last active December 10, 2015 18:28
SPARQL for British Museum Satires with titles and dates
PREFIX crm: <http://erlangen-crm.org/current/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX thes: <http://collection.britishmuseum.org/id/thesauri/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bmo: <http://collection.britishmuseum.org/id/ontology/>
PREFIX thesIdentifier: <http://collection.britishmuseum.org/id/>
SELECT DISTINCT ?id ?title ?name ?desc ?date
{
?object crm:P70i_is_documented_in <http://collection.britishmuseum.org/id/bibliography/294> .
OPTIONAL {
@ostephens
ostephens / gist:d2bd979968e28f62dfca
Created November 20, 2014 16:49
BM Satires with one line per ID
PREFIX crm: <http://erlangen-crm.org/current/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX thes: <http://collection.britishmuseum.org/id/thesauri/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bmo: <http://collection.britishmuseum.org/id/ontology/>
PREFIX thesIdentifier: <http://collection.britishmuseum.org/id/>
SELECT DISTINCT ?id (GROUP_CONCAT(?title; SEPARATOR = "|") as ?titles) (GROUP_CONCAT(?name; SEPARATOR = "|") as ?names) (GROUP_CONCAT(?desc; SEPARATOR = "|") as ?descs) (GROUP_CONCAT(?date; SEPARATOR = "|") as ?dates)
{
?object crm:P70i_is_documented_in <http://collection.britishmuseum.org/id/bibliography/294> .
OPTIONAL {
@ostephens
ostephens / Include date of birth in SPARQL results
Created April 20, 2015 18:05
Include date of birth in SPARQL results when selecting by DoB in query on BNB
PREFIX bio: <http://purl.org/vocab/bio/0.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?author ?name ?dob WHERE {
?event a bio:Birth;
bio:date "1945"^^xsd:gYear;
bio:date ?dob.
?author bio:event ?event;
foaf:name ?name.