SlideShare a Scribd company logo
1 of 17
Download to read offline
Introduction to SPARQL

Introduction to SPARQL
Overview
•
•
•
•
•
•
•
•

What is SPARQL?
ASK and SELECT query forms
UNION and ORDER BY
Subsets of results
FILTER expressions and functions
OPTIONAL
DESCRIBE and CONSTRUCT query forms
Common problems

Introduction to SPARQL

#2
What is SPARQL?
• SPARQL is a query language for RDF data
– http://www.w3.org/TR/rdf-sparql-query/

• It is also a protocol
• It is designed around graph patterns
– Graph patterns use Turtle syntax

• SPARQL 1.0 is query only
– SPARQL 1.1 (covered next, not yet a recommendation) includes
syntax for updates

Introduction to SPARQL

#3
Ask
• Did 'Steve Hillage' make the album 'Fish Rising'?
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
ASK { dbpedia:Steve_Hillage foaf:made ?album .
?album dc:title "Fish Rising" . }

• Namespaces are added with 'PREFIX' directive
• Statement patterns that make up the graph are
between {} brackets

Introduction to SPARQL

#4
Select
• What albums and tracks did 'Steve Hillage' make?
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>

SELECT ?album_name ?track_title
WHERE {
dbpedia:Steve_Hillage foaf:made ?album .
?album dc:title ?album_name.
?album music-ont:track ?track .
?track dc:title ?track_title . }

• All variables in a query can be selected with '*'
– i.e. SELECT * WHERE { … }

Introduction to SPARQL

#5
Union
• 'Steve Hillage' and 'Jimi Hendrix'?
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>

SELECT ?album_name ?track_title
WHERE
{
{
dbpedia:Steve_Hillage foaf:made ?album .
}
UNION
{
dbpedia:Jimi_Hendrix foaf:made ?album .
}
?album dc:title ?album_name.
?album music-ont:track ?track .
?track dc:title ?track_title .
}

Introduction to SPARQL

#6
Order By
• In what order did 'Steve Hillage' release his albums?
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>

SELECT distinct ?album_name ?date
WHERE
{
dbpedia:Steve_Hillage foaf:made ?album .
?album dc:title ?album_name.
?album music-ont:track ?track .
?album dc:date ?date.
} ORDER BY( ?date)

Introduction to SPARQL

#7
Subsets of results
• What albums and tracks did 'Steve Hillage' make?
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>

SELECT ?album_name ?track_title
WHERE {
dbpedia:Steve_Hillage foaf:made ?album .
?album dc:title ?album_name.
?album music-ont:track ?track .
?track dc:title ?track_title . }
OFFSET 10
LIMIT 15

• Start after the 10th solution, provide (up to) 15 more
Introduction to SPARQL

#8
Filtering solutions
• What are 'Steve Hillage' longer tracks?
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>

SELECT ?album_name ?track_title ?duration
WHERE {
dbpedia:Steve_Hillage foaf:made ?album .
?album dc:title ?album_name.
?album music-ont:track ?track .
?track dc:title ?track_title .
?track music-ont:duration ?duration .
FILTER( ?duration > 500000 ).
}

• Allow only those solutions where the track length is
more than 500 seconds
Introduction to SPARQL

#9
Functions
• What albums and tracks did 'Steve Hillage' make?
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>

SELECT ?album_name ?track_title
WHERE {
dbpedia:Steve_Hillage foaf:made ?album .
?album dc:title ?album_name.
?album music-ont:track ?track .
?track dc:title ?track_title .
FILTER( REGEX( ?track_title, "hurd.*", "i") ) }

• Allow only those solutions where the track title
contains a substring that begins with 'hurd' in any case
Introduction to SPARQL

#10
Filter expressions
• Can be combined with logical, arithmetic, casts and
comparisons, e.g.
FILTER( ?age < 30 && xsd:double(?weight) < (?empty + ?fuel) )

• Also tests, accessors, e.g.
FILTER( isURI( ?id ) && datatype( ?age ) = xsd:double )

Introduction to SPARQL

#11
Optionals
• Parts of the matching graph can be optional
• Use OPTIONAL {} to enclose the optional parts
• Can test in filter expressions if variable are bound
• Using logical NOT '!' it is possible to filter out
solutions for the optional part

Introduction to SPARQL

#12
Optionals
• Albums from artists who are not dead
PREFIX
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>
dbp-ont: <http://dbpedia.org/ontology/>

SELECT distinct ?artist_name ?album_name ?place_of_death
WHERE {
?artist foaf:made ?album .
?artist foaf:name ?artist_name .
?album dc:title ?album_name.
?album music-ont:track ?track .
?track dc:title ?track_title .
OPTIONAL { ?artist dbp-ont:deathPlace ?place_of_death }
FILTER( ! BOUND( ?place_of_death ) ).
}
Introduction to SPARQL

#13
Describe
• Returns RDF statements about any resource
identified by the query
PREFIX dbpedia: <http://dbpedia.org/resource/>
DESCRIBE dbpedia:Steve_Hillage

PREFIX foaf:
<http://xmlns.com/foaf/0.1/>
DESCRIBE ?x ?y <http://example.org/>
WHERE
{?x foaf:knows ?y}

Introduction to SPARQL

#14
Construct
• Returns RDF statements created from variable
bindings
PREFIX
PREFIX
PREFIX
PREFIX

dc: <http://purl.org/dc/elements/1.1/>
foaf: <http://xmlns.com/foaf/0.1/>
dbpedia: <http://dbpedia.org/resource/>
music-ont: <http://purl.org/ontology/mo/>

CONSTRUCT { ?album dc:creator dbpedia:Steve_Hillage }
WHERE {
dbpedia:Steve_Hillage foaf:made ?album .
?album dc:title ?album_name.
?album music-ont:track ?track . }

Introduction to SPARQL

#15
Common Problems
• Spelling mistakes in identifiers are not noticed
– It is simply a different URI
– URIs are LONG, are case-sensitive, have '#' or '/' for local part

• Easy to use the right local name with the wrong
namespace
• Literals are compared on type, language and value
– "Steve Hillage"@EN is not the same as "Steve Hillage"
– "3" is not the same as "3"^^xsd:integer

Introduction to SPARQL

#16
Summary
• SPARQL is a powerful query language for RDF
• SPARQL 1.0 is read-only
• SPARQL 1.1 will allow updates

Introduction to SPARQL

#17

More Related Content

What's hot

AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...
AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...
AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...Amazon Web Services
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshellFabien Gandon
 
Drupal case study: ABC Dig Music
Drupal case study: ABC Dig MusicDrupal case study: ABC Dig Music
Drupal case study: ABC Dig MusicDavid Peterson
 
떠먹는 '오브젝트' Ch02 객체지향 프로그래밍
떠먹는 '오브젝트' Ch02 객체지향 프로그래밍떠먹는 '오브젝트' Ch02 객체지향 프로그래밍
떠먹는 '오브젝트' Ch02 객체지향 프로그래밍Covenant Ko
 
Backup recovery with PostgreSQL
Backup recovery with PostgreSQLBackup recovery with PostgreSQL
Backup recovery with PostgreSQLFederico Campoli
 

What's hot (7)

AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...
AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...
AWS Webcast - Data Modeling and Best Practices for Scaling your Application w...
 
Graph Modelling
Graph ModellingGraph Modelling
Graph Modelling
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
 
Primary analysis tutorial depracated
Primary analysis tutorial depracatedPrimary analysis tutorial depracated
Primary analysis tutorial depracated
 
Drupal case study: ABC Dig Music
Drupal case study: ABC Dig MusicDrupal case study: ABC Dig Music
Drupal case study: ABC Dig Music
 
떠먹는 '오브젝트' Ch02 객체지향 프로그래밍
떠먹는 '오브젝트' Ch02 객체지향 프로그래밍떠먹는 '오브젝트' Ch02 객체지향 프로그래밍
떠먹는 '오브젝트' Ch02 객체지향 프로그래밍
 
Backup recovery with PostgreSQL
Backup recovery with PostgreSQLBackup recovery with PostgreSQL
Backup recovery with PostgreSQL
 

Viewers also liked

ESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data Tutorial
ESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data TutorialESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data Tutorial
ESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data Tutorialeswcsummerschool
 
ESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked data
ESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked dataESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked data
ESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked dataeswcsummerschool
 
Programming with LOD
Programming with LODProgramming with LOD
Programming with LODFumihiro Kato
 
Semantics, Sensors, and the Social Web
Semantics, Sensors, and the Social WebSemantics, Sensors, and the Social Web
Semantics, Sensors, and the Social WebThe Open University
 
DAA Keynote- 99 Amazing Big Data Experiences
DAA Keynote- 99 Amazing Big Data ExperiencesDAA Keynote- 99 Amazing Big Data Experiences
DAA Keynote- 99 Amazing Big Data ExperiencesOxford Tech + UX
 
Mapping Lo Dto Proton Revised [Compatibility Mode]
Mapping Lo Dto Proton Revised [Compatibility Mode]Mapping Lo Dto Proton Revised [Compatibility Mode]
Mapping Lo Dto Proton Revised [Compatibility Mode]Mariana Damova, Ph.D
 

Viewers also liked (7)

ESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data Tutorial
ESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data TutorialESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data Tutorial
ESWC SS 2012 - Friday Keynote Marko Grobelnik: Big Data Tutorial
 
ESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked data
ESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked dataESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked data
ESWC SS 2013 - Thursday Keynote Vassilis Christophides: Preserving linked data
 
Programming with LOD
Programming with LODProgramming with LOD
Programming with LOD
 
Semantics, Sensors, and the Social Web
Semantics, Sensors, and the Social WebSemantics, Sensors, and the Social Web
Semantics, Sensors, and the Social Web
 
IndustryInform Service of Mozaika
IndustryInform Service of MozaikaIndustryInform Service of Mozaika
IndustryInform Service of Mozaika
 
DAA Keynote- 99 Amazing Big Data Experiences
DAA Keynote- 99 Amazing Big Data ExperiencesDAA Keynote- 99 Amazing Big Data Experiences
DAA Keynote- 99 Amazing Big Data Experiences
 
Mapping Lo Dto Proton Revised [Compatibility Mode]
Mapping Lo Dto Proton Revised [Compatibility Mode]Mapping Lo Dto Proton Revised [Compatibility Mode]
Mapping Lo Dto Proton Revised [Compatibility Mode]
 

Similar to ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL

Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02eswcsummerschool
 
Querying Linked Data on Android
Querying Linked Data on AndroidQuerying Linked Data on Android
Querying Linked Data on AndroidEUCLID project
 
SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)andyseaborne
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLMyungjin Lee
 
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query LanguageESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Languageeswcsummerschool
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Storesandyseaborne
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLEmanuele Della Valle
 
Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...
Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...
Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...ALATechSource
 
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...Allison Jai O'Dell
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQLPedro Szekely
 
Mon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked dataMon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked dataeswcsummerschool
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialAdonisDamian
 
Intro to Linked, Dutch Ships and Sailors and SPARQL handson
Intro to Linked, Dutch Ships and Sailors and SPARQL handson Intro to Linked, Dutch Ships and Sailors and SPARQL handson
Intro to Linked, Dutch Ships and Sailors and SPARQL handson Victor de Boer
 

Similar to ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL (20)

Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02Mon norton tut_queryinglinkeddata02
Mon norton tut_queryinglinkeddata02
 
Querying Linked Data
Querying Linked DataQuerying Linked Data
Querying Linked Data
 
Querying Linked Data on Android
Querying Linked Data on AndroidQuerying Linked Data on Android
Querying Linked Data on Android
 
SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query LanguageESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language
ESWC SS 2012 - Monday Tutorial 2 Barry Norton: SPARQL 1.1 Query Language
 
Introduction to Bio SPARQL
Introduction to Bio SPARQL Introduction to Bio SPARQL
Introduction to Bio SPARQL
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
 
Sparql
SparqlSparql
Sparql
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...
Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...
Snyder Kishimoto: RDA for Music: Popular Music, Jazz, and World Music Audio R...
 
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Mon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked dataMon fundulaki tut_querying linked data
Mon fundulaki tut_querying linked data
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
 
Semantic Web
Semantic WebSemantic Web
Semantic Web
 
Semantic Web
Semantic WebSemantic Web
Semantic Web
 
Intro to Linked, Dutch Ships and Sailors and SPARQL handson
Intro to Linked, Dutch Ships and Sailors and SPARQL handson Intro to Linked, Dutch Ships and Sailors and SPARQL handson
Intro to Linked, Dutch Ships and Sailors and SPARQL handson
 

More from eswcsummerschool

Semantic Aquarium - ESWC SSchool 14 - Student project
Semantic Aquarium - ESWC SSchool 14 - Student projectSemantic Aquarium - ESWC SSchool 14 - Student project
Semantic Aquarium - ESWC SSchool 14 - Student projecteswcsummerschool
 
Syrtaki - ESWC SSchool 14 - Student project
Syrtaki  - ESWC SSchool 14 - Student projectSyrtaki  - ESWC SSchool 14 - Student project
Syrtaki - ESWC SSchool 14 - Student projecteswcsummerschool
 
Keep fit (a bit) - ESWC SSchool 14 - Student project
Keep fit (a bit)  - ESWC SSchool 14 - Student projectKeep fit (a bit)  - ESWC SSchool 14 - Student project
Keep fit (a bit) - ESWC SSchool 14 - Student projecteswcsummerschool
 
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student project
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student projectArabic Sentiment Lexicon - ESWC SSchool 14 - Student project
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student projecteswcsummerschool
 
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student projectFIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student projecteswcsummerschool
 
Personal Tours at the British Museum - ESWC SSchool 14 - Student project
Personal Tours at the British Museum  - ESWC SSchool 14 - Student projectPersonal Tours at the British Museum  - ESWC SSchool 14 - Student project
Personal Tours at the British Museum - ESWC SSchool 14 - Student projecteswcsummerschool
 
Exhibition recommendation using British Museum data and Event Registry - ESWC...
Exhibition recommendation using British Museum data and Event Registry - ESWC...Exhibition recommendation using British Museum data and Event Registry - ESWC...
Exhibition recommendation using British Museum data and Event Registry - ESWC...eswcsummerschool
 
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...eswcsummerschool
 
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014 Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014 eswcsummerschool
 
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014eswcsummerschool
 
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014 Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014 eswcsummerschool
 
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...eswcsummerschool
 
Mon norton tut_publishing01
Mon norton tut_publishing01Mon norton tut_publishing01
Mon norton tut_publishing01eswcsummerschool
 
Mon domingue introduction to the school
Mon domingue introduction to the schoolMon domingue introduction to the school
Mon domingue introduction to the schooleswcsummerschool
 
Mon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage dataMon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage dataeswcsummerschool
 
Tue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddataTue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddataeswcsummerschool
 
Thu bernstein key_warp_speed
Thu bernstein key_warp_speedThu bernstein key_warp_speed
Thu bernstein key_warp_speedeswcsummerschool
 
Fri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineeringFri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineeringeswcsummerschool
 
Mon domingue key_introduction to semantic
Mon domingue key_introduction to semanticMon domingue key_introduction to semantic
Mon domingue key_introduction to semanticeswcsummerschool
 
Tue acosta tut_providing_linkeddata
Tue acosta tut_providing_linkeddataTue acosta tut_providing_linkeddata
Tue acosta tut_providing_linkeddataeswcsummerschool
 

More from eswcsummerschool (20)

Semantic Aquarium - ESWC SSchool 14 - Student project
Semantic Aquarium - ESWC SSchool 14 - Student projectSemantic Aquarium - ESWC SSchool 14 - Student project
Semantic Aquarium - ESWC SSchool 14 - Student project
 
Syrtaki - ESWC SSchool 14 - Student project
Syrtaki  - ESWC SSchool 14 - Student projectSyrtaki  - ESWC SSchool 14 - Student project
Syrtaki - ESWC SSchool 14 - Student project
 
Keep fit (a bit) - ESWC SSchool 14 - Student project
Keep fit (a bit)  - ESWC SSchool 14 - Student projectKeep fit (a bit)  - ESWC SSchool 14 - Student project
Keep fit (a bit) - ESWC SSchool 14 - Student project
 
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student project
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student projectArabic Sentiment Lexicon - ESWC SSchool 14 - Student project
Arabic Sentiment Lexicon - ESWC SSchool 14 - Student project
 
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student projectFIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
FIT-8BIT An activity music assistant - ESWC SSchool 14 - Student project
 
Personal Tours at the British Museum - ESWC SSchool 14 - Student project
Personal Tours at the British Museum  - ESWC SSchool 14 - Student projectPersonal Tours at the British Museum  - ESWC SSchool 14 - Student project
Personal Tours at the British Museum - ESWC SSchool 14 - Student project
 
Exhibition recommendation using British Museum data and Event Registry - ESWC...
Exhibition recommendation using British Museum data and Event Registry - ESWC...Exhibition recommendation using British Museum data and Event Registry - ESWC...
Exhibition recommendation using British Museum data and Event Registry - ESWC...
 
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
Empowering fishing business using Linked Data - ESWC SSchool 14 - Student pro...
 
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014 Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
Tutorial: Social Semantic Web and Crowdsourcing - E. Simperl - ESWC SS 2014
 
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
Keynote: Global Media Monitoring - M. Grobelnik - ESWC SS 2014
 
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014 Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
Hands On: Amazon Mechanical Turk - M. Acosta - ESWC SS 2014
 
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
Tutorial: Querying a Marine Data Warehouse Using SPARQL - I. Fundulaki - ESWC...
 
Mon norton tut_publishing01
Mon norton tut_publishing01Mon norton tut_publishing01
Mon norton tut_publishing01
 
Mon domingue introduction to the school
Mon domingue introduction to the schoolMon domingue introduction to the school
Mon domingue introduction to the school
 
Mon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage dataMon norton tut_querying cultural heritage data
Mon norton tut_querying cultural heritage data
 
Tue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddataTue acosta hands_on_providinglinkeddata
Tue acosta hands_on_providinglinkeddata
 
Thu bernstein key_warp_speed
Thu bernstein key_warp_speedThu bernstein key_warp_speed
Thu bernstein key_warp_speed
 
Fri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineeringFri schreiber key_knowledge engineering
Fri schreiber key_knowledge engineering
 
Mon domingue key_introduction to semantic
Mon domingue key_introduction to semanticMon domingue key_introduction to semantic
Mon domingue key_introduction to semantic
 
Tue acosta tut_providing_linkeddata
Tue acosta tut_providing_linkeddataTue acosta tut_providing_linkeddata
Tue acosta tut_providing_linkeddata
 

Recently uploaded

BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...noida100girls
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst SummitHolger Mueller
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...anilsa9823
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Serviceritikaroy0888
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurSuhani Kapoor
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfPaul Menig
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
 
The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024christinemoorman
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsApsara Of India
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 

Recently uploaded (20)

BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...BEST ✨ Call Girls In  Indirapuram Ghaziabad  ✔️ 9871031762 ✔️ Escorts Service...
BEST ✨ Call Girls In Indirapuram Ghaziabad ✔️ 9871031762 ✔️ Escorts Service...
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst Summit
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Service
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024The CMO Survey - Highlights and Insights Report - Spring 2024
The CMO Survey - Highlights and Insights Report - Spring 2024
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Best Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting PartnershipBest Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting Partnership
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 

ESWC SS 2012 - Monday Tutorial 2 Barry Norton: Introduction to SPARQL

  • 2. Overview • • • • • • • • What is SPARQL? ASK and SELECT query forms UNION and ORDER BY Subsets of results FILTER expressions and functions OPTIONAL DESCRIBE and CONSTRUCT query forms Common problems Introduction to SPARQL #2
  • 3. What is SPARQL? • SPARQL is a query language for RDF data – http://www.w3.org/TR/rdf-sparql-query/ • It is also a protocol • It is designed around graph patterns – Graph patterns use Turtle syntax • SPARQL 1.0 is query only – SPARQL 1.1 (covered next, not yet a recommendation) includes syntax for updates Introduction to SPARQL #3
  • 4. Ask • Did 'Steve Hillage' make the album 'Fish Rising'? PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dbpedia: <http://dbpedia.org/resource/> ASK { dbpedia:Steve_Hillage foaf:made ?album . ?album dc:title "Fish Rising" . } • Namespaces are added with 'PREFIX' directive • Statement patterns that make up the graph are between {} brackets Introduction to SPARQL #4
  • 5. Select • What albums and tracks did 'Steve Hillage' make? PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> SELECT ?album_name ?track_title WHERE { dbpedia:Steve_Hillage foaf:made ?album . ?album dc:title ?album_name. ?album music-ont:track ?track . ?track dc:title ?track_title . } • All variables in a query can be selected with '*' – i.e. SELECT * WHERE { … } Introduction to SPARQL #5
  • 6. Union • 'Steve Hillage' and 'Jimi Hendrix'? PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> SELECT ?album_name ?track_title WHERE { { dbpedia:Steve_Hillage foaf:made ?album . } UNION { dbpedia:Jimi_Hendrix foaf:made ?album . } ?album dc:title ?album_name. ?album music-ont:track ?track . ?track dc:title ?track_title . } Introduction to SPARQL #6
  • 7. Order By • In what order did 'Steve Hillage' release his albums? PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> SELECT distinct ?album_name ?date WHERE { dbpedia:Steve_Hillage foaf:made ?album . ?album dc:title ?album_name. ?album music-ont:track ?track . ?album dc:date ?date. } ORDER BY( ?date) Introduction to SPARQL #7
  • 8. Subsets of results • What albums and tracks did 'Steve Hillage' make? PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> SELECT ?album_name ?track_title WHERE { dbpedia:Steve_Hillage foaf:made ?album . ?album dc:title ?album_name. ?album music-ont:track ?track . ?track dc:title ?track_title . } OFFSET 10 LIMIT 15 • Start after the 10th solution, provide (up to) 15 more Introduction to SPARQL #8
  • 9. Filtering solutions • What are 'Steve Hillage' longer tracks? PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> SELECT ?album_name ?track_title ?duration WHERE { dbpedia:Steve_Hillage foaf:made ?album . ?album dc:title ?album_name. ?album music-ont:track ?track . ?track dc:title ?track_title . ?track music-ont:duration ?duration . FILTER( ?duration > 500000 ). } • Allow only those solutions where the track length is more than 500 seconds Introduction to SPARQL #9
  • 10. Functions • What albums and tracks did 'Steve Hillage' make? PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> SELECT ?album_name ?track_title WHERE { dbpedia:Steve_Hillage foaf:made ?album . ?album dc:title ?album_name. ?album music-ont:track ?track . ?track dc:title ?track_title . FILTER( REGEX( ?track_title, "hurd.*", "i") ) } • Allow only those solutions where the track title contains a substring that begins with 'hurd' in any case Introduction to SPARQL #10
  • 11. Filter expressions • Can be combined with logical, arithmetic, casts and comparisons, e.g. FILTER( ?age < 30 && xsd:double(?weight) < (?empty + ?fuel) ) • Also tests, accessors, e.g. FILTER( isURI( ?id ) && datatype( ?age ) = xsd:double ) Introduction to SPARQL #11
  • 12. Optionals • Parts of the matching graph can be optional • Use OPTIONAL {} to enclose the optional parts • Can test in filter expressions if variable are bound • Using logical NOT '!' it is possible to filter out solutions for the optional part Introduction to SPARQL #12
  • 13. Optionals • Albums from artists who are not dead PREFIX PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> dbp-ont: <http://dbpedia.org/ontology/> SELECT distinct ?artist_name ?album_name ?place_of_death WHERE { ?artist foaf:made ?album . ?artist foaf:name ?artist_name . ?album dc:title ?album_name. ?album music-ont:track ?track . ?track dc:title ?track_title . OPTIONAL { ?artist dbp-ont:deathPlace ?place_of_death } FILTER( ! BOUND( ?place_of_death ) ). } Introduction to SPARQL #13
  • 14. Describe • Returns RDF statements about any resource identified by the query PREFIX dbpedia: <http://dbpedia.org/resource/> DESCRIBE dbpedia:Steve_Hillage PREFIX foaf: <http://xmlns.com/foaf/0.1/> DESCRIBE ?x ?y <http://example.org/> WHERE {?x foaf:knows ?y} Introduction to SPARQL #14
  • 15. Construct • Returns RDF statements created from variable bindings PREFIX PREFIX PREFIX PREFIX dc: <http://purl.org/dc/elements/1.1/> foaf: <http://xmlns.com/foaf/0.1/> dbpedia: <http://dbpedia.org/resource/> music-ont: <http://purl.org/ontology/mo/> CONSTRUCT { ?album dc:creator dbpedia:Steve_Hillage } WHERE { dbpedia:Steve_Hillage foaf:made ?album . ?album dc:title ?album_name. ?album music-ont:track ?track . } Introduction to SPARQL #15
  • 16. Common Problems • Spelling mistakes in identifiers are not noticed – It is simply a different URI – URIs are LONG, are case-sensitive, have '#' or '/' for local part • Easy to use the right local name with the wrong namespace • Literals are compared on type, language and value – "Steve Hillage"@EN is not the same as "Steve Hillage" – "3" is not the same as "3"^^xsd:integer Introduction to SPARQL #16
  • 17. Summary • SPARQL is a powerful query language for RDF • SPARQL 1.0 is read-only • SPARQL 1.1 will allow updates Introduction to SPARQL #17