Top Banner
Querying Semantic Web Data with SPARQL Marcelo Arenas * and Jorge P´ erez * Pontificia Universidad Cat´olica de Chile Universidad de Chile Santiago, January 2015 1
220

Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

May 05, 2018

Download

Documents

tranhanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Querying Semantic Web Data with SPARQL

Marcelo Arenas∗ and Jorge Perez†

∗Pontificia Universidad Catolica de Chile†Universidad de Chile

Santiago, January 2015

1

Page 2: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

RDF + SPARQL

MOTIVATION

2

Page 3: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Relational Semantic Web

Tables

SQL

3

Page 4: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Relational Semantic Web

Tables RDF Graphs

SQL

3

Page 5: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Relational Semantic Web

Tables RDF Graphs

SQL SPARQL

3

Page 6: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Relational Semantic Web

Tables RDF Graphs

SQL SPARQL

Closed Data

(inside an organization)

3

Page 7: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Relational Semantic Web

Tables RDF Graphs

SQL SPARQL

Closed Data Open Data

(inside an organization) (available on the Web)

3

Page 8: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Demo: Can you answer these questions?

4

Page 9: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Demo: Can you answer these questions?

People in Wikipedia that has “University of Chile” as alma mater?

4

Page 10: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Demo: Can you answer these questions?

People in Wikipedia that has “University of Chile” as alma mater?

Who is the oldest person appearing in Wikipediathat was born in Chile?

4

Page 11: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Demo: Can you answer these questions?

People in Wikipedia that has “University of Chile” as alma mater?

Who is the oldest person appearing in Wikipediathat was born in Chile?

What is the rainiest place during February?

4

Page 12: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

RDF

5

Page 13: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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)

6

Page 14: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

7

Page 15: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

RDF formal model

Subject ObjectPredicate

LB

U

U UB

U = set of Uris

B = set of Blank nodes

L = set of Literals

8

Page 16: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

8

Page 17: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

8

Page 18: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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/>

9

Page 19: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

An example of a URI

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

10

Page 20: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

URI can be used for any abstract resource

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

11

Page 21: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

12

Page 22: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

13

Page 23: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

14

Page 24: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

14

Page 25: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

14

Page 26: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

15

Page 27: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

16

Page 28: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

17

Page 29: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

17

Page 30: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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.

17

Page 31: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

17

Page 32: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

18

Page 33: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

19

Page 34: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

20

Page 35: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL

21

Page 36: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Querying RDF: SPARQL

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

SPARQL is a recursive acronym that stands for SPARQLProtocol 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, . . ..

22

Page 37: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

23

Page 38: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

23

Page 39: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

WHERE

23

Page 40: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

23

Page 41: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

23

Page 42: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:iswc .

23

Page 43: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:iswc .

A SPARQL query consists of a:

23

Page 44: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:iswc .

A SPARQL query consists of a:

Head: Processing of the variables

23

Page 45: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

Example: Authors that have published in ISWC

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:iswc .

A SPARQL query consists of a:

Head: Processing of the variables

Body: Pattern matching expression

23

Page 46: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

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

SELECT ?Author ?WebPage

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:iswc .

OPTIONAL

?Author foaf:homePage ?WebPage .

24

Page 47: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: A Simple RDF Query Language

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

SELECT ?Author ?WebPage

WHERE

?Paper dc:creator ?Author .

?Paper dct:partOf ?Conf .

?Conf swrc:series conf:iswc .

OPTIONAL

?Author foaf:homePage ?WebPage .

24

Page 48: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

But things can become more complex...

Interesting features of patternmatching on graphs

SELECT ?X1 ?X2 ...

P1 .

P2

25

Page 49: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

But things can become more complex...

Interesting features of patternmatching on graphs

Grouping SELECT ?X1 ?X2 ...

P1 .

P2

P3 .

P4

25

Page 50: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 51: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 52: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 53: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 54: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 55: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 56: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL: An algebraic syntax

V : set of variables

Each variable is assumed to start with ?

26

Page 57: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 58: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 59: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 60: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Standard versus algebraic notation

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

28

Page 61: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Standard versus algebraic notation

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

P1 . P2 (P1 AND P2 )

28

Page 62: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Standard versus algebraic notation

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

P1 . P2 (P1 AND P2 )

P1 OPTIONAL P2 (P1 OPT P2 )

28

Page 63: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

28

Page 64: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

28

Page 65: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

28

Page 66: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Mappings: building block for the semantics

Definition

A mapping is a partial function:

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

29

Page 67: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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:

29

Page 68: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 µ

29

Page 69: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

29

Page 70: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

29

Page 71: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

29

Page 72: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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)

29

Page 73: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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:

30

Page 74: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

30

Page 75: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

30

Page 76: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Example

G(R1, name, john)

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

J(?X , name, ?N)KG

31

Page 77: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

31

Page 78: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

31

Page 79: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

31

Page 80: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

31

Page 81: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

32

Page 82: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

32

Page 83: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

32

Page 84: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

32

Page 85: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Semantics of SPARQL: Basic graph patterns

Let P be a basic graph pattern

var(P): set of variables mentioned in P

33

Page 86: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

33

Page 87: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

33

Page 88: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

34

Page 89: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

34

Page 90: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

34

Page 91: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

34

Page 92: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

34

Page 93: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

35

Page 94: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

35

Page 95: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

35

Page 96: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

35

Page 97: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

35

Page 98: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

35

Page 99: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

35

Page 100: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Sets of mappings and operations

Let Ω1 and Ω2 be sets of mappings:

Definition

Join: Ω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

36

Page 101: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Sets of mappings and operations

Let Ω1 and Ω2 be sets of mappings:

Definition

Join: Ω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

36

Page 102: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

37

Page 103: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

37

Page 104: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 =

38

Page 105: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

38

Page 106: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

38

Page 107: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

39

Page 108: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

39

Page 109: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

39

Page 110: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

39

Page 111: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

39

Page 112: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

39

Page 113: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

40

Page 114: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

40

Page 115: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

40

Page 116: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

40

Page 117: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

40

Page 118: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

40

Page 119: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

40

Page 120: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

41

Page 121: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

41

Page 122: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

41

Page 123: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

41

Page 124: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

41

Page 125: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

41

Page 126: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

42

Page 127: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

42

Page 128: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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]

42

Page 129: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 (∧, ∨, ¬)

43

Page 130: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Satisfaction of value constraints

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

44

Page 131: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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(µ)

44

Page 132: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

44

Page 133: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

44

Page 134: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

45

Page 135: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

45

Page 136: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

45

Page 137: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

45

Page 138: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

46

Page 139: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

46

Page 140: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 )

46

Page 141: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

46

Page 142: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL 1.1(and some research issues)

47

Page 143: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

An operator (SERVICE) to distribute the execution of a query

Also in this version: Nesting of SELECT expressions, aggregatesand some forms of negation (NOT EXISTS, MINUS)

48

Page 144: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

To remember: Syntax of RDFS

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

49

Page 145: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

To remember: Syntax of RDFS

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

How do we evaluate a query over RDFS data?

49

Page 146: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A simple SPARQL query: (Messi, rdf:type, 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

50

Page 147: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Semantics of RDFS

Checking whether a triple t is in a graph G is the basic step whenanswering queries over RDF.

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

The notion of entailment in RDFS can be defined as forfirst-order logic.

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

51

Page 148: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

An inference system for RDFS

Sub-property :(A, rdf:sp, B) (B, rdf:sp, C)

(A, rdf:sp, C)

(A, rdf:sp, B) (X , A, Y)(X , B, Y)

Subclass :(A, rdf:sc, B) (B, rdf:sc, C)

(A, rdf:sc, C)

(A, rdf:sc, B) (X , rdf:type, A)(X , rdf:type, B)

Typing :(A, rdf:dom, B) (X , A, Y)

(X , rdf:type, B)

(A, rdf:range, B) (X , A, Y)(Y, rdf:type, B)

52

Page 149: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment in RDFS

Theorem (H03,MPG09,GHM11)

The previous system of inference rules characterize the notion ofentailment in RDFS (without blank nodes).

Thus, a triple t can be deduced from an RDF graph G (G |= t) ifft can be deduced from G by applying the inference rules a finitenumber of times.

53

Page 150: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

An entailment regime for RDFS in SPARQL 1.1

Basic graph patterns are evaluated by considering RDFS entailment.

Definition

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

dom(µ) = var(P)

For every t ∈ P : G |= µ(t)

54

Page 151: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

An entailment regime for RDFS in SPARQL 1.1

Basic graph patterns are evaluated by considering RDFS entailment.

Definition

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

dom(µ) = var(P)

For every t ∈ P : G |= µ(t)

The semantics of AND, UNION, OPT, FILTER and SELECT are definedas before.

RDFS entailment is only used at the level of bgps

54

Page 152: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Example 1: What is the answer to

(?X , rdf:type, 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

55

Page 153: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Example 2: What is the answer to

(Messi, rdf:type, 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

56

Page 154: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Example 3: What is the answer to

(Messi, rdf:type, ?Y ), (?Y , rdf:sc, 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

57

Page 155: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations

SPARQL 1.1 can be used to query not only data but also schemainformation

For example: (?X , rdf:sc, person)

58

Page 156: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations (cont’d)

Web Ontology Language (OWL): A more general ontologylanguage for the Semantic Web

Users can define their own axioms

For example: every Chilean has a RUT number

59

Page 157: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations (cont’d)

Web Ontology Language (OWL): A more general ontologylanguage for the Semantic Web

Users can define their own axioms

For example: every Chilean has a RUT number

Basic graph patterns can also be evaluated by considering OWLentailment.

G |= µ(t) has to be defined according to the semantics ofOWL

59

Page 158: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations (cont’d)

What are the consequences of considering entailment only at the levelbgps?

Example

Let G be a graph consisting of (john, rdf:type, student) together with:

(student, rdf:sc, u)(u, owl:union, l)(l , rdf:first, undergrad)(l , rdf:rest, r)(r , rdf:first, grad)(r , rdf:rest, rdf:nil)

axiom student ⊑ (undergrad ⊔ grad)

60

Page 159: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations (cont’d)

What are the consequences of considering entailment only at the levelbgps?

Example

Let G be a graph consisting of (john, rdf:type, student) together with:

(student, rdf:sc, u)(u, owl:union, l)(l , rdf:first, undergrad)(l , rdf:rest, r)(r , rdf:first, grad)(r , rdf:rest, rdf:nil)

axiom student ⊑ (undergrad ⊔ grad)

What should be the answer to

P = ((?X , rdf:type, undergrad) UNION (?X , rdf:type, grad))?

60

Page 160: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations (cont’d)

What are the consequences of considering entailment only at the levelbgps?

Example

Let G be a graph consisting of (john, rdf:type, student) together with:

(student, rdf:sc, u)(u, owl:union, l)(l , rdf:first, undergrad)(l , rdf:rest, r)(r , rdf:first, grad)(r , rdf:rest, rdf:nil)

axiom student ⊑ (undergrad ⊔ grad)

What should be the answer to

P = ((?X , rdf:type, undergrad) UNION (?X , rdf:type, grad))?

Under the current semantics: JPKG = ∅

60

Page 161: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations (cont’d)

It is possible to define a certain-answers semantics for SPARQL 1.1.

Previous example shows that this semantics does not coincide with theofficial semantics of SPARQL 1.1

61

Page 162: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Entailment regimes in SPARQL 1.1: Some observations (cont’d)

It is possible to define a certain-answers semantics for SPARQL 1.1.

Previous example shows that this semantics does not coincide with theofficial semantics of SPARQL 1.1

Open issues

How natural is the semantics of SPARQL 1.1? Is it a good semantics?Why?

Under which (natural) restrictions these two semantics coincide?

61

Page 163: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

62

Page 164: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

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

62

Page 165: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

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

62

Page 166: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

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

62

Page 167: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

63

Page 168: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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)))

63

Page 169: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Navigational capabilities in SPARQL 1.1: Property paths

Syntax of property paths:

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

where a ∈ U

64

Page 170: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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)

64

Page 171: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Evaluating property paths

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

65

Page 172: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Evaluating property paths

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

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

65

Page 173: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

65

Page 174: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

65

Page 175: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 ∪ · · ·

65

Page 176: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

66

Page 177: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 ): Verifies whether there exists a path offriends of arbitrary length from ?X to ?Y

66

Page 178: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 ): Verifies whether there exists a path offriends of arbitrary length from ?X to ?Y

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

66

Page 179: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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 ): Verifies whether there exists a path offriends of arbitrary length from ?X to ?Y

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

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

66

Page 180: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Semantics of property paths

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

67

Page 181: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Semantics of property paths

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

dom(µ) = ?X , ?Y

67

Page 182: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

67

Page 183: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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.

67

Page 184: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

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

67

Page 185: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL 1.1: Entailment regimes and property paths

List the pairs a, b of cities such that there is a way to travel from a to b.

rdfs:sp

LondonOxford Madrid Valladolid

British Airwaysthe Airline Renfe

bus service flight service train service

rdfs:sp rdfs:sp rdfs:sp

transportation service

rdfs:sp rdfs:sp

68

Page 186: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

SPARQL 1.1: Entailment regimes and property paths

List the pairs a, b of cities such that there is a way to travel from a to b.

rdfs:sp

LondonOxford Madrid Valladolid

British Airwaysthe Airline Renfe

bus service flight service train service

rdfs:sp rdfs:sp rdfs:sp

transportation service

rdfs:sp rdfs:sp

In SPARQL 1.1: (?X , transportation service∗, ?Y )

68

Page 187: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Navigational capabilities in SPARQL 1.1: Some observations

Previous query can be expressed in SPARQL 1.1 as the intermediate form ofnavigation involves RDFS vocabulary.

69

Page 188: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Navigational capabilities in SPARQL 1.1: Some observations

Previous query can be expressed in SPARQL 1.1 as the intermediate form ofnavigation involves RDFS vocabulary.

Not expressible: List pairs a, b of persons that are connected through a path ofnodes certified by certifying agency [RK13]:

certified by

Alice Bob

linkedTolinkedTo linkedTo

certified by certified by certified by

certifying agency

certified by certified by

69

Page 189: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Navigational capabilities in SPARQL 1.1: Some observations (cont’d)

Some proposals solve the aforementioned issues: nSPARQL [PAG10],

nested monadically defined queries [RK13], triple algebra [LRV13]

RDFS entailment can be handled in these proposals by using

navigational capabilities

70

Page 190: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Navigational capabilities in SPARQL 1.1: Some observations (cont’d)

Some proposals solve the aforementioned issues: nSPARQL [PAG10],

nested monadically defined queries [RK13], triple algebra [LRV13]

RDFS entailment can be handled in these proposals by using

navigational capabilities

Open issues

How can OWL entailment be handled in these proposals?

What navigational capabilities should be added to SPARQL 1.1?

There is a need for query languages that can return paths

70

Page 191: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

RFD graphs can be interconnected

DBpedia

DBLP

inPods:FaginLN01

:Ronald Fagin

dbpedia:Ronald Fagin dbpedia:Oklahoma

yago:ResearchWorker

dc:creator

owl:sa

meAs

dbo:birthPlace

rdf:type

rdfs:subClassOfyago:DatabaseResearchers

<http://dbpedia.org/ontology/>

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

owl:

rdfs:

<http://www.w3.org/1999/02/22-rdf-syntax-ns#>rdf:

<http://dbpedia.org/resource/>dbpedia:

yago: <http://dbpedia.org/class/yago>

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

dbo:

<http://www.w3.org/2002/07/owl#>

71

Page 192: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Querying interconnected RDF graphs

Retrieve the authors that have published in PODS and were bornin Oklahoma:

SELECT ?Author

WHERE

?Paper dc:creator ?Author .

?Paper dct:PartOf ?Conf .

?Conf swrc:series conf:pods .

SERVICE <http://dbpedia.org/sparql>

?Person owl:sameAs ?Author .

?Person dbo:birthPlace dbpedia:Oklahoma .

72

Page 193: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Federation in SPARQL 1.1

New rule to generate graph patterns:

If P is a graph pattern and c ∈ (U ∪ V ), then (SERVICE c P) is agraph pattern.

73

Page 194: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Federation in SPARQL 1.1

New rule to generate graph patterns:

If P is a graph pattern and c ∈ (U ∪ V ), then (SERVICE c P) is agraph pattern.

We will define the semantics of this new operator.

This corresponds with the official semantics for (SERVICE c P)with c ∈ U

(SERVICE ?X P) is allowed in the official specification of SPARQL1.1, but its semantics is not defined

73

Page 195: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Semantics of SERVICE

ep(·): Partial function from U to the set of all RDF graphs

If c ∈ dom(ep), then ep(c) is the RDF graph associated with theendpoint accessible via c

74

Page 196: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Semantics of SERVICE

ep(·): Partial function from U to the set of all RDF graphs

If c ∈ dom(ep), then ep(c) is the RDF graph associated with theendpoint accessible via c

Definition [BACP13]

The evaluation of P = (SERVICE c P1) over an RDF graph G is defined as:

if c ∈ dom(ep), then JPKG = JP1Kep(c)

if c ∈ U \ dom(ep), then JPKG = µ∅ (where µ∅ is the mapping withempty domain)

if c ∈ V , then

JPKG =⋃

a∈dom(ep)

(

JP1Kep(a) c → a

)

,

74

Page 197: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Are variables useful in SERVICE queries?

Consider the query:

(?X , service address, ?Y ) AND (SERVICE ?Y (?N, email, ?E ))

75

Page 198: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Are variables useful in SERVICE queries?

Consider the query:

(?X , service address, ?Y ) AND (SERVICE ?Y (?N, email, ?E ))

There is a simple strategy to compute the answer to this query.

Can this strategy be generalized?

75

Page 199: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

How can we evaluate SERVICE queries?

We need some notion of boundedness

A variable ?X is bound in a graph pattern P if for every RDF graph G

and every µ ∈ JPKG , it holds that ?X ∈ dom(µ) and µ(?X ) ∈ U

First attempt: Graph pattern P can be evaluated if for every sub-pattern(SERVICE ?X P1) of P, it holds that ?X is bound in P

?Y is bound in(?X , service address, ?Y ) AND (SERVICE ?Y (?N, email, ?E))

76

Page 200: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

The first attempt: Too restrictive

Consider the query:

(?X , service description, ?Z ) UNION(

(?X , service address, ?Y ) AND (SERVICE ?Y (?N , email, ?E ))

)

?Y is not bound in this query, but there is a simple strategy to

evaluate it.

77

Page 201: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

The first attempt: Not appropriate for nested SERVICE

operators

Consider the query:

(?U1, related with, ?U2) AND[

SERVICE ?U1

(

(?N , email, ?E ) OPT

(SERVICE ?U2 (?N , phone, ?F ))

)]

78

Page 202: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Solving the problems . . .

Notation: T (P) is the parse tree of P, in which every node corresponds to asub-pattern of P

Parse tree of (?Y , a, ?Z ) UNION ((?X , b, c) AND (SERVICE ?X (?Y , a, ?Z ))):

(?Y , a, ?Z) UNION ((?X , b, c) AND (SERVICE ?X (?Y , a, ?Z)))

(?Y , a, ?Z) (?X , b, c) AND (SERVICE ?X (?Y , a, ?Z))

(?X , b, c) (SERVICE ?X (?Y , a, ?Z))

(?Y , a, ?Z)

79

Page 203: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

80

Page 204: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:

(?Y , a, ?Z) UNION ((?X , b, c) AND (SERVICE ?X (?Y , a, ?Z)))

(?Y , a, ?Z) (?X , b, c) AND (SERVICE ?X (?Y , a, ?Z))

(?X , b, c) (SERVICE ?X (?Y , a, ?Z))

(?Y , a, ?Z)

80

Page 205: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:

(?Y , a, ?Z) UNION ((?X , b, c) AND (SERVICE ?X (?Y , a, ?Z)))

(?Y , a, ?Z) (?X , b, c) AND (SERVICE ?X (?Y , a, ?Z))

(?X , b, c) (SERVICE ?X (?Y , a, ?Z))

(?Y , a, ?Z)

80

Page 206: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:

(?Y , a, ?Z) UNION ((?X , b, c) AND (SERVICE ?X (?Y , a, ?Z)))

(?Y , a, ?Z) (?X , b, c) AND (SERVICE ?X (?Y , a, ?Z))

(?X , b, c) (SERVICE ?X (?Y , a, ?Z))

(?Y , a, ?Z)

80

Page 207: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:

(?Y , a, ?Z) UNION ((?X , b, c) AND (SERVICE ?X (?Y , a, ?Z)))

(?Y , a, ?Z) (?X , b, c) AND (SERVICE ?X (?Y , a, ?Z))

(?X , b, c) (SERVICE ?X (?Y , a, ?Z))

(?Y , a, ?Z)

80

Page 208: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:(?U1, rw, ?U2) AND (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F ))))

(?U1, rw, ?U2) (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

(?N, e, ?E ) (SERVICE ?U2 (?N, ph, ?F ))

(?N, ph, ?F )

80

Page 209: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:(?U1, rw, ?U2) AND (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F ))))

(?U1, rw, ?U2) (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

(?N, e, ?E ) (SERVICE ?U2 (?N, ph, ?F ))

(?N, ph, ?F )

80

Page 210: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:(?U1, rw, ?U2) AND (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F ))))

(?U1, rw, ?U2) (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

(?N, e, ?E ) (SERVICE ?U2 (?N, ph, ?F ))

(?N, ph, ?F )

80

Page 211: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:(?U1, rw, ?U2) AND (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F ))))

(?U1, rw, ?U2) (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

(?N, e, ?E ) (SERVICE ?U2 (?N, ph, ?F ))

(?N, ph, ?F )

80

Page 212: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness

Definition [BACP13]

A graph pattern P is service-bound if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X is bound in P2

P1 is service-bound

Examples:(?U1, rw, ?U2) AND (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F ))))

(?U1, rw, ?U2) (SERVICE ?U1 ((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

((?N, e, ?E ) OPT (SERVICE ?U2 (?N, ph, ?F )))

(?N, e, ?E ) (SERVICE ?U2 (?N, ph, ?F ))

(?N, ph, ?F )

80

Page 213: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

A more appropriate notion of boundedness (cont’d)

But we still have a problem:

Proposition (BACP13)

The problem of verifying, given a graph pattern P, whether P isservice-bound is undecidable.

We consider a (syntactic) sufficient condition forservice-boundedness.

81

Page 214: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

An appropriate notion: Service-safeness

The set of strongly bound variables in P , denoted by SB(P), isrecursively defined as follows:

if P is a bgp, then SB(P) = var(P)

if P = (P1 AND P2), then SB(P) = SB(P1) ∪ SB(P2)

if P = (P1 UNION P2), then SB(P) = SB(P1) ∩ SB(P2)

if P = (P1 OPT P2), then SB(P) = SB(P1)

if P = (P1 FILTER R), then SB(P) = SB(P1)

if P = (SERVICE c P1), then SB(P) = ∅

82

Page 215: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

An appropriate notion: Service-safeness (cont’d)

Definition [BACP13]

A graph pattern P is service-safe if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X ∈ SB(P2)

P1 is service-safe

If P is service-safe, then there is a strategy to evaluate P without consideringall possible SPARQL endpoints.

83

Page 216: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

An appropriate notion: Service-safeness (cont’d)

Definition [BACP13]

A graph pattern P is service-safe if for every node u of T (P) with label(SERVICE ?X P1), it holds that:

there exists a node v of T (P) with label P2 such that v is an ancestor ofu in T (P) and ?X ∈ SB(P2)

P1 is service-safe

If P is service-safe, then there is a strategy to evaluate P without consideringall possible SPARQL endpoints.

Open issue

Is service-safeness the right condition to ensure that a query containing theSERVICE operator can be executed? Why?

83

Page 217: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Take-home message

RDF is the framework proposed by the W3C to represent information inthe Web

SPARQL is the W3C recommendation query language for RDF (January2008)

SPARLQ 1.1 is the new version of SPARQL (March 2013)

SPARQL 1.1 includes some interesting and useful new features

Entailment regimes for RDFS and OWL, navigationalcapabilities and an operator to distribute the execution of aquery

There are some interesting open issues about these features

84

Page 218: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Thank you!

85

Page 219: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Bibliography

[BACP13] C. Buil-Aranda, M. Arenas, O. Corcho, A. Polleres: Federatingqueries in SPARQL 1.1: Syntax, semantics and evaluation. J. WebSem. 18(1): 1-17 (2013)

[GHM11] C. Gutierrez, C. A. Hurtado, A. O. Mendelzon, J. Perez: Founda-tions of Semantic Web databases. J. Comput. Syst. Sci. 77(3):520-541 (2011)

[H04] P. Hayes: RDF Semantics. W3C Recommendation 10 February2004

86

Page 220: Querying Semantic Web Data with SPARQL - UCmarenas.sitios.ing.uc.cl/talks/CIWS-Jan-15.pdf · Querying Semantic Web Data with SPARQL Marcelo Arenas ... Does the blank node add some

Bibliography (cont’d)

[LRV13] L. Libkin, J. L. Reutter, D. Vrgoc: Trial for RDF: adapting graphquery languages for RDF data. PODS 2013: 201-212

[MPG09] S. Munoz, J. Perez, C. Gutierrez: Simple and Efficient MinimalRDFS. J. Web Sem. 7(3): 220-234 (2009)

[PAG10] J. Perez, M. Arenas, C. Gutierrez: nSPARQL: A navigational lan-guage for RDF. J. Web Sem. 8(4): 255-270 (2010)

[RK13] S. Rudolph, M. Krotzsch: Flag & check: data access with monad-ically defined queries. PODS 2013: 151-162

87