60
An Introduction to Linked Data David Hyland-Wood University of Mary Washington Part 4 of 5 SPARQL Query Language Monday, May 16, 2011

Intro to Linked Data: SPARQL

Embed Size (px)

Citation preview

Page 1: Intro to Linked Data: SPARQL

An Introduction

toLinked Data

David Hyland-WoodUniversity of Mary Washington

Part 4 of 5SPARQL Query Language

Monday, May 16, 2011

Page 2: Intro to Linked Data: SPARQL

SPARQL:A query

language for RDFMonday, May 16, 2011

Page 3: Intro to Linked Data: SPARQL

SPARQL• Query Language for RDF

http://www.w3.org/TR/rdf-sparql-query

• SPARQL Protocol and RDF Query Language

• Graph pattern based languagewritten the same as Turtle

• Several queries — Ask; Select; Describe; Construct

• Read Onlystill vulnerable to injection, though not as bad as SQL

Monday, May 16, 2011

Page 4: Intro to Linked Data: SPARQL

Queries• ASK — True or False

Simple, Fast

• SELECT — Tabular dataeasy to work with

• DESCRIBE — RDFwhatever the store has

• CONSTRUCT — RDFWhatever you want

Monday, May 16, 2011

Page 5: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 6: Intro to Linked Data: SPARQL

Triple Patterns

Monday, May 16, 2011

Page 7: Intro to Linked Data: SPARQL

Triple Patterns

<http://example.com/spacecraft/1957-001B> foaf:name "Sputnik 1" .

Monday, May 16, 2011

Page 8: Intro to Linked Data: SPARQL

Triple Patterns

<http://example.com/spacecraft/1957-001B> foaf:name "Sputnik 1" .

?something foaf:name "Sputnik 1" .

Monday, May 16, 2011

Page 9: Intro to Linked Data: SPARQL

Triple Patterns

<http://example.com/spacecraft/1957-001B> foaf:name "Sputnik 1" .

?something foaf:name "Sputnik 1" .

?something foaf:name ?name .

Monday, May 16, 2011

Page 10: Intro to Linked Data: SPARQL

Triple Patterns

<http://example.com/spacecraft/1957-001B> foaf:name "Sputnik 1" .

?something foaf:name "Sputnik 1" .

?something foaf:name ?name .

ASK WHERE { ?something foaf:name "Sputnik 1" .}

Monday, May 16, 2011

Page 11: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 12: Intro to Linked Data: SPARQL

Triple Patterns

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

ASK WHERE { ?something rdfs:label ?label .}

Monday, May 16, 2011

Page 13: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 14: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 15: Intro to Linked Data: SPARQL

Triple Patterns

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

ASK WHERE { ?something rdfs:label ?label ; rdf:type space:Discipline .}

Monday, May 16, 2011

Page 16: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 17: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 18: Intro to Linked Data: SPARQL

Triple Patterns

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>

ASK WHERE { ?spacecraft foaf:name “Sputnik 1” . ?launch space:spacecraft ?spacecraft . ?launch space:launched ?launchdate .}

Monday, May 16, 2011

Page 19: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 20: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 21: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 22: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 23: Intro to Linked Data: SPARQL

Example SELECT

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?subject ?label WHERE {

?subject rdfs:label ?label ; a space:Discipline .

}

Monday, May 16, 2011

Page 24: Intro to Linked Data: SPARQL

Example SELECT<sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="subject"/> <variable name="label"/> </head> <results> <result> <binding name="subject"> <uri>http://nasa.dataincubator.org/discipline/astronomy</uri> </binding> <binding name="label"> <literal>Astronomy</literal> </binding> </result> <result> <binding name="subject"> <uri>http://nasa.dataincubator.org/discipline/communications</uri> </binding> <binding name="label"> <literal>Communications</literal> </binding> </result>

Monday, May 16, 2011

Page 25: Intro to Linked Data: SPARQL

Example SELECT

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT * WHERE {

?subject rdfs:label ?label ; a space:Discipline .

}

Monday, May 16, 2011

Page 26: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 27: Intro to Linked Data: SPARQL

Example SELECT DISTINCT

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?date WHERE {

?launch space:launched ?date .

}

Monday, May 16, 2011

Page 28: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 29: Intro to Linked Data: SPARQL

Example OPTIONAL

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?name ?image WHERE {

?spacecraft foaf:name ?name .

OPTIONAL { ?spacecraft foaf:depiction ?image . }}

Monday, May 16, 2011

Page 30: Intro to Linked Data: SPARQL

Example OPTIONAL<?xml version="1.0"?><sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="name"/> <variable name="image"/> </head> <results> <result> <binding name="name"> <literal>Soyuz 2</literal> </binding> </result> <result> <binding name="name"> <literal>Apollo 10</literal> </binding> <binding name="image"> <uri>http://nssdc.gsfc.nasa.gov/image/spacecraft/apollo_10_cm.jpg</uri> </binding> </result>

Monday, May 16, 2011

Page 31: Intro to Linked Data: SPARQL

Example UNION

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?subject ?displayLabel WHERE { { ?subject foaf:name ?displayLabel . } UNION { ?subject rdfs:label ?displayLabel . }}

Monday, May 16, 2011

Page 32: Intro to Linked Data: SPARQL

Example UNION<?xml version="1.0"?><sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="subject"/> <variable name="displayLabel"/> </head> <results> <result> <binding name="subject"> <uri>http://nasa.dataincubator.org/spacecraft/ATLAS2</uri> </binding> <binding name="displayLabel"> <literal>Atlas 2</literal> </binding> </result> <result> <binding name="subject"> <uri>http://nasa.dataincubator.org/spacecraft/ATLAS3</uri> </binding> <binding name="displayLabel"> <literal>Atlas 3</literal> </binding> </result>

Monday, May 16, 2011

Page 33: Intro to Linked Data: SPARQL

Example ORDER BY

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?name ?launchdate WHERE { ?spacecraft foaf:name ?name . ?launch space:spacecraft ?spacecraft . ?launch space:launched ?launchdate .}

Monday, May 16, 2011

Page 34: Intro to Linked Data: SPARQL

Example ORDER BY

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?name ?launchdate WHERE { ?spacecraft foaf:name ?name . ?launch space:spacecraft ?spacecraft . ?launch space:launched ?launchdate .}ORDER BY DESC(?launchdate)

Monday, May 16, 2011

Page 35: Intro to Linked Data: SPARQL

Example ORDER BY

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?name ?launchdate WHERE { ?spacecraft foaf:name ?name . ?launch space:spacecraft ?spacecraft . ?launch space:launched ?launchdate .}ORDER BY DESC(?launchdate)LIMIT 10

Monday, May 16, 2011

Page 36: Intro to Linked Data: SPARQL

Example ORDER BY

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?name ?launchdate WHERE { ?spacecraft foaf:name ?name . ?launch space:spacecraft ?spacecraft . ?launch space:launched ?launchdate .}ORDER BY DESC(?launchdate)LIMIT 10OFFSET 10

Monday, May 16, 2011

Page 37: Intro to Linked Data: SPARQL

Example FILTER

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?name WHERE { ?launch space:launched ?date ; space:spacecraft ?spacecraft . ?spacecraft foaf:name ?name .

FILTER ( ?date >= "1969-01-01"^^xsd:date && ?date <= "1969-12-31"^^xsd:date )}

Monday, May 16, 2011

Page 38: Intro to Linked Data: SPARQL

Example FILTER

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?spacecraft ?name WHERE { ?spacecraft foaf:name ?name ; space:mass ?mass . FILTER( xsd:double(?mass) < 90.0 )}

Monday, May 16, 2011

Page 39: Intro to Linked Data: SPARQL

Example FILTER

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?name WHERE {

?spacecraft foaf:name ?name . FILTER( regex(?name, “ollo”, “i” ) )}

Monday, May 16, 2011

Page 40: Intro to Linked Data: SPARQL

Built-in Filters• Logical (!, &&, ||)

• Math (+, -, *, /)

• Comparison (=, !=, >, <, ...)

• TestsisURI, isBlank, isLiteral, bound, sameTerm, langMatches, regex

• Accessorsstr, lang, datatype

Monday, May 16, 2011

Page 41: Intro to Linked Data: SPARQL

Example NOT

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?s WHERE {

?s a space:Spacecraft .

OPTIONAL { ?s foaf:depiction ?image . }

FILTER ( !bound(?image) )}

Monday, May 16, 2011

Page 42: Intro to Linked Data: SPARQL

Queries• ASK — True or False

Simple, Fast

• SELECT — Tabular dataeasy to work with

• DESCRIBE — RDFwhatever the store has

• CONSTRUCT — RDFWhatever you want

Monday, May 16, 2011

Page 43: Intro to Linked Data: SPARQL

Example DESCRIBE

DESCRIBE <http://example.com/launch/1969-059>

Monday, May 16, 2011

Page 44: Intro to Linked Data: SPARQL

Example DESCRIBE<rdf:RDF xmlns:space="http://purl.org/net/schemas/space/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >

<rdf:Description rdf:about="http://nasa.dataincubator.org/launch/1969-059"> <space:spacecraft rdf:resource="http://nasa.dataincubator.org/spacecraft/1969-059C"/> <space:spacecraft rdf:resource="http://nasa.dataincubator.org/spacecraft/1969-059B"/> <space:spacecraft rdf:resource="http://nasa.dataincubator.org/spacecraft/1969-059A"/> <space:launchvehicle>Saturn 5</space:launchvehicle> <space:launchsite rdf:resource="http://nasa.dataincubator.org/launchsite/capecana..."/> <space:launched rdf:datatype="http://www.w3.org/2001/XMLSchema#date"> 1969-07-16 </space:launched> <rdf:type rdf:resource="http://purl.org/net/schemas/space/Launch"/> </rdf:Description> </rdf:RDF>

Monday, May 16, 2011

Page 45: Intro to Linked Data: SPARQL

Example DESCRIBE

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

DESCRIBE ?spacecraft WHERE {

?launch space:launched "1969-07-16"^^xsd:date . ?spacecraft space:launch ?launch .

}

Monday, May 16, 2011

Page 46: Intro to Linked Data: SPARQL

Example DESCRIBE<rdf:RDF xmlns:space="http://purl.org/net/schemas/space/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" > <rdf:Description rdf:about="http://nasa.dataincubator.org/spacecraft/1969-059B"> <foaf:homepage rdf:resource="http://nssdc.gsfc.nasa.gov/database/MasterCatalog?sc=1969-059B"/> <dc:description>The...</dc:description> <space:mission rdf:resource="http://nasa.dataincubator.org/mission/apollo-11"/> <space:agency>United States</space:agency> <rdf:type rdf:resource="http://purl.org/net/schemas/space/Spacecraft"/> <space:launch rdf:resource="http://nasa.dataincubator.org/launch/1969-059"/> <space:discipline rdf:resource="http://nasa.dataincubator.org/discipline/planetaryscience"/> <space:alternateName>04040</space:alternateName> <space:alternateName>Apollo 11 Saturn V third stage</space:alternateName> <foaf:name>Apollo 11 SIVB</foaf:name> <space:internationalDesignator>1969-059B</space:internationalDesignator> <space:mass>13300.0</space:mass> </rdf:Description> ...

Monday, May 16, 2011

Page 47: Intro to Linked Data: SPARQL

Example DESCRIBE

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

DESCRIBE ?spacecraft ?launch WHERE {

?launch space:launched "1969-07-16"^^xsd:date . ?spacecraft space:launch ?launch .

}

Monday, May 16, 2011

Page 48: Intro to Linked Data: SPARQL

Example CONSTRUCT

PREFIX space: <http://purl.org/net/schemas/space/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX foaf: <http://xmlns.com/foaf/0.1/>

CONSTRUCT { ?spacecraft foaf:name ?name ; space:agency ?agency ; space:launched ?launchdate . }WHERE { ?spacecraft foaf:name ?name ; space:agency ?agency . ?launch space:spacecraft ?spacecraft . ?launch space:launched ?launchdate .}

Monday, May 16, 2011

Page 49: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 50: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 51: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

space:launched

Monday, May 16, 2011

Page 52: Intro to Linked Data: SPARQL

Common Problems• Typos

wrong case for property or class name

• wrong prefix URImissing # or / or the URI for the web page

• Missing OPTIONALyou won't even notice...

• Comparing LiteralsLiterals are compared on all of value, type and language

Monday, May 16, 2011

Page 53: Intro to Linked Data: SPARQL

Tip 1: Find all the Properties

SELECT DISTINCT ?p WHERE {

?s ?p ?o .

}

Monday, May 16, 2011

Page 54: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 55: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 56: Intro to Linked Data: SPARQL

Tip 2: Find all the Classes

SELECT DISTINCT ?type WHERE {

?s a ?type .

}

Monday, May 16, 2011

Page 57: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 58: Intro to Linked Data: SPARQL

Space Physicsspace:Discipline

space:Spacecraft

space:Launch

space:Launchsite

/discipline/spacephysics

/spacecraft/1957-001B

/launch/1957-001

/launchsite/tyurata

a

a

a

a

space:discipline

space:spacecraft

space:launchsite

Sputnik 1

The Sputnik 1 spacecraft was ...

U.S.S.R

86.3

1957-10-04

Modified SS-6 (Sapwood)

Tyuratam (Baikonur Cosmodrome)

U.S.S.R

rdfs:label

space:country

foaf:name

dc:description

space:agency

space:mass

space:launched

space:launchvehicle

rdfs:label

/images/sputnik.jpgfoaf:depiction

Monday, May 16, 2011

Page 59: Intro to Linked Data: SPARQL

Thanks to

• Rob Styles, Talis Group Ltd for his CC-BY licensed “Two Day Introduction to the Web of Data” slides and spacecraft example data.

Monday, May 16, 2011

Page 60: Intro to Linked Data: SPARQL

This work is Copyright © 2010 David Hyland-WoodBased partially on CC-BY licensed content Copyright © 2010 Talis Systems Limited by Rob Styles. It is licensed under the Creative Commons Attribution 3.0 Unported License.Full details at: http://creativecommons.org/licenses/by/3.0/

You are free:

to Share — to copy, distribute and transmit the work

to Remix — to adapt the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

• For any reuse or distribution, you must make clear to others the license terms of this work.• Any of the above conditions can be waived if you get permission from the copyright holder.• Nothing in this license impairs or restricts the author's moral rights.• Some Content in the work may be licensed under different terms, this is noted separately.

Monday, May 16, 2011