notes from the library juice academy courses on “sparql fundamentals”: university of florida...

13

Click here to load reader

Upload: allison-jai-odell

Post on 22-Jan-2018

497 views

Category:

Data & Analytics


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

Let’s have a go.http://dbpedia.org/snorql/

http://collection.britishmuseum.org/sparql