linked data, rdf & sparql

79
http://creativecommons.org/licenses/by/2.0/uk/ Linked Data, RDF & SPARQL Rob Styles Senior Technical Consultant

Upload: mmmmmrob

Post on 11-May-2015

3.689 views

Category:

Technology


3 download

DESCRIPTION

A 50 minute introduction to RDF, Linked Data and SPARQL.

TRANSCRIPT

Page 1: Linked Data, Rdf & Sparql

http://creativecommons.org/licenses/by/2.0/uk/

Linked Data, RDF & SPARQLRob StylesSenior Technical Consultant

Page 2: Linked Data, Rdf & Sparql

Tim Berners Lee on Linked Data at TED, By PhOtOnQuAnTiQuE, CC-BY-NC-SA on Flickr, http://www.flickr.com/photos/photonquantique/3272712288/

Page 3: Linked Data, Rdf & Sparql
Page 4: Linked Data, Rdf & Sparql

Linked Data

1. Use URIs as names for things

2. Use HTTP URIs so that people can look up those names.

3. When someone looks up a URI, provide useful information, using the standards (RDF*, SPARQL)

4. Include links to other URIs. so that they can discover more things.

Sir Tim Berners-Lee, http://www.w3.org/DesignIssues/LinkedData

Page 5: Linked Data, Rdf & Sparql

What isLinked Data?

Page 6: Linked Data, Rdf & Sparql

What isThe Web of Documents?

Page 7: Linked Data, Rdf & Sparql

The Web of Documents

A global network of linked documents

A place where anyone can say anything about anything

A vast collection of human-readable knowledge (and opinion)

Documents are linked, but links are not qualified

Page 8: Linked Data, Rdf & Sparql

Linked Data

1. Use URIs as names for things

2. Use HTTP URIs so that people can look up those names.

3. When someone looks up a URI, provide useful information, using the standards (RDF*, SPARQL)

4. Include links to other URIs. so that they can discover more things.

Sir Tim Berners-Lee, http://www.w3.org/DesignIssues/LinkedData

Page 9: Linked Data, Rdf & Sparql

The Web of Documents

A global network of linked documents

A place where anyone can say anything about anything

A vast collection of human-readable knowledge (and opinion)

Documents are linked, but links are not qualified

Page 10: Linked Data, Rdf & Sparql

The Web of Data

A global network of linked statements

A place where anyone can say anything about anything

A vast collection of machine-readable knowledge (and opinion)

Statements are linked, and links are qualified

Page 11: Linked Data, Rdf & Sparql
Page 12: Linked Data, Rdf & Sparql
Page 13: Linked Data, Rdf & Sparql
Page 14: Linked Data, Rdf & Sparql
Page 15: Linked Data, Rdf & Sparql
Page 16: Linked Data, Rdf & Sparql
Page 17: Linked Data, Rdf & Sparql

What is RDF?

Page 18: Linked Data, Rdf & Sparql

RDF is ...

Resource Description Frameworkhttp://www.w3.org/RDF/

A simple, powerful, data model

Used to define relationships between things

Designed to work with the architecture of the web

The data model for the Web of Data

Page 19: Linked Data, Rdf & Sparql

Allow anyoneto say anythingabout anything

Page 20: Linked Data, Rdf & Sparql
Page 23: Linked Data, Rdf & Sparql

Resources...

Represent things on the web, like web pages

Represent things not on the web, like people and places

Can represent anything at all

Named using URIs (usually)

Page 24: Linked Data, Rdf & Sparql

Values...

Values can be ‘literal’ values or other resources

Literal values are to work with and show users

Literal values can have specific types (numbers, dates) and language codes (en-gb, cy-gb)

Other resources are URIs to follow and find more data

Page 25: Linked Data, Rdf & Sparql

Properties are...

The relationship between Resources

Named using URIs

Described in Schema(or vocabularies, or ontologies)

Page 27: Linked Data, Rdf & Sparql

Apollo 11 Command and Service Module Cape Canaveral Cape Canaveral,

United States namelaunchsite

Page 28: Linked Data, Rdf & Sparql

Apollo 11 Command and Service Module Cape Canaveral Cape Canaveral,

United States namelaunchsite

Subject Property Value

Page 29: Linked Data, Rdf & Sparql

Apollo 11 Command and Service Module Cape Canaveral Cape Canaveral,

United States namelaunchsite

Subject Property Value

Subject Property Value

Page 30: Linked Data, Rdf & Sparql

Apollo 11 Command and Service Module Cape Canaveral Cape Canaveral,

United States namelaunchsite

Subject Property Value

Subject Property Value

Statement or Triple

Page 31: Linked Data, Rdf & Sparql

Apollo 11 Command and Service Module Cape Canaveral Cape Canaveral,

United States namelaunchsite

Subject Property Value

Subject Property Value

Statement or Triple

Statement or Triple

Page 32: Linked Data, Rdf & Sparql

Simple Rules for Merging

URIs name the resources we are describing

Two people using the same URI are describing the same thing

The same URI in two datasets becomes one URI with all of the properties from both datasets

RDF data can use URIs from many different websites

Page 35: Linked Data, Rdf & Sparql

Simple Rules for Merging

Graphs from several different sources can be merged

Resources with the same URI are considered identical

No limitations on which graphs can be merged

Page 36: Linked Data, Rdf & Sparql

Any RDF can be merged with any other

RDF

Page 37: Linked Data, Rdf & Sparql

RDF...

is a Graph data modelXML is a tree data modelRDBMS is a table data model

can be easily distributed

can be easily merged

allows anyone say anything about anything

is not newthe spec is from 1999the idea stems back to the late 1960s

Page 38: Linked Data, Rdf & Sparql

What does RDF look like?

Page 39: Linked Data, Rdf & Sparql

Writing RDF

TurtleWhat I’m about to show you

N-TriplesOne statement per line, subset of Turtle, grep compatible

RDF/JSONUseful for AJAX Applications and anything with else JSON support

RDFaWriting RDF within HTML pages

RDF/XMLMachine to Machine TransferDe-facto Standard

Page 40: Linked Data, Rdf & Sparql

Turtle (TTL) stands for Terse Triple Language

Page 41: Linked Data, Rdf & Sparql

Turtle

Terse Triple Language (TTL)http://www.w3.org/2007/02/turtle/primer/

A human-readable notation for RDF

Provides useful syntax for quickly hand-writing RDF

Forms the basis of patterns in SPARQL

Page 43: Linked Data, Rdf & Sparql

http://.../1969-059A

http://.../Spacecraft

a

Apollo 11 Command and Service Modulename

16 July 1969launched

28801.0mass

<http://example.com/spacecraft/1969-059A>

a space:Spacecraft ;

space:name "Apollo 11 Command and Service Module" ;

space:launched "1969-07-16"^^xsd:date ;

@prefix space: <http://example.com/space-schema/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

space:mass 28801.0 .

Page 45: Linked Data, Rdf & Sparql

http://.../1969-059A

http://.../Spacecraft

a

Apollo 11 Command and Service Modulename

16 July 1969launched

28801.0mass

http://.../cape+cana...

Cape Canaveral, United States name

launchsite

<http://example.com/spacecraft/1969-059A>

a space:Spacecraft ;

space:name "Apollo 11 Command and Service Module" ;

space:launched "1969-07-16"^^xsd:date ;

@prefix space: <http://example.com/space-schema/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

space:launchsite <http://.../cape+cana...> .

space:mass 28801.0 . space:mass 28801.0 ;

Page 46: Linked Data, Rdf & Sparql

http://.../1969-059A

http://.../Spacecraft

a

Apollo 11 Command and Service Modulename

16 July 1969launched

28801.0mass

http://.../cape+cana...

Cape Canaveral, United States name

launchsite

<http://example.com/spacecraft/1969-059A>

a space:Spacecraft ;

space:name "Apollo 11 Command and Service Module" ;

space:launched "1969-07-16"^^xsd:date ;

@prefix space: <http://example.com/space-schema/> .@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://.../cape+cana...> space:name "Cape Canaveral, United States"@en-us .

space:launchsite <http://.../cape+cana...> .

space:mass 28801.0 . space:mass 28801.0 ;

Page 47: Linked Data, Rdf & Sparql

How do I SPARQL?

Page 48: Linked Data, Rdf & Sparql

SPARQL

Query Language for RDFhttp://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

Page 49: Linked Data, Rdf & 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

Page 50: Linked Data, Rdf & Sparql

Triple Patterns

Page 51: Linked Data, Rdf & Sparql

Triple Patterns

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

Page 52: Linked Data, Rdf & Sparql

Triple Patterns

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

?something foaf:name "Sputnik 1" .

Page 53: Linked Data, Rdf & Sparql

Triple Patterns

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

?something foaf:name "Sputnik 1" .

?something foaf:name ?name .

Page 54: Linked Data, Rdf & Sparql

Triple Patterns

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

?something foaf:name "Sputnik 1" .

?something foaf:name ?name .

SELECT ?name WHERE { ?something foaf:name ?name .}

Page 55: Linked Data, Rdf & 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

Page 56: Linked Data, Rdf & Sparql

Triple Patterns

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

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

Page 57: Linked Data, Rdf & 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

Page 58: Linked Data, Rdf & 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

Page 59: Linked Data, Rdf & 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#>

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

Page 60: Linked Data, Rdf & 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

Page 61: Linked Data, Rdf & 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

Page 62: Linked Data, Rdf & Sparql

Triple Patterns

PREFIX space: <http://purl.org/net/schemas/space/>

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

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

Page 63: Linked Data, Rdf & 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

Page 64: Linked Data, Rdf & 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

Page 65: Linked Data, Rdf & 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

Page 66: Linked Data, Rdf & 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

Page 67: Linked Data, Rdf & 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 .

}

Page 68: Linked Data, Rdf & 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>

Page 69: Linked Data, Rdf & 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 .

}

Page 70: Linked Data, Rdf & 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

Page 71: Linked Data, Rdf & Sparql

Example QueryPREFIX 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 ?mass WHERE{ ?launch space:launched ?date ; space:spacecraft ?spacecraft .

?spacecraft foaf:name ?name ; space:mass ?mass .

FILTER ( ?date >= "1965-01-01"^^xsd:date && ?date <= "1975-12-31"^^xsd:date )}ORDER BY DESC(?mass)LIMIT 10OFFSET 10

Page 72: Linked Data, Rdf & Sparql

Tip 1: Find all the Properties

SELECT DISTINCT ?p WHERE {

?s ?p ?o .

}

Page 73: Linked Data, Rdf & 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

Page 74: Linked Data, Rdf & 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

Page 75: Linked Data, Rdf & Sparql

Tip 2: Find all the Classes

SELECT DISTINCT ?type WHERE {

?s a ?type .

}

Page 76: Linked Data, Rdf & 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

Page 77: Linked Data, Rdf & 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

Page 78: Linked Data, Rdf & Sparql

This work is Copyright © 2010 Talis Systems Limited.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.

Page 79: Linked Data, Rdf & Sparql