115
SPARQL - Query Basics and Federated Queries Knud Möller, Talis Systems Ltd. @knudmoeller 16 April 2012 Tutorial: Practical Cross-Dataset Queries on the Web of Data WWW2012, Lyon, France

SPARQL - Basic and Federated Queries

Embed Size (px)

Citation preview

Page 1: SPARQL - Basic and Federated Queries

SPARQL -

Query Basics and Federated Queries

Knud Möller, Talis Systems Ltd.@knudmoeller

16 April 2012Tutorial: Practical Cross-Dataset Queries on the Web of Data

WWW2012, Lyon, France

Page 2: SPARQL - Basic and Federated Queries

What is SPARQL?

• query language for RDF graphs (i.e., linked data)

• get specific information out of a dataset (or several datasets)

• “The SQL for the Web of Data”

SPARQL

Page 3: SPARQL - Basic and Federated Queries

History

• 2004: work started on SPARQL

• 2008: SPARQL 1.0 finished (W3C Rec)

• 2009: work started on SPARQL 1.1

• 2012 (now): SPARQL 1.1 almost finished

• soon: SPARQL 1.1 finished

Page 4: SPARQL - Basic and Federated Queries

SPARQL Endpoint

SPAR

QL Endpoint

Query in

Result back

Page 5: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

Page 6: SPARQL - Basic and Federated Queries

SPARQL in a Nutshell

query clause1

WHERE clause2

Page 7: SPARQL - Basic and Federated Queries

SPARQL in a Nutshell

query clause1

WHERE clause2

What do I want to get back?• SELECT: list of things• DESCRIBE: RDF graph for one

resource• CONSTRUCT: custom RDF graph• ASK: boolean value (true or false)

Page 8: SPARQL - Basic and Federated Queries

SPARQL in a Nutshell

query clause1

WHERE clause2

What do I want to get back?• SELECT: list of things• DESCRIBE: RDF graph for one

resource• CONSTRUCT: custom RDF graph• ASK: boolean value (true or false)

Which part of the graph am I looking for?• WHERE• triple patterns• graph patterns

Page 9: SPARQL - Basic and Federated Queries

SPARQL in a Nutshell

query clause1

WHERE clause2

Prologue0

What do I want to get back?• SELECT: list of things• DESCRIBE: RDF graph for one

resource• CONSTRUCT: custom RDF graph• ASK: boolean value (true or false)

Which part of the graph am I looking for?• WHERE• triple patterns• graph patterns

Page 10: SPARQL - Basic and Federated Queries

SPARQL in a Nutshell

query clause1

WHERE clause2

Prologue0

Modifiers3

What do I want to get back?• SELECT: list of things• DESCRIBE: RDF graph for one

resource• CONSTRUCT: custom RDF graph• ASK: boolean value (true or false)

Which part of the graph am I looking for?• WHERE• triple patterns• graph patterns

Page 11: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

Page 12: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

Page 13: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

Page 14: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

graph pattern

Page 15: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

graph pattern

Page 16: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_date

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

ORDER BY ?release_date

graph pattern

Page 17: SPARQL - Basic and Federated Queries

Example Data• from music site Jamendo:

http://ww.jamendo.com

• linked data at DBTune:

http://dbtune.org/jamendo/

• thousands of artists with albums, tracks, etc.

• additionally, some geographical data from Geonames:

http://www.geonames.org/

Page 18: SPARQL - Basic and Federated Queries
Page 19: SPARQL - Basic and Federated Queries

artists:3732

mo:MusicArtist

a

locations:3019599/foaf:based_near

http://blackshoulders.hautetfort.com/

foaf:homepage

http://img.jamendo.com/artists/w/white-shoulders.jpg

foaf:img

records:8836

foaf:made

records:4092 foaf:made

records:6361foaf:made

records:3738

foaf:made

foaf:name

artists:3908a

foaf:based_near

http://www.petithomme.org

foaf:homepage

http://img.jamendo.com/

artists/p/petit.homme.gif

foaf:imgrecords:4295

foaf:made

records:3604

foaf:made

foaf:name

mo:Record

a

dce:date

dce:title

tracks:90508

mo:track

tracks:90496

mo:track

tracks:90510

mo:track

tracks:90504

mo:track

tags:noisy hg:taggedWithTag

tags:electro

hg:taggedWithTag

tags:experimental

hg:taggedWithTag

tags:noise

hg:taggedWithTag

foaf:maker

Whiteshoulders Petit Homme

2007-10-09T15:58:17

W (EP)

Page 20: SPARQL - Basic and Federated Queries

Text

@base <http://dbtune.org/jamendo/> .@prefix foaf: <http://xmlns.com/foaf/0.1/> .@prefix mo: <http://purl.org/ontology/mo/> .@prefix dce: <http://purl.org/dc/elements/1.1/> .@prefix hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/> .@prefix tags: <tag/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<artist/3908> a mo:MusicArtist ; foaf:based_near <http://sws.geonames.org/3019599/> ; foaf:homepage <http://www.petithomme.org> ; foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> ; foaf:made <record/3604>, <record/4295> ; foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist ; foaf:based_near <http://sws.geonames.org/3019599/> ; foaf:homepage <http://blackshoulders.hautetfort.com/> ; foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> ; foaf:made <record/3738>, <record/4092>, <record/6361>, <record/8836> ; foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime ; dce:title "W (EP)"^^xsd:string ; mo:track <track/90496>, <track/90504>, <track/90508>, <track/90510> ; hg:taggedWithTag tags:electro, tags:experimental, tags:noise, tags:noisy ; a mo:Record ; foaf:maker <artist/3732> .

Page 21: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 22: SPARQL - Basic and Federated Queries

Triple and Graph Patterns

Page 23: SPARQL - Basic and Federated Queries

WHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (year(?release_date) = 2007 && month(?release_date) = 7)}

Page 24: SPARQL - Basic and Federated Queries

no variables

Page 25: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 26: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 27: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 28: SPARQL - Basic and Federated Queries

one variable

Page 29: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 30: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 31: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 32: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 33: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 34: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 35: SPARQL - Basic and Federated Queries

two variables

Page 36: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 37: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 38: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 39: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 40: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 41: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 42: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 43: SPARQL - Basic and Federated Queries

Text

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 44: SPARQL - Basic and Federated Queries

?subject ?predicate ?object

three variables

Page 45: SPARQL - Basic and Federated Queries

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 46: SPARQL - Basic and Federated Queries

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 47: SPARQL - Basic and Federated Queries

?artist a mo:MusicArtist ;! ! foaf:name ?artist_name ;! ! foaf:homepage ?homepage .

graph pattern

Page 48: SPARQL - Basic and Federated Queries

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 49: SPARQL - Basic and Federated Queries

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 50: SPARQL - Basic and Federated Queries

<artist/3908> a mo:MusicArtist .<artist/3908> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3908> foaf:homepage <http://www.petithomme.org> .<artist/3908> foaf:img <http://img.jamendo.com/artists/p/petit.homme.gif> .<artist/3908> foaf:made <record/3604> .<artist/3908> foaf:made <record/4295> .<artist/3908> foaf:name "Petit Homme"^^xsd:string .

<artist/3732> a mo:MusicArtist .<artist/3732> foaf:based_near <http://sws.geonames.org/3019599/> .<artist/3732> foaf:homepage <http://blackshoulders.hautetfort.com/> .<artist/3732> foaf:img <http://img.jamendo.com/artists/w/white-shoulders.jpg> .<artist/3732> foaf:made <record/3738> .<artist/3732> foaf:made <record/4092> .<artist/3732> foaf:made <record/6361> .<artist/3732> foaf:made <record/8836> .<artist/3732> foaf:name "Whiteshoulders"^^xsd:string .

<record/8836> dce:date "2007-10-09T15:58:17"^^xsd:dateTime .<record/8836> dce:title "W (EP)"^^xsd:string .<record/8836> mo:track <track/90496> .<record/8836> mo:track <track/90504> .<record/8836> mo:track <track/90508> .<record/8836> mo:track <track/90510> .<record/8836> hg:taggedWithTag tags:electro . <record/8836> hg:taggedWithTag tags:experimental .<record/8836> hg:taggedWithTag tags:noise .<record/8836> hg:taggedWithTag tags:noisy .<record/8836> a mo:Record .<record/8836> foaf:maker <artist/3732> .

Page 51: SPARQL - Basic and Federated Queries

Interfaces to SPARQL endpoints

•Web interfaces

• Bindings for programming languages

• straight HTTP

• command line interfaces

Page 53: SPARQL - Basic and Federated Queries

http://factforge.net/sparql

Page 55: SPARQL - Basic and Federated Queries

ARQ

we will use the arq command line tool - see the ARQ Command Line Cheat Sheet:

arq --data data/jamendo.nt

--query queries/query5.rq

Page 56: SPARQL - Basic and Federated Queries

Example Scenario

• Get all albums for a particular month (e.g., July 2007)

• List all Jamendo artists in France

• explore datasets and build final query bit by bit

• learn about different features of SPARQL along the way

• cannot cover every aspect of SPARQL! E.g., property paths are missing.

Page 57: SPARQL - Basic and Federated Queries

List all ClassesSELECT DISTINCT ?classWHERE {! ?s a ?class .}

find all types of things in the dataset (classes)

Page 58: SPARQL - Basic and Federated Queries

List all ClassesSELECT DISTINCT ?classWHERE {! ?s a ?class .}

find all types of things in the dataset (classes)

--------------------------------------------------------| class |========================================================| <http://purl.org/ontology/mo/Playlist> || <http://purl.org/ontology/mo/Signal> || <http://purl.org/ontology/mo/Lyrics> || <http://purl.org/ontology/mo/Track> || <http://www.w3.org/2006/time#Interval> || <http://purl.org/ontology/mo/Torrent> || <http://purl.org/ontology/mo/ED2K> || <http://purl.org/ontology/mo/Record> || <http://www.holygoat.co.uk/owl/redwood/0.1/tags/Tag> || <http://purl.org/ontology/mo/MusicArtist> || <http://xmlns.com/foaf/0.1/Document> |--------------------------------------------------------

Page 59: SPARQL - Basic and Federated Queries

List all ClassesSELECT DISTINCT ?classWHERE {! ?s a ?class .}

find all types of things in the dataset (classes)

--------------------------------------------------------| class |========================================================| <http://purl.org/ontology/mo/Playlist> || <http://purl.org/ontology/mo/Signal> || <http://purl.org/ontology/mo/Lyrics> || <http://purl.org/ontology/mo/Track> || <http://www.w3.org/2006/time#Interval> || <http://purl.org/ontology/mo/Torrent> || <http://purl.org/ontology/mo/ED2K> || <http://purl.org/ontology/mo/Record> || <http://www.holygoat.co.uk/owl/redwood/0.1/tags/Tag> || <http://purl.org/ontology/mo/MusicArtist> || <http://xmlns.com/foaf/0.1/Document> |--------------------------------------------------------

Page 60: SPARQL - Basic and Federated Queries

Properties of ArtistsPREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?predWHERE {! ?artist a mo:MusicArtist ;! ! ?pred ?obj .}

all properties for the mo:MusicArtist class

Page 61: SPARQL - Basic and Federated Queries

Properties of ArtistsPREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?predWHERE {! ?artist a mo:MusicArtist ;! ! ?pred ?obj .}

all properties for the mo:MusicArtist class

-----------------------------------------------------| pred |=====================================================| <http://xmlns.com/foaf/0.1/name> || <http://xmlns.com/foaf/0.1/made> || <http://xmlns.com/foaf/0.1/img> || <http://xmlns.com/foaf/0.1/based_near> || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> || <http://xmlns.com/foaf/0.1/homepage> || mo:biography |-----------------------------------------------------

Page 62: SPARQL - Basic and Federated Queries

Properties of Artists, ctd.PREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?classWHERE {! ?artist a mo:MusicArtist ;! ! ?pred ?obj .! ?obj a ?class ;}

properties with objects

Page 63: SPARQL - Basic and Federated Queries

Properties of Artists, ctd.PREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?classWHERE {! ?artist a mo:MusicArtist ;! ! ?pred ?obj .! ?obj a ?class ;}

properties with objects

------------------------------------------------| pred | class |================================================| <http://xmlns.com/foaf/0.1/made> | mo:Record |------------------------------------------------

only one result?

Page 64: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?classWHERE {! ?artist a mo:MusicArtist ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }} OPTIONAL statement

Properties of Artists, ctd.

Page 65: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?classWHERE {! ?artist a mo:MusicArtist ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }} OPTIONAL statement

-----------------------------------------------------------------| pred | class |=================================================================| <http://xmlns.com/foaf/0.1/name> | || <http://xmlns.com/foaf/0.1/made> | mo:Record || <http://xmlns.com/foaf/0.1/img> | || <http://xmlns.com/foaf/0.1/based_near> | || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | || <http://xmlns.com/foaf/0.1/homepage> | || mo:biography | |-----------------------------------------------------------------

Properties of Artists, ctd.

Page 66: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dce: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?pred ?classWHERE {! ?record a mo:Record ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }}

Properties of Records

Page 67: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dce: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?pred ?classWHERE {! ?record a mo:Record ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }}

----------------------------------------------------------------------| pred | class |======================================================================| foaf:maker | mo:MusicArtist || mo:track | mo:Track || hg:taggedWithTag | hg:Tag || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | || mo:available_as | mo:ED2K || mo:image | || dce:date | || mo:available_as | mo:Torrent || dce:title | || mo:available_as | mo:Playlist || dce:description | |----------------------------------------------------------------------

Properties of Records

Page 68: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dce: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?pred ?classWHERE {! ?record a mo:Record ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }}

----------------------------------------------------------------------| pred | class |======================================================================| foaf:maker | mo:MusicArtist || mo:track | mo:Track || hg:taggedWithTag | hg:Tag || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | || mo:available_as | mo:ED2K || mo:image | || dce:date | || mo:available_as | mo:Torrent || dce:title | || mo:available_as | mo:Playlist || dce:description | |----------------------------------------------------------------------

Properties of Records

Page 69: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dce: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?pred ?classWHERE {! ?record a mo:Record ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }} ORDER BY ASC(?pred) DESC(?class)

Properties of Records, ctd.

ORDER BY statement

Page 70: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dce: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?pred ?classWHERE {! ?record a mo:Record ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }} ORDER BY ASC(?pred) DESC(?class)

----------------------------------------------------------------------| pred | class |======================================================================| dce:date | || dce:description | || dce:title | || mo:available_as | mo:Torrent || mo:available_as | mo:Playlist || mo:available_as | mo:ED2K || mo:image | || mo:track | mo:Track || hg:taggedWithTag | hg:Tag || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | || foaf:maker | mo:MusicArtist |----------------------------------------------------------------------

Properties of Records, ctd.

ORDER BY statement

Page 71: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dce: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?pred ?classWHERE {! ?record a mo:Record ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }} ORDER BY ASC(?pred) DESC(?class)

----------------------------------------------------------------------| pred | class |======================================================================| dce:date | || dce:description | || dce:title | || mo:available_as | mo:Torrent || mo:available_as | mo:Playlist || mo:available_as | mo:ED2K || mo:image | || mo:track | mo:Track || hg:taggedWithTag | hg:Tag || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | || foaf:maker | mo:MusicArtist |----------------------------------------------------------------------

Properties of Records, ctd.

ORDER BY statement

Page 72: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX hg: <http://www.holygoat.co.uk/owl/redwood/0.1/tags/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dce: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?pred ?classWHERE {! ?record a mo:Record ;! ! ?pred ?obj .! OPTIONAL {! ! ?obj a ?class .! }} ORDER BY ASC(?pred) DESC(?class)

----------------------------------------------------------------------| pred | class |======================================================================| dce:date | || dce:description | || dce:title | || mo:available_as | mo:Torrent || mo:available_as | mo:Playlist || mo:available_as | mo:ED2K || mo:image | || mo:track | mo:Track || hg:taggedWithTag | hg:Tag || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | || foaf:maker | mo:MusicArtist |----------------------------------------------------------------------

Properties of Records, ctd.

ORDER BY statement

Page 73: SPARQL - Basic and Federated Queries

Problem: Wrong data format

• date/time related functions in SPARQL expect dates in xsd:dateTime format:

"2007-06-15T17:13:58"^^xsd:dateTime

• however, source data has dates as plain literals with wrong format:

"2007-06-15 17:13:58"

Page 74: SPARQL - Basic and Federated Queries

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX dce: <http://purl.org/dc/elements/1.1/>

CONSTRUCT {! ?s2 dce:date ?date_fixed .}WHERE {! ?s2 dce:date ?date .! BIND (STRDT(REPLACE(?date, " ", "T"), xsd:dateTime) AS ?date_fixed)}

Fixing Data

Page 75: SPARQL - Basic and Federated Queries

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX dce: <http://purl.org/dc/elements/1.1/>

CONSTRUCT {! ?s2 dce:date ?date_fixed .}WHERE {! ?s2 dce:date ?date .! BIND (STRDT(REPLACE(?date, " ", "T"), xsd:dateTime) AS ?date_fixed)}

Fixing Data

Page 76: SPARQL - Basic and Federated Queries

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX dce: <http://purl.org/dc/elements/1.1/>

CONSTRUCT {! ?s2 dce:date ?date_fixed .}WHERE {! ?s2 dce:date ?date .! BIND (STRDT(REPLACE(?date, " ", "T"), xsd:dateTime) AS ?date_fixed)}

Fixing Data

Page 77: SPARQL - Basic and Federated Queries

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX dce: <http://purl.org/dc/elements/1.1/>

CONSTRUCT {! ?s2 dce:date ?date_fixed .}WHERE {! ?s2 dce:date ?date .! BIND (STRDT(REPLACE(?date, " ", "T"), xsd:dateTime) AS ?date_fixed)}

Fixing Data

Page 78: SPARQL - Basic and Federated Queries

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX dce: <http://purl.org/dc/elements/1.1/>

CONSTRUCT {! ?s2 dce:date ?date_fixed .}WHERE {! ?s2 dce:date ?date .! BIND (STRDT(REPLACE(?date, " ", "T"), xsd:dateTime) AS ?date_fixed)}

Fixing Data

Page 79: SPARQL - Basic and Federated Queries

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX dce: <http://purl.org/dc/elements/1.1/>

CONSTRUCT {! ?s2 dce:date ?date_fixed .}WHERE {! ?s2 dce:date ?date .! BIND (STRDT(REPLACE(?date, " ", "T"), xsd:dateTime) AS ?date_fixed)}

Fixing Data

@prefix dce: <http://purl.org/dc/elements/1.1/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://dbtune.org/jamendo/record/6015> dce:date "2007-06-15T17:13:58"^^xsd:dateTime .

<http://dbtune.org/jamendo/record/6343> dce:date "2007-07-05T19:32:23"^^xsd:dateTime .

<http://dbtune.org/jamendo/record/12863> dce:date "2007-11-19T11:46:34"^^xsd:dateTime .

<http://dbtune.org/jamendo/record/3993> dce:date "2007-02-01T18:08:28"^^xsd:dateTime .

Page 80: SPARQL - Basic and Federated Queries

PREFIX dce: <http://purl.org/dc/elements/1.1/>

CONSTRUCT {! ?s ?p ?o .}WHERE {! ?s ?p ?o .! FILTER (?p != dce:date)}

Filtering Results

Page 81: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_dateWHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (YEAR(?release_date) = 2007 && MONTH(?release_date) = 7)}ORDER BY ?release_date

All albums for 2007/07

Page 82: SPARQL - Basic and Federated Queries

PREFIX mo: <http://purl.org/ontology/mo/>PREFIX dce: <http://purl.org/dc/elements/1.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?album ?title ?release_dateWHERE {! ?album a mo:Record ;! ! dce:date ?release_date ;! ! dce:title ?title .! FILTER (YEAR(?release_date) = 2007 && MONTH(?release_date) = 7)}ORDER BY ?release_date

All albums for 2007/07

--------------------------------------------------------------------------------------------------------------------------| album | title | release_date |==========================================================================================================================| <http://dbtune.org/jamendo/record/6310> | "Demo 2005"^^xsd:string | "2007-07-04T16:24:23"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6320> | "Cinema"^^xsd:string | "2007-07-04T16:39:11"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6312> | "ECLECTEK II"^^xsd:string | "2007-07-04T17:02:09"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6302> | "Unknow user"^^xsd:string | "2007-07-04T18:06:18"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6323> | "girls always cry-xysides"^^xsd:string | "2007-07-04T23:16:26"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6327> | "Fest-noz is dead"^^xsd:string | "2007-07-05T11:29:03"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6328> | "Félin Pour L'Autre"^^xsd:string | "2007-07-05T13:04:37"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6250> | "BLAPP."^^xsd:string | "2007-07-05T14:18:11"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6332> | "Cà Phê and Pizza"^^xsd:string | "2007-07-05T16:04:02"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6329> | "Life in Lento Violento"^^xsd:string | "2007-07-05T16:39:17"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6336> | "Transition"^^xsd:string | "2007-07-05T16:47:49"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6338> | "Die Zahl der Toten"^^xsd:string | "2007-07-05T19:20:52"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6343> | "Offender Girl"^^xsd:string | "2007-07-05T19:32:23"^^xsd:dateTime || <http://dbtune.org/jamendo/record/6377> | "Donne moi"^^xsd:string | "2007-07-10T17:29:23"^^xsd:dateTime |

Page 83: SPARQL - Basic and Federated Queries

SPARQLFederated Queries

Page 84: SPARQL - Basic and Federated Queries

PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?locationWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near ?location .}

Artists in France

Page 85: SPARQL - Basic and Federated Queries

PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?locationWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near ?location .}

Artists in France

Page 86: SPARQL - Basic and Federated Queries

PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX mo: <http://purl.org/ontology/mo/>

SELECT DISTINCT ?locationWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near ?location .}

Artists in France

--------------------------------------| location |======================================| <http://sws.geonames.org/2661602/> || <http://sws.geonames.org/2997861/> || <http://sws.geonames.org/3013767/> || <http://sws.geonames.org/3013726/> || <http://sws.geonames.org/2802361/> || <http://sws.geonames.org/3026644/> || <http://sws.geonames.org/3017382/> || <http://sws.geonames.org/3865483/> || <http://sws.geonames.org/2968815/> || <http://sws.geonames.org/3013657/> || <http://sws.geonames.org/2987410/> || <http://sws.geonames.org/2750405/> || <http://sws.geonames.org/6424360/> || <http://sws.geonames.org/6556330/> || <http://sws.geonames.org/3213264/> || <http://sws.geonames.org/2967196/> |

Page 90: SPARQL - Basic and Federated Queries

SELECT DISTINCT ?predWHERE {! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=07d5e23c8d7bf5ae576f39c64e822ea6baffea98>! {! ! <http://sws.geonames.org/2661602/> ?pred ?obj .! }}

Querying Remote Endpoint

-------------------------------------------------------| pred |=======================================================| <http://www.geonames.org/ontology#alternateName> || <http://www.geonames.org/ontology#countryCode> || <http://www.geonames.org/ontology#featureClass> || <http://www.geonames.org/ontology#featureCode> || <http://www.geonames.org/ontology#locationMap> || <http://www.geonames.org/ontology#name> || <http://www.geonames.org/ontology#parentADM1> || <http://www.geonames.org/ontology#parentCountry> || <http://www.geonames.org/ontology#parentFeature> || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> || <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> || <http://www.w3.org/2003/01/geo/wgs84_pos#lat> || <http://www.w3.org/2003/01/geo/wgs84_pos#long> || <http://www.geonames.org/ontology#childrenFeatures> |-------------------------------------------------------

Page 91: SPARQL - Basic and Federated Queries

SELECT DISTINCT ?predWHERE {! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=07d5e23c8d7bf5ae576f39c64e822ea6baffea98>! {! ! <http://sws.geonames.org/2661602/> ?pred ?obj .! }}

Querying Remote Endpoint

-------------------------------------------------------| pred |=======================================================| <http://www.geonames.org/ontology#alternateName> || <http://www.geonames.org/ontology#countryCode> || <http://www.geonames.org/ontology#featureClass> || <http://www.geonames.org/ontology#featureCode> || <http://www.geonames.org/ontology#locationMap> || <http://www.geonames.org/ontology#name> || <http://www.geonames.org/ontology#parentADM1> || <http://www.geonames.org/ontology#parentCountry> || <http://www.geonames.org/ontology#parentFeature> || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> || <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> || <http://www.w3.org/2003/01/geo/wgs84_pos#lat> || <http://www.w3.org/2003/01/geo/wgs84_pos#long> || <http://www.geonames.org/ontology#childrenFeatures> |-------------------------------------------------------

Page 92: SPARQL - Basic and Federated Queries

SELECT DISTINCT ?predWHERE {! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=07d5e23c8d7bf5ae576f39c64e822ea6baffea98>! {! ! <http://sws.geonames.org/2661602/> ?pred ?obj .! }}

Querying Remote Endpoint

-------------------------------------------------------| pred |=======================================================| <http://www.geonames.org/ontology#alternateName> || <http://www.geonames.org/ontology#countryCode> || <http://www.geonames.org/ontology#featureClass> || <http://www.geonames.org/ontology#featureCode> || <http://www.geonames.org/ontology#locationMap> || <http://www.geonames.org/ontology#name> || <http://www.geonames.org/ontology#parentADM1> || <http://www.geonames.org/ontology#parentCountry> || <http://www.geonames.org/ontology#parentFeature> || <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> || <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> || <http://www.w3.org/2003/01/geo/wgs84_pos#lat> || <http://www.w3.org/2003/01/geo/wgs84_pos#long> || <http://www.geonames.org/ontology#childrenFeatures> |-------------------------------------------------------

Page 93: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist ?nameWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near ?location .! !! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=07d5e23c8d7bf5ae576f39c64e822ea6baffea98>! {! ! ?location geonames:name ?name .! }! !}LIMIT 50

Combining Local + Remote

Page 94: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist ?nameWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near ?location .! !! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=07d5e23c8d7bf5ae576f39c64e822ea6baffea98>! {! ! ?location geonames:name ?name .! }! !}LIMIT 50

Combining Local + Remote

-------------------------------------------------------------------------------------| artist | name |=====================================================================================| <http://dbtune.org/jamendo/artist/5496> | "Kanton Basel-Stadt" || <http://dbtune.org/jamendo/artist/256> | "Département de la Loire-Atlantique" || <http://dbtune.org/jamendo/artist/337049> | "Département de la Haute-Garonne" || <http://dbtune.org/jamendo/artist/8035> | "Département des Hautes-Pyrénées" || <http://dbtune.org/jamendo/artist/6260> | "Kingdom of Belgium" || <http://dbtune.org/jamendo/artist/2471> | "Département de la Charente-Maritime" || <http://dbtune.org/jamendo/artist/3572> | "Republic of France" || <http://dbtune.org/jamendo/artist/4680> | "Argentine Republic" |

Page 95: SPARQL - Basic and Federated Queries

PREFIX geonames: <http://www.geonames.org/ontology#>

SELECT DISTINCT ?country ?nameWHERE {! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=07d5e23c8d7bf5ae576f39c64e822ea6baffea98>! {! ! SELECT DISTINCT ?country ?name! ! WHERE {! ! ! ?country geonames:featureCode geonames:A.PCLI ;! ! ! ! geonames:name ?name .! ! ! FILTER (regex(?name, "france", "i"))! ! }! }}ORDER BY ?name

What is France?

Page 96: SPARQL - Basic and Federated Queries

PREFIX geonames: <http://www.geonames.org/ontology#>

SELECT DISTINCT ?country ?nameWHERE {! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=07d5e23c8d7bf5ae576f39c64e822ea6baffea98>! {! ! SELECT DISTINCT ?country ?name! ! WHERE {! ! ! ?country geonames:featureCode geonames:A.PCLI ;! ! ! ! geonames:name ?name .! ! ! FILTER (regex(?name, "france", "i"))! ! }! }}ORDER BY ?name

What is France?

-------------------------------------------------------------| country | name |=============================================================| <http://sws.geonames.org/3017382/> | "Republic of France" |-------------------------------------------------------------

Page 97: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist ?nameWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near <http://sws.geonames.org/3017382/> ;! ! foaf:name ?name .! !}ORDER BY ?name

Artists in France (1)

Page 98: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist ?nameWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near <http://sws.geonames.org/3017382/> ;! ! foaf:name ?name .! !}ORDER BY ?name

Artists in France (1)

-------------------------------------------------------------------------------------------------------------------| artist | name |===================================================================================================================| <http://dbtune.org/jamendo/artist/3972> | "#2 Orchestra"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/5865> | "(own+line)"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/4779> | "7BZH"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/3297> | "AMarie.C"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/754> | "Adam Lwo"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/4825> | "Alteranti"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/784> | "Ataraxia Rebel Force"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/289> | "Auto/Sexual"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/565> | "BUREAU DES FLUIDES"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/336803> | "Baron Baroff"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/8316> | "Bertrand Homassel"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/274> | "Bleacher"^^<http://www.w3.org/2001/XMLSchema#string> || <http://dbtune.org/jamendo/artist/3835> | "Brigade Neurale"^^<http://www.w3.org/2001/XMLSchema#string> |

Page 99: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist ?name ?place ?place_nameWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near ?place ;! ! foaf:name ?name .!! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=APIKEY>! {! ! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! ! geonames:name ?place_name .! }! !}ORDER BY ?nameLIMIT 10

Artists in France (2)

Page 100: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist ?name ?place ?place_nameWHERE {! ?artist a mo:MusicArtist ;! ! foaf:based_near ?place ;! ! foaf:name ?name .!! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=APIKEY>! {! ! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! ! geonames:name ?place_name .! }! !}ORDER BY ?nameLIMIT 10

Artists in France (2)

Page 101: SPARQL - Basic and Federated Queries

PREFIX geonames: ! <http://www.geonames.org/ontology#>

CONSTRUCT {! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! geonames:name ?name .}WHERE {! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=APIKEY>! {! ! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! ! geonames:name ?name .! }! !}

Places in France

Page 102: SPARQL - Basic and Federated Queries

PREFIX geonames: ! <http://www.geonames.org/ontology#>

CONSTRUCT {! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! geonames:name ?name .}WHERE {! SERVICE <http://api.kasabi.com/dataset/geonames/apis/sparql?apikey=APIKEY>! {! ! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! ! geonames:name ?name .! }! !}

Places in France

@prefix geonames: <http://www.geonames.org/ontology#> .

<http://sws.geonames.org/3003977/> geonames:name "Le Grand Merimont" ; geonames:parentCountry <http://sws.geonames.org/3017382/> .

<http://sws.geonames.org/2994812/> geonames:name "Mean-Ruz" ; geonames:parentCountry <http://sws.geonames.org/3017382/> .

<http://sws.geonames.org/7535264/> geonames:name "Golf du Prieuré" ; geonames:parentCountry <http://sws.geonames.org/3017382/> .

Page 103: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist_name ?place_nameFROM <../data/jamendo-rdf/jamendo.nt>FROM <../data/in_france.nt>WHERE { ! ?artist a mo:MusicArtist ; ! ! foaf:based_near ?place ; ! ! foaf:name ?artist_name .! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! geonames:name ?place_name .}ORDER BY ?artist_name

Et voilà - Les artistes de France!

Page 104: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist_name ?place_nameFROM <../data/jamendo-rdf/jamendo.nt>FROM <../data/in_france.nt>WHERE { ! ?artist a mo:MusicArtist ; ! ! foaf:based_near ?place ; ! ! foaf:name ?artist_name .! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! geonames:name ?place_name .}ORDER BY ?artist_name

Et voilà - Les artistes de France!

----------------------------------------------------------------------------------------------------------------| artist_name | place_name |================================================================================================================| "#2 Orchestra"^^<http://www.w3.org/2001/XMLSchema#string> | "Republic of France" || "#Blockout"^^<http://www.w3.org/2001/XMLSchema#string> | "Département des Yvelines" || "#Dance 75#"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "#NarNaoud#"^^<http://www.w3.org/2001/XMLSchema#string> | "Département de la Gironde" || "#ZedMeta#"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "#Zorglups#"^^<http://www.w3.org/2001/XMLSchema#string> | "Département de l'Essonne" || "&ND"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "(own+line)"^^<http://www.w3.org/2001/XMLSchema#string> | "Republic of France" || "* Q u i r y *"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "-=Kwada=-"^^<http://www.w3.org/2001/XMLSchema#string> | "Département de la Haute-Garonne" || "-DEMO-"^^<http://www.w3.org/2001/XMLSchema#string> | "Département du Nord" |

Page 105: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist_name ?place_nameFROM <../data/jamendo-rdf/jamendo.nt>FROM <../data/in_france.nt>WHERE { ! ?artist a mo:MusicArtist ; ! ! foaf:based_near ?place ; ! ! foaf:name ?artist_name .! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! geonames:name ?place_name .}ORDER BY ?artist_name

Et voilà - Les artistes de France!

----------------------------------------------------------------------------------------------------------------| artist_name | place_name |================================================================================================================| "#2 Orchestra"^^<http://www.w3.org/2001/XMLSchema#string> | "Republic of France" || "#Blockout"^^<http://www.w3.org/2001/XMLSchema#string> | "Département des Yvelines" || "#Dance 75#"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "#NarNaoud#"^^<http://www.w3.org/2001/XMLSchema#string> | "Département de la Gironde" || "#ZedMeta#"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "#Zorglups#"^^<http://www.w3.org/2001/XMLSchema#string> | "Département de l'Essonne" || "&ND"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "(own+line)"^^<http://www.w3.org/2001/XMLSchema#string> | "Republic of France" || "* Q u i r y *"^^<http://www.w3.org/2001/XMLSchema#string> | "Paris" || "-=Kwada=-"^^<http://www.w3.org/2001/XMLSchema#string> | "Département de la Haute-Garonne" || "-DEMO-"^^<http://www.w3.org/2001/XMLSchema#string> | "Département du Nord" |

Page 106: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist_name ?place_nameFROM <../data/jamendo-rdf/jamendo.nt>FROM NAMED <../data/in_france.nt>WHERE { ! ?artist a mo:MusicArtist ; ! ! foaf:based_near ?place ; ! ! foaf:name ?artist_name .! GRAPH <../data/in_france.nt> {! ! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! ! geonames:name ?place_name .! }}ORDER BY ?artist_name

One more thing...

Page 107: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist_name ?place_nameFROM <../data/jamendo-rdf/jamendo.nt>FROM NAMED <../data/in_france.nt>WHERE { ! ?artist a mo:MusicArtist ; ! ! foaf:based_near ?place ; ! ! foaf:name ?artist_name .! GRAPH <../data/in_france.nt> {! ! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! ! geonames:name ?place_name .! }}ORDER BY ?artist_name

One more thing...

Page 108: SPARQL - Basic and Federated Queries

PREFIX foaf: ! ! <http://xmlns.com/foaf/0.1/>PREFIX geonames: ! <http://www.geonames.org/ontology#>PREFIX mo: ! ! <http://purl.org/ontology/mo/>

SELECT DISTINCT ?artist_name ?place_nameFROM <../data/jamendo-rdf/jamendo.nt>FROM NAMED <../data/in_france.nt>WHERE { ! ?artist a mo:MusicArtist ; ! ! foaf:based_near ?place ; ! ! foaf:name ?artist_name .! GRAPH <../data/in_france.nt> {! ! ?place geonames:parentCountry <http://sws.geonames.org/3017382/> ;! ! ! geonames:name ?place_name .! }}ORDER BY ?artist_name

One more thing...

Page 109: SPARQL - Basic and Federated Queries
Page 110: SPARQL - Basic and Federated Queries
Page 111: SPARQL - Basic and Federated Queries

PREFIX swrc: <http://swrc.ontoware.org/ontology#>PREFIX org: <http://data.semanticweb.org/organization/>

SELECT ?affiliation ?conference_graphWHERE {! SERVICE <http://data.semanticweb.org/sparql> {! ! GRAPH ?conference_graph {! ! ! <http://data.semanticweb.org/person/richard-cyganiak> swrc:affiliation ?affiliation .! ! }! }}

One last thing...

Page 112: SPARQL - Basic and Federated Queries

PREFIX swrc: <http://swrc.ontoware.org/ontology#>PREFIX org: <http://data.semanticweb.org/organization/>

SELECT ?affiliation ?conference_graphWHERE {! SERVICE <http://data.semanticweb.org/sparql> {! ! GRAPH ?conference_graph {! ! ! <http://data.semanticweb.org/person/richard-cyganiak> swrc:affiliation ?affiliation .! ! }! }}

One last thing...

Page 113: SPARQL - Basic and Federated Queries

PREFIX swrc: <http://swrc.ontoware.org/ontology#>PREFIX org: <http://data.semanticweb.org/organization/>

SELECT ?affiliation ?conference_graphWHERE {! SERVICE <http://data.semanticweb.org/sparql> {! ! GRAPH ?conference_graph {! ! ! <http://data.semanticweb.org/person/richard-cyganiak> swrc:affiliation ?affiliation .! ! }! }}

One last thing...

---------------------------------------------------------------------------------------------------------| affiliation | conference_graph |=========================================================================================================| org:freie-universitaet-berlin | <http://data.semanticweb.org/conference/iswc-aswc/2007/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/eswc/2008/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/iswc/2008/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/iswc/2009/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/eswc/2010/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/isemantics/2009/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/eswc/2011/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/ruleml-eu/2011/complete> || org:freie-universitaet-berlin | <http://data.semanticweb.org/conference/ruleml-eu/2011/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/iswc/2011/complete> || org:deri-nui-galway | <http://data.semanticweb.org/workshop/cold/2011/complete> || org:deri-nui-galway | <http://data.semanticweb.org/workshop/sdow/2011/complete> || org:deri-nui-galway | <http://data.semanticweb.org/conference/www/2012/complete> || org:deri-nui-galway | <http://data.semanticweb.org/workshop/ldow/2012/complete> |---------------------------------------------------------------------------------------------------------

Page 114: SPARQL - Basic and Federated Queries

Now you try it!Run queries from within

/Datasets/Hands On Session I