Semantic Web Data/RDF/SPARQL - University of...

155
Semantic Web Data/RDF/SPARQL 1

Transcript of Semantic Web Data/RDF/SPARQL - University of...

Page 1: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantic Web Data/RDF/SPARQL

1

Page 2: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Relational Semantic Web

Tables

SQL

2

Page 3: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Relational Semantic Web

Tables RDF Graphs

SQL

2

Page 4: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Relational Semantic Web

Tables RDF Graphs

SQL SPARQL

2

Page 5: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Relational Semantic Web

Tables RDF Graphs

SQL SPARQL

Closed Data

(inside an organization)

2

Page 6: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Relational Semantic Web

Tables RDF Graphs

SQL SPARQL

Closed Data Open Data

(inside an organization) (available on the Web)

2

Page 7: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantic Web

“The Semantic Web is an extension of the current web in whichinformation is given well-defined meaning, better enablingcomputers and people to work in cooperation.”

[Tim Berners-Lee et al. 2001.]

Specific Goals:

Build a description language with standard semantics

Make semantics machine-processable and understandable

Incorporate logical infrastructure to reason about resources

W3C Proposal: Resource Description Framework (RDF)

3

Page 8: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

RDF in a nutshell

RDF is the W3C proposal framework for representinginformation in the Web

Abstract syntax based on directed labeled graph

Schema definition language (RDFS): Define new vocabulary(typing, inheritance of classes and properties)

Extensible URI-based vocabulary

Formal semantics

4

Page 9: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

RDF formal model

Subject ObjectPredicate

LB

U

U UB

U = set of Uris

B = set of Blank nodes

L = set of Literals

5

Page 10: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

RDF formal model

Subject ObjectPredicate

LB

U

U UB

U = set of Uris

B = set of Blank nodes

L = set of Literals

(s, p, o) ∈ (U ∪ B) × U × (U ∪ B ∪ L) is called an RDF triple

5

Page 11: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

RDF formal model

Subject ObjectPredicate

LB

U

U UB

U = set of Uris

B = set of Blank nodes

L = set of Literals

(s, p, o) ∈ (U ∪ B) × U × (U ∪ B ∪ L) is called an RDF triple

A set of RDF triples is called an RDF graph

5

Page 12: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

An example of an RDF graph: DBLP

inPods:FaginLN01 :Moni Naor

:Amnon Lotem

:Ronald Fagin

inPods:2001

"Optimal Aggregation ..."

dc:creatordc:creator

dc:cre

ator

dct:PartOf

dc:titleswrc:series

conf:pods

<http://purl.org/dc/terms/>

: <http://dblp.l3s.de/d2r/resource/authors/>

conf: <http://dblp.l3s.de/d2r/resource/conferences/>

inPods: <http://dblp.l3s.de/d2r/resource/publications/conf/pods/>

swrc: <http://swrc.ontoware.org/ontology#>

dc:

dct:

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

6

Page 13: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

An example of a URI

http://dblp.l3s.de/d2r/resource/conferences/pods

7

Page 14: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

URI can be used for any abstract resource

http://dblp.l3s.de/d2r/page/authors/Ronald Fagin

8

Page 15: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

RDF: Another example

country

works in

rdf:sp

person

sportman

soccer player

rdf:sc

rdf:sc

rdf:dom

rdf:dom rdf:range

rdf:range

Barcelona

plays in

plays in

soccer team

company

rdf:typerdf:type

rdf:sc

Messi

Spain:b

addresslives in

9

Page 16: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Some peculiarities of the RDF data model

Existential variables as datavalues (null values)

Built-in vocabulary with fixed semantics (RDFS)

Graph model where nodes may also be edge labels

10

Page 17: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Previous example: A better representation

Messi

works in

rdf:sp

person

sportman

soccer player

rdf:sc

rdf:sc

rdf:dom

rdf:dom rdf:range

rdf:range

Barcelona

plays in soccer team

company

rdf:typerdf:type

rdf:sc

Spain:b

lives in

country

address

works inperson

sportman

rdf:sc

rdf:dom rdf:rangecompany

11

Page 18: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

RDF + RDFS

RDFS extends RDF with a schema vocabulary: subPropertyOf(rdf:sp), subClassOf (rdf:sc), domain (rdf:dom), range(rdf:range), type (rdf:type).

plus semantics for this vocabulary

12

Page 19: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

RDFS: Messi is a Person

lives in

works in

rdf:sp

person

sportman

soccer player

rdf:sc

rdf:sc

rdf:dom

rdf:dom rdf:range

rdf:range

Barcelona

plays in soccer team

company

rdf:typerdf:type

rdf:sc

Messi

Spain

13

Page 20: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of RDFS

Checking whether a triple t is in a graph G is the basic step whenreasoning about RDF(S).

For the case of RDFS, we need to check whether t is implied by G

14

Page 21: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of RDFS

Checking whether a triple t is in a graph G is the basic step whenreasoning about RDF(S).

For the case of RDFS, we need to check whether t is implied by G

The notion of entailment in RDFS can be defined in terms ofclassical notions such as model, interpretation, etc.

As for the case of first-order logic

14

Page 22: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of RDFS

Checking whether a triple t is in a graph G is the basic step whenreasoning about RDF(S).

For the case of RDFS, we need to check whether t is implied by G

The notion of entailment in RDFS can be defined in terms ofclassical notions such as model, interpretation, etc.

As for the case of first-order logic

This notion can also be characterized by a set of inference rules.

14

Page 23: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of RDFS

Checking whether a triple t is in a graph G is the basic step whenreasoning about RDF(S).

For the case of RDFS, we need to check whether t is implied by G

The notion of entailment in RDFS can be defined in terms ofclassical notions such as model, interpretation, etc.

As for the case of first-order logic

This notion can also be characterized by a set of inference rules.

The closure of an RDFS graph G (cl(G )) is the graph obtained byadding to G all the triples that are implied by G .

A basic property of the closure:

G implies t iff t ∈ cl(G )

14

Page 24: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example: (Messi, rdf:type, person) over the closure

Messi

works in

rdf:sp

person

sportman

soccer player

rdf:sc

rdf:sc

rdf:dom

rdf:dom rdf:range

rdf:range

Barcelona

plays in soccer team

company

rdf:typerdf:type

rdf:sc

rdf:type

rdf:sc

rdf:type

Spain

lives in

15

Page 25: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Does the blank node add some information?

country

works in

rdf:sp

person

sportman

soccer player

rdf:sc

rdf:sc

rdf:dom

rdf:dom rdf:range

rdf:range

Barcelona

plays in soccer team

company

rdf:typerdf:type

rdf:sc

Messi

Spain:b

addresslives in

16

Page 26: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

What about now?

lives in

works in

rdf:sp

person

sportman

soccer player

rdf:sc

rdf:sc

rdf:dom

rdf:dom rdf:range

rdf:range

Barcelona

plays in soccer team

company

rdf:typerdf:type

rdf:sc

Messi

Spain:b

lives in

17

Page 27: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL

18

Page 28: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Querying RDF: SPARQL

SPARQL is the W3C recommendation query language forRDF (January 2008).

SPARQL is a recursive acronym that stands for SPARQL

Protocol and RDF Query Language

SPARQL is a graph-matching query language.

A SPARQL query consists of three parts:

Pattern matching: optional, union, filtering, . . . Solution modifiers: projection, distinct, order, limit, offset, . . . Output part: construction of new triples, . . ..

19

Page 29: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

21

Page 30: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

21

Page 31: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

WHERE

21

Page 32: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

21

Page 33: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

21

Page 34: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:pods .

21

Page 35: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:pods .

A SPARQL query consists of a:

21

Page 36: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:pods .

A SPARQL query consists of a:

Head: Processing of the variables

21

Page 37: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:pods .

A SPARQL query consists of a:

Head: Processing of the variables

Body: Pattern matching expression

21

Page 38: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS, and their Webpages if this information is available:

SELECT ?Author ?WebPage

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:pods .

OPTIONAL

?Author foaf:homePage ?WebPage .

23

Page 39: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: A Simple RDF Query Language

Example: Authors that have published in PODS, and their Webpages if this information is available:

SELECT ?Author ?WebPage

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:pods .

OPTIONAL

?Author foaf:homePage ?WebPage .

23

Page 40: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

SELECT ?X1 ?X2 ...

P1 .

P2

25

Page 41: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping SELECT ?X1 ?X2 ...

P1 .

P2

P3 .

P4

25

Page 42: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping

Optional parts

SELECT ?X1 ?X2 ...

P1 .

P2

OPTIONAL P5

P3 .

P4

OPTIONAL P7

25

Page 43: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping

Optional parts

Nesting

SELECT ?X1 ?X2 ...

P1 .

P2

OPTIONAL P5

P3 .

P4

OPTIONAL P7

OPTIONAL P8

25

Page 44: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping

Optional parts

Nesting

Union of patterns

SELECT ?X1 ?X2 ...

P1 .

P2

OPTIONAL P5

P3 .

P4

OPTIONAL P7

OPTIONAL P8

UNION

P9

25

Page 45: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping

Optional parts

Nesting

Union of patterns

Filtering

SELECT ?X1 ?X2 ...

P1 .

P2

OPTIONAL P5

P3 .

P4

OPTIONAL P7

OPTIONAL P8

UNION

P9

FILTER ( R )

25

Page 46: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping

Optional parts

Nesting

Union of patterns

Filtering

...

+ several new features in thenew version (March 2013):navigation, entailment regimes,federation, . . .

SELECT ?X1 ?X2 ...

P1 .

P2

OPTIONAL P5

P3 .

P4

OPTIONAL P7

OPTIONAL P8

UNION

P9

FILTER ( R )

25

Page 47: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping

Optional parts

Nesting

Union of patterns

Filtering

...

+ several new features in thenew version (March 2013):navigation, entailment regimes,federation, . . .

SELECT ?X1 ?X2 ...

P1 .

P2

OPTIONAL P5

P3 .

P4

OPTIONAL P7

OPTIONAL P8

UNION

P9

FILTER ( R )

What is the (formal) meaning of a general SPARQL query?

25

Page 48: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: An algebraic syntax

V : set of variables

Each variable is assumed to start with ?

26

Page 49: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: An algebraic syntax

V : set of variables

Each variable is assumed to start with ?

Triple pattern: t ∈ (U ∪ V ) × (U ∪ V ) × (U ∪ L ∪ V )

Examples: (?X , name, john), (?X , name, ?Y )

26

Page 50: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: An algebraic syntax

V : set of variables

Each variable is assumed to start with ?

Triple pattern: t ∈ (U ∪ V ) × (U ∪ V ) × (U ∪ L ∪ V )

Examples: (?X , name, john), (?X , name, ?Y )

Basic graph pattern (bgp): Finite set of triple patterns

Examples: (?X , knows, ?Y ), (?Y , name, john)

26

Page 51: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL: An algebraic syntax (cont’d)

Recursive definition of SPARQL graph patterns:

Every basic graph pattern is a graph pattern

If P1, P2 are graph patterns, then (P1 AND P2), (P1 OPT P2),(P1 UNION P2) are graph pattern

If P is a graph pattern and R is a built-in condition, then(P FILTER R) is a graph pattern

SPARQL query:

If P is a graph pattern and W is a finite set of variables, then(SELECT W P) is a SPARQL query

27

Page 52: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Standard versus algebraic notation

?X :name "john" (?X , name, john)

29

Page 53: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Standard versus algebraic notation

?X :name "john" (?X , name, john)

P1 . P2 (P1 AND P2 )

29

Page 54: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Standard versus algebraic notation

?X :name "john" (?X , name, john)

P1 . P2 (P1 AND P2 )

P1 OPTIONAL P2 (P1 OPT P2 )

29

Page 55: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Standard versus algebraic notation

?X :name "john" (?X , name, john)

P1 . P2 (P1 AND P2 )

P1 OPTIONAL P2 (P1 OPT P2 )

P1 UNION P2 (P1 UNION P2 )

29

Page 56: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Standard versus algebraic notation

?X :name "john" (?X , name, john)

P1 . P2 (P1 AND P2 )

P1 OPTIONAL P2 (P1 OPT P2 )

P1 UNION P2 (P1 UNION P2 )

P1 FILTER ( R ) (P1 FILTER R )

29

Page 57: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Standard versus algebraic notation

?X :name "john" (?X , name, john)

P1 . P2 (P1 AND P2 )

P1 OPTIONAL P2 (P1 OPT P2 )

P1 UNION P2 (P1 UNION P2 )

P1 FILTER ( R ) (P1 FILTER R )

SELECT W WHERE P ( SELECT W P )

29

Page 58: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Mappings: building block for the semantics

Definition

A mapping is a partial function:

µ : V −→ (U ∪ L ∪ B)

30

Page 59: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Mappings: building block for the semantics

Definition

A mapping is a partial function:

µ : V −→ (U ∪ L ∪ B)

Given a mapping µ and a triple pattern t:

30

Page 60: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Mappings: building block for the semantics

Definition

A mapping is a partial function:

µ : V −→ (U ∪ L ∪ B)

Given a mapping µ and a triple pattern t:

µ(t): triple obtained from t replacing variables according to µ

30

Page 61: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Mappings: building block for the semantics

Definition

A mapping is a partial function:

µ : V −→ (U ∪ L ∪ B)

Given a mapping µ and a triple pattern t:

µ(t): triple obtained from t replacing variables according to µ

Example

30

Page 62: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Mappings: building block for the semantics

Definition

A mapping is a partial function:

µ : V −→ (U ∪ L ∪ B)

Given a mapping µ and a triple pattern t:

µ(t): triple obtained from t replacing variables according to µ

Example

µ = ?X → R1, ?Y → R2, ?Z → john

30

Page 63: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Mappings: building block for the semantics

Definition

A mapping is a partial function:

µ : V −→ (U ∪ L ∪ B)

Given a mapping µ and a triple pattern t:

µ(t): triple obtained from t replacing variables according to µ

Example

µ = ?X → R1, ?Y → R2, ?Z → john

t = (?X , name, ?Z )

30

Page 64: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Mappings: building block for the semantics

Definition

A mapping is a partial function:

µ : V −→ (U ∪ L ∪ B)

Given a mapping µ and a triple pattern t:

µ(t): triple obtained from t replacing variables according to µ

Example

µ = ?X → R1, ?Y → R2, ?Z → john

t = (?X , name, ?Z )

µ(t) = (R1, name, john)

30

Page 65: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

The semantics of triple patterns

Definition

The evaluation of triple pattern t over a graph G , denoted byJtKG , is the set of all mappings µ such that:

31

Page 66: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

The semantics of triple patterns

Definition

The evaluation of triple pattern t over a graph G , denoted byJtKG , is the set of all mappings µ such that:

dom(µ) is exactly the set of variables occurring in t

31

Page 67: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

The semantics of triple patterns

Definition

The evaluation of triple pattern t over a graph G , denoted byJtKG , is the set of all mappings µ such that:

dom(µ) is exactly the set of variables occurring in t

µ(t) ∈ G

31

Page 68: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(?X , name, ?N)KG

32

Page 69: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(?X , name, ?N)KG

µ1 = ?X → R1, ?N → johnµ2 = ?X → R2, ?N → paul

32

Page 70: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(?X , name, ?N)KG

µ1 = ?X → R1, ?N → johnµ2 = ?X → R2, ?N → paul

J(?X , email, ?E )KG

32

Page 71: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(?X , name, ?N)KG

µ1 = ?X → R1, ?N → johnµ2 = ?X → R2, ?N → paul

J(?X , email, ?E )KG

µ = ?X → R1, ?E → [email protected]

32

Page 72: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(?X , name, ?N)KG

?X ?Nµ1 R1 johnµ2 R2 paul

J(?X , email, ?E )KG

?X ?Eµ R1 [email protected]

32

Page 73: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(R1, webPage, ?W )KG

J(R2, name, paul)KG

J(R3, name, ringo)KG

33

Page 74: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(R1, webPage, ?W )KG

J(R2, name, paul)KG

J(R3, name, ringo)KG

33

Page 75: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(R1, webPage, ?W )KG

J(R2, name, paul)KG

J(R3, name, ringo)KG

33

Page 76: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example

G(R1, name, john)

(R1, email, [email protected])(R2, name, paul)

J(R1, webPage, ?W )KG

J(R2, name, paul)KG

µ∅ =

J(R3, name, ringo)KG

33

Page 77: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of SPARQL: Basic graph patterns

Let P be a basic graph pattern

var(P): set of variables mentioned in P

34

Page 78: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of SPARQL: Basic graph patterns

Let P be a basic graph pattern

var(P): set of variables mentioned in P

Given a mapping µ such that var(P) ⊆ dom(µ):

µ(P) = µ(t) | t ∈ P

34

Page 79: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of SPARQL: Basic graph patterns

Let P be a basic graph pattern

var(P): set of variables mentioned in P

Given a mapping µ such that var(P) ⊆ dom(µ):

µ(P) = µ(t) | t ∈ P

Definition

The evaluation of P over an RDF graph G , denoted by JPKG , isthe set of mappings µ:

dom(µ) = var(P)

µ(P) ⊆ G

34

Page 80: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of basic graph patterns: An example

graph bgp evaluation(R1, name, john)(R1, email, [email protected])(R2, name, paul)

(?X , name, ?Y ),(?X , email, ?Z )

35

Page 81: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of basic graph patterns: An example

graph bgp evaluation(R1, name, john)(R1, email, [email protected])(R2, name, paul)

(?X , name, ?Y ),(?X , email, ?Z )

35

Page 82: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of basic graph patterns: An example

graph bgp evaluation(R1, name, john)(R1, email, [email protected])(R2, name, paul)

(?X , name, ?Y ),(?X , email, ?Z )

35

Page 83: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of basic graph patterns: An example

graph bgp evaluation(R1, name, john)(R1, email, [email protected])(R2, name, paul)

(?X , name, ?Y ),(?X , email, ?Z )

?X ?Y ?Zµ: R1 john [email protected]

35

Page 84: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of basic graph patterns: An example

graph bgp evaluation(R1, name, john)(R1, email, [email protected])(R2, name, paul)

(?X , name, ?Y ),(?X , email, ?Z )

?X ?Y ?Zµ: R1 john [email protected]

Notationt is used to represent t

35

Page 85: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Compatible mappings: mappings that can be merged

Definition

Mappings µ1 and µ2 are compatible if they agree in their commonvariables:

If ?X ∈ dom(µ1) ∩ dom(µ2), then µ1(?X ) = µ2(?X )

36

Page 86: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Compatible mappings: mappings that can be merged

Definition

Mappings µ1 and µ2 are compatible if they agree in their commonvariables:

If ?X ∈ dom(µ1) ∩ dom(µ2), then µ1(?X ) = µ2(?X )

Example

?X ?Y ?Z ?Vµ1 : R1 johnµ2 : R1 [email protected]µ3 : [email protected] R2

36

Page 87: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Compatible mappings: mappings that can be merged

Definition

Mappings µ1 and µ2 are compatible if they agree in their commonvariables:

If ?X ∈ dom(µ1) ∩ dom(µ2), then µ1(?X ) = µ2(?X )

Example

?X ?Y ?Z ?Vµ1 : R1 johnµ2 : R1 [email protected]µ3 : [email protected] R2

36

Page 88: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Compatible mappings: mappings that can be merged

Definition

Mappings µ1 and µ2 are compatible if they agree in their commonvariables:

If ?X ∈ dom(µ1) ∩ dom(µ2), then µ1(?X ) = µ2(?X )

Example

?X ?Y ?Z ?Vµ1 : R1 johnµ2 : R1 [email protected]µ3 : [email protected] R2

µ1 ∪ µ2 : R1 john [email protected]

36

Page 89: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Compatible mappings: mappings that can be merged

Definition

Mappings µ1 and µ2 are compatible if they agree in their commonvariables:

If ?X ∈ dom(µ1) ∩ dom(µ2), then µ1(?X ) = µ2(?X )

Example

?X ?Y ?Z ?Vµ1 : R1 johnµ2 : R1 [email protected]µ3 : [email protected] R2

µ1 ∪ µ2 : R1 john [email protected]

36

Page 90: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Compatible mappings: mappings that can be merged

Definition

Mappings µ1 and µ2 are compatible if they agree in their commonvariables:

If ?X ∈ dom(µ1) ∩ dom(µ2), then µ1(?X ) = µ2(?X )

Example

?X ?Y ?Z ?Vµ1 : R1 johnµ2 : R1 [email protected]µ3 : [email protected] R2

µ1 ∪ µ2 : R1 john [email protected]µ1 ∪ µ3 : R1 john [email protected] R2

36

Page 91: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Compatible mappings: mappings that can be merged

Definition

Mappings µ1 and µ2 are compatible if they agree in their commonvariables:

If ?X ∈ dom(µ1) ∩ dom(µ2), then µ1(?X ) = µ2(?X )

Example

?X ?Y ?Z ?Vµ1 : R1 johnµ2 : R1 [email protected]µ3 : [email protected] R2

µ1 ∪ µ2 : R1 john [email protected]µ1 ∪ µ3 : R1 john [email protected] R2

µ2 and µ3 are not compatible

36

Page 92: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Sets of mappings and operations

Let Ω1 and Ω2 be sets of mappings:

DefinitionJoin: Ω1 Ω2

µ1 ∪ µ2 | µ1 ∈ Ω1, µ2 ∈ Ω2, and µ1, µ2 are compatibles

extending mappings in Ω1 with compatible mappings in Ω2

will be used to define AND

37

Page 93: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Sets of mappings and operations

Let Ω1 and Ω2 be sets of mappings:

DefinitionJoin: Ω1 Ω2

µ1 ∪ µ2 | µ1 ∈ Ω1, µ2 ∈ Ω2, and µ1, µ2 are compatibles

extending mappings in Ω1 with compatible mappings in Ω2

will be used to define AND

DefinitionUnion: Ω1 ∪ Ω2

µ | µ ∈ Ω1 or µ ∈ Ω2

mappings in Ω1 plus mappings in Ω2 (the usual union of sets)

will be used to define UNION

37

Page 94: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Sets of mappings and operations

DefinitionDifference: Ω1 r Ω2

µ ∈ Ω1 | for all µ′ ∈ Ω2, µ and µ′ are not compatibles

mappings in Ω1 that cannot be extended with mappings in Ω2

38

Page 95: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Sets of mappings and operations

DefinitionDifference: Ω1 r Ω2

µ ∈ Ω1 | for all µ′ ∈ Ω2, µ and µ′ are not compatibles

mappings in Ω1 that cannot be extended with mappings in Ω2

Definition

Left outer join: Ω1 Ω2 = (Ω1 Ω2) ∪ (Ω1 r Ω2)

extension of mappings in Ω1 with compatible mappings in Ω2

plus the mappings in Ω1 that cannot be extended.

will be used to define OPT

38

Page 96: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of SPARQL: AND, UNION, OPT and SELECT

Given an RDF graph G

Definition

J(P1 AND P2)KG =

J(P1 UNION P2)KG =

J(P1 OPT P2)KG =

J(SELECT W P)KG =

39

Page 97: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of SPARQL: AND, UNION, OPT and SELECT

Given an RDF graph G

Definition

J(P1 AND P2)KG = JP1KG JP2KG

J(P1 UNION P2)KG = JP1KG ∪ JP2KG

J(P1 OPT P2)KG = JP1KG JP2KG

J(SELECT W P)KG = µ|W | µ ∈ JPKG

39

Page 98: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of SPARQL: AND, UNION, OPT and SELECT

Given an RDF graph G

Definition

J(P1 AND P2)KG = JP1KG JP2KG

J(P1 UNION P2)KG = JP1KG ∪ JP2KG

J(P1 OPT P2)KG = JP1KG JP2KG

J(SELECT W P)KG = µ|W | µ ∈ JPKG

dom(µ|W ) = dom(µ) ∩ W and

µ|W (?X ) = µ(?X ) for every ?X ∈ dom(µ|W )

39

Page 99: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (AND)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) AND (?X , email, ?E ))KG

40

Page 100: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (AND)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) AND (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

40

Page 101: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (AND)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) AND (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

40

Page 102: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (AND)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) AND (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?X ?Eµ4 R1 [email protected]µ5 R3 [email protected]

40

Page 103: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (AND)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) AND (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?X ?Eµ4 R1 [email protected]µ5 R3 [email protected]

40

Page 104: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (AND)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) AND (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?X ?Eµ4 R1 [email protected]µ5 R3 [email protected]

?X ?N ?Eµ1 ∪ µ4 R1 john [email protected]µ3 ∪ µ5 R3 ringo [email protected]

40

Page 105: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (OPT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) OPT (?X , email, ?E ))KG

41

Page 106: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (OPT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) OPT (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

41

Page 107: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (OPT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) OPT (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

41

Page 108: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (OPT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) OPT (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?X ?Eµ4 R1 [email protected]µ5 R3 [email protected]

41

Page 109: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (OPT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) OPT (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?X ?Eµ4 R1 [email protected]µ5 R3 [email protected]

41

Page 110: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (OPT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) OPT (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?X ?Eµ4 R1 [email protected]µ5 R3 [email protected]

?X ?N ?Eµ1 ∪ µ4 R1 john [email protected]µ3 ∪ µ5 R3 ringo [email protected]

µ2 R2 paul

41

Page 111: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (OPT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) OPT (?X , email, ?E ))KG

J(?X , name, ?N)KG J(?X , email, ?E )KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?X ?Eµ4 R1 [email protected]µ5 R3 [email protected]

?X ?N ?Eµ1 ∪ µ4 R1 john [email protected]µ3 ∪ µ5 R3 ringo [email protected]

µ2 R2 paul

41

Page 112: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (UNION)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , email, ?Info) UNION (?X , webPage, ?Info))KG

42

Page 113: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (UNION)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , email, ?Info) UNION (?X , webPage, ?Info))KG

J(?X , email, ?Info)KG ∪ J(?X , webPage, ?Info)KG

42

Page 114: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (UNION)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , email, ?Info) UNION (?X , webPage, ?Info))KG

J(?X , email, ?Info)KG ∪ J(?X , webPage, ?Info)KG

?X ?Info

µ1 R1 [email protected]µ2 R3 [email protected]

42

Page 115: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (UNION)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , email, ?Info) UNION (?X , webPage, ?Info))KG

J(?X , email, ?Info)KG ∪ J(?X , webPage, ?Info)KG

?X ?Info

µ1 R1 [email protected]µ2 R3 [email protected]

?X ?Info

µ3 R3 www.ringo.com

42

Page 116: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (UNION)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , email, ?Info) UNION (?X , webPage, ?Info))KG

J(?X , email, ?Info)KG ∪ J(?X , webPage, ?Info)KG

?X ?Info

µ1 R1 [email protected]µ2 R3 [email protected]

∪?X ?Info

µ3 R3 www.ringo.com

42

Page 117: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (UNION)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , email, ?Info) UNION (?X , webPage, ?Info))KG

J(?X , email, ?Info)KG ∪ J(?X , webPage, ?Info)KG

?X ?Info

µ1 R1 [email protected]µ2 R3 [email protected]

∪?X ?Info

µ3 R3 www.ringo.com

?X ?Info

µ1 R1 [email protected]µ2 R3 [email protected]µ3 R3 www.ringo.com

42

Page 118: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (SELECT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J(SELECT ?N , ?E ((?X , name, ?N) AND (?X , email, ?E )))KG

43

Page 119: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (SELECT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J(SELECT ?N , ?E ((?X , name, ?N) AND (?X , email, ?E )))KG

SELECT?N , ?E?X ?N ?E

µ1 R1 john [email protected]µ2 R3 ringo [email protected]

43

Page 120: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (SELECT)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J(SELECT ?N , ?E ((?X , name, ?N) AND (?X , email, ?E )))KG

SELECT?N , ?E?X ?N ?E

µ1 R1 john [email protected]µ2 R3 ringo [email protected]

?N ?Eµ1|?N,?E

john [email protected]

µ2|?N,?Eringo [email protected]

43

Page 121: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Filter expressions (value constraints)

Filter expression: (P FILTER R)

P is a graph pattern

R is a built-in condition

We consider in R :

equality = among variables and RDF terms

unary predicate bound

boolean combinations (∧, ∨, ¬)

44

Page 122: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Satisfaction of value constraints

A mapping µ satisfies a condition R (µ |= R) if:

45

Page 123: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Satisfaction of value constraints

A mapping µ satisfies a condition R (µ |= R) if:

R is ?X = c , ?X ∈ dom(µ) and µ(?X ) = c

R is ?X =?Y , ?X , ?Y ∈ dom(µ) and µ(?X ) = µ(?Y )

R is bound(?X ) and ?X ∈ dom(µ)

45

Page 124: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Satisfaction of value constraints

A mapping µ satisfies a condition R (µ |= R) if:

R is ?X = c , ?X ∈ dom(µ) and µ(?X ) = c

R is ?X =?Y , ?X , ?Y ∈ dom(µ) and µ(?X ) = µ(?Y )

R is bound(?X ) and ?X ∈ dom(µ)

usual rules for Boolean connectives

45

Page 125: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Satisfaction of value constraints

A mapping µ satisfies a condition R (µ |= R) if:

R is ?X = c , ?X ∈ dom(µ) and µ(?X ) = c

R is ?X =?Y , ?X , ?Y ∈ dom(µ) and µ(?X ) = µ(?Y )

R is bound(?X ) and ?X ∈ dom(µ)

usual rules for Boolean connectives

Definition

FILTER : selects mappings that satisfy a condition

J(P FILTER R)KG = µ ∈ JPKG | µ |= R

45

Page 126: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) FILTER (?N = ringo ∨ ?N = paul))KG

46

Page 127: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) FILTER (?N = ringo ∨ ?N = paul))KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

46

Page 128: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) FILTER (?N = ringo ∨ ?N = paul))KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?N = ringo ∨ ?N = paul

46

Page 129: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J((?X , name, ?N) FILTER (?N = ringo ∨ ?N = paul))KG

?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo

?N = ringo ∨ ?N = paul

?X ?Nµ2 R2 paulµ3 R3 ringo

46

Page 130: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J(((?X , name, ?N) OPT (?X , email, ?E )) FILTER ¬ bound(?E ))KG

47

Page 131: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J(((?X , name, ?N) OPT (?X , email, ?E )) FILTER ¬ bound(?E ))KG

?X ?N ?Eµ1 ∪ µ4 R1 john [email protected]µ3 ∪ µ5 R3 ringo [email protected]

µ2 R2 paul

47

Page 132: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J(((?X , name, ?N) OPT (?X , email, ?E )) FILTER ¬ bound(?E ))KG

?X ?N ?Eµ1 ∪ µ4 R1 john [email protected]µ3 ∪ µ5 R3 ringo [email protected]

µ2 R2 paul

¬ bound(?E )

47

Page 133: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Example (FILTER)

G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected]) (R3, email, [email protected])

(R3, webPage, www.ringo.com)

J(((?X , name, ?N) OPT (?X , email, ?E )) FILTER ¬ bound(?E ))KG

?X ?N ?Eµ1 ∪ µ4 R1 john [email protected]µ3 ∪ µ5 R3 ringo [email protected]

µ2 R2 paul

¬ bound(?E )

?X ?Nµ2 R2 paul

47

Page 134: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL 1.1

A new version of SPARQL was recently released (March 2013):SPARQL 1.1

Some new features in SPARQL 1.1:

Entailment regimes for RDFS and OWL

Navigational capabilities: Property paths

48

Page 135: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL provides limited navigational capabilities

URI 2email

[email protected]

email

phone

name

friendOf [email protected]

URI 1

Paul446928888

John

Petername

nameGeorge

URI 0

friendOf

URI 3

friendOf

URI 2email

[email protected]

email

phone

name

friendOf [email protected]

URI 1

Paul446928888

John

Petername

nameGeorge

URI 0

friendOf

URI 3

friendOf

50

Page 136: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

SPARQL provides limited navigational capabilities

URI 2email

[email protected]

email

phone

name

friendOf [email protected]

URI 1

Paul446928888

John

Petername

nameGeorge

URI 0

friendOf

URI 3

friendOf

URI 2email

[email protected]

email

phone

name

friendOf [email protected]

URI 1

Paul446928888

John

Petername

nameGeorge

URI 0

friendOf

URI 3

friendOf

(SELECT ?X ((?X , friendOf, ?Y ) AND (?Y , name, George)))

50

Page 137: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

A possible solution: Property paths

URI 2email

[email protected]

email

phone

name

friendOf [email protected]

URI 1

Paul446928888

John

Petername

nameGeorge

URI 0

friendOf

URI 3

friendOf

52

Page 138: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

A possible solution: Property paths

URI 2email

[email protected]

email

phone

name

friendOf [email protected]

URI 1

Paul446928888

John

Petername

nameGeorge

URI 0

friendOf

URI 3

friendOf

(SELECT ?X ((?X , (friendOf)∗, ?Y ) AND (?Y , name, George)))

52

Page 139: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Navigational capabilities in SPARQL 1.1: Property paths

Syntax of property paths:

exp := a | exp/exp | exp|exp | exp∗

where a ∈ U

53

Page 140: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Navigational capabilities in SPARQL 1.1: Property paths

Syntax of property paths:

exp := a | exp/exp | exp|exp | exp∗

where a ∈ U

Other expressions are allowed:

ˆexp : inverse path!(a1| . . . |an) : a URI which is not one of ai (1 ≤ i ≤ n)

53

Page 141: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Evaluating property paths

The evaluation of a property path over an RDF graph G is definedas follows:

54

Page 142: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Evaluating property paths

The evaluation of a property path over an RDF graph G is definedas follows:

JaKG = (x , y) | (x , a, y) ∈ G

54

Page 143: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Evaluating property paths

The evaluation of a property path over an RDF graph G is definedas follows:

JaKG = (x , y) | (x , a, y) ∈ GJexp1/exp2KG = (x , y) | ∃z (x , z) ∈ Jexp1KG and

(z , y) ∈ Jexp2KG

54

Page 144: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Evaluating property paths

The evaluation of a property path over an RDF graph G is definedas follows:

JaKG = (x , y) | (x , a, y) ∈ GJexp1/exp2KG = (x , y) | ∃z (x , z) ∈ Jexp1KG and

(z , y) ∈ Jexp2KGJexp1|exp2KG = Jexp1KG ∪ Jexp2KG

54

Page 145: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Evaluating property paths

The evaluation of a property path over an RDF graph G is definedas follows:

JaKG = (x , y) | (x , a, y) ∈ GJexp1/exp2KG = (x , y) | ∃z (x , z) ∈ Jexp1KG and

(z , y) ∈ Jexp2KGJexp1|exp2KG = Jexp1KG ∪ Jexp2KG

Jexp∗KG = (a, a) | a is a URI in G ∪ JexpKG ∪Jexp/expKG ∪ Jexp/exp/expKG ∪ · · ·

54

Page 146: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Property paths in SPARQL 1.1

New element in SPARQL 1.1: A triple of the form (x , exp, y)

exp is a property path

x (resp. y) is either an element from U or a variable

55

Page 147: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Property paths in SPARQL 1.1

New element in SPARQL 1.1: A triple of the form (x , exp, y)

exp is a property path

x (resp. y) is either an element from U or a variable

Example

(?X , (friendOf)∗, ?Y ): Checks whether there exists a path offriends of arbitrary length from ?X to ?Y

55

Page 148: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Property paths in SPARQL 1.1

New element in SPARQL 1.1: A triple of the form (x , exp, y)

exp is a property path

x (resp. y) is either an element from U or a variable

Example

(?X , (friendOf)∗, ?Y ): Checks whether there exists a path offriends of arbitrary length from ?X to ?Y

(?X , (rdf:sc)∗, person): Checks whether the value stored in ?X isa subclass of person

55

Page 149: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Property paths in SPARQL 1.1

New element in SPARQL 1.1: A triple of the form (x , exp, y)

exp is a property path

x (resp. y) is either an element from U or a variable

Example

(?X , (friendOf)∗, ?Y ): Checks whether there exists a path offriends of arbitrary length from ?X to ?Y

(?X , (rdf:sc)∗, person): Checks whether the value stored in ?X isa subclass of person

(?X , (rdf:sp)∗, ?Y ): Checks whether the value stored in ?X is asubproperty of the value stored in ?Y

55

Page 150: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of property paths

Evaluation of t = (?X , exp, ?Y ) over an RDF graph G is the set ofmappings µ such that:

56

Page 151: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of property paths

Evaluation of t = (?X , exp, ?Y ) over an RDF graph G is the set ofmappings µ such that:

dom(µ) = ?X , ?Y

56

Page 152: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of property paths

Evaluation of t = (?X , exp, ?Y ) over an RDF graph G is the set ofmappings µ such that:

dom(µ) = ?X , ?Y

(µ(?X ), µ(?Y )) ∈ JexpKG

56

Page 153: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of property paths

Evaluation of t = (?X , exp, ?Y ) over an RDF graph G is the set ofmappings µ such that:

dom(µ) = ?X , ?Y

(µ(?X ), µ(?Y )) ∈ JexpKG

Other cases are defined analogously.

56

Page 154: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Semantics of property paths

Evaluation of t = (?X , exp, ?Y ) over an RDF graph G is the set ofmappings µ such that:

dom(µ) = ?X , ?Y

(µ(?X ), µ(?Y )) ∈ JexpKG

Other cases are defined analogously.

Example

((?X , KLM/(KLM)∗, ?Y ) FILTER ¬(?X =?Y )): It is possible to go from?X to ?Y by using the airline KLM, where ?X , ?Y are different cities

56

Page 155: Semantic Web Data/RDF/SPARQL - University of Edinburghhomepages.inf.ed.ac.uk/libkin/teach/atfd16/rdfslides.pdf · Relational Semantic Web Tables RDF Graphs SQL SPARQL Closed Data

Comments on papers

Jorge Perez, Marcelo Arenas, Claudio Gutierrez: Semantics and complexity of SPARQL. ACM Trans.Database Syst. 34(3) (2009)

M. Arenas, J. Perez: Querying semantic web data with SPARQL. PODS 2011: 305-316In these two papers, your essays ought to concentrate on complexity, as semantics was already covered.

Marcelo Arenas, Georg Gottlob, Andreas Pieris: Expressive languages for querying the semantic web.PODS 2014: 14-26Extend SPARQL with more expressive ontologies and recursion, and translation into datalog.

Leonid Libkin, Juan L. Reutter, Domagoj Vrgoc: Trial for RDF: adapting graph query languages for RDFdata. PODS 2013: 201-212Are graph data and RDF the same? Not really. This shows how to bridge them.

Jorge Perez, Marcelo Arenas, Claudio Gutierrez: nSPARQL: A navigational language for RDF. J. WebSem. 8(4): 255-270 (2010)Extending navigational capabilities, using some XPath ideas.

Marcelo Arenas, Sebastian Conca, Jorge Perez: Counting beyond a Yottabyte, or how SPARQL 1.1property paths will prevent adoption of the standard. WWW 2012: 629-638

Katja Losemann, Wim Martens: The complexity of regular expressions and property paths in SPARQL.ACM Trans. Database Syst. 38(4): 24 (2013)Two papers showing that bad things happen if one queries RDF accoring to SPARQL 1.1 standard, anddifferent solutions for fixing the problem.

57