![Page 1: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/1.jpg)
Tech TalkBIBFRAME Working Group
15 March 2016
Notes from the Library Juice Academy courses on
“SPARQL Fundamentals” Allison Jai O’Dell | [email protected]
![Page 2: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/2.jpg)
SPARQLThe SPARQL Protocol and RDF Query Language (SPARQL) is “a semantic query
language for databases, able to retrieve and manipulate data stored in Resource
Description Framework (RDF) format” -- Wikipedia
![Page 3: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/3.jpg)
Turtle Syntax
SPARQL uses the triple pattern and Turtle syntax
Turtle: Terse RDF Triple Language
<http://www.example.com/uri> namespace:element “literal” .
“literal”@en Literal with a language tag
“literal”^^xsd:integer Typed literal
![Page 4: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/4.jpg)
Basic SPARQL Query
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?subject
WHERE
{
<http://www.worldcat.org/oclc/704257552> dct:creator ?subject .
}
PREFIX specifies namespaces
SELECT specifies solutions to return
WHERE specifies triple & graph patterns to query
![Page 5: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/5.jpg)
DISTINCT Modifier
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ?subject
WHERE
{
?title dct:subject ?subject .
}
DISTINCT de-duplicates solutions
![Page 6: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/6.jpg)
More Modifiers
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?title ?subject
WHERE { ?title dct:subject ?subject . }
ORDER BY ?subject
LIMIT 5
OFFSET 10
ORDER BY specifies how to sort solutions.
OFFSET causes the solutions generated to start after the specified number of solutions.
LIMIT puts an upper bound on the number of solutions returned.
![Page 7: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/7.jpg)
Federated Queries
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ?subject
WHERE
{
SERVICE <http://dbpedia.org/snorql>
{
?title dct:subject ?subject .
}
}
SERVICE lets you run federated queries over multiple endpoints
![Page 8: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/8.jpg)
Helpful Operators
• Conjunction / Boolean “and”
A . B
• Disjunction / Boolean “or”
{A} UNION {B}
• Negation
A MINUS {B}
![Page 9: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/9.jpg)
Property Paths
• path1/path2 Sequence path (pipe)
• ^path1 Inverse path (object to subject)
• path1|path2 Alternative path (either path1 or path2)
• path1* path1 repeated zero or more times
• path1+ path1 repeated one or more times
• path1? Zero or one, e.g., path1 is optional
• !(set) Negation
![Page 10: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/10.jpg)
Slightly complicated SPARQL Query
# British Museum http://collection.britishmuseum.org/sparql
PREFIX crm: <http://erlangen-crm.org/current/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX bmo: <http://collection.britishmuseum.org/id/ontology/>
SELECT ?physdesc
{
?henry skos:prefLabel "Henry Spencer Ashbee" .
?henry ^ecrm:P51_has_former_or_current_owner/
bmo:PX_physical_description ?physdesc .
}
![Page 11: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/11.jpg)
Four Query Forms
• SELECT
• CONSTRUCTConstruct new RDF triples & graphs based on patterns and existing data
• ASKAsk whether or not a pattern matches the data; result is true or false
• DESCRIBEDescribe the resources matched by given variables
![Page 12: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/12.jpg)
CONSTRUCT Query
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT
{
dbr:Mindy_Kaling foaf:knows ?who .
?who foaf:knows ?more .
}
WHERE
{
SERVICE <http://dbpedia.org/sparql>
{
dbr:The_Mindy_Project dbo:starring ?who .
?who ^dbo:starring/dbo:starring ?more .
}
}
![Page 13: Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: University of Florida Libraries, Linked Data Working Group, Tech Talk, 15 March 2016](https://reader038.vdocuments.us/reader038/viewer/2022100807/589a1c041a28ab2a678b5c49/html5/thumbnails/13.jpg)
Let’s have a go.http://dbpedia.org/snorql/
http://collection.britishmuseum.org/sparql