repositories and sparql

61
www.sti-innsbruck.at © Copyright 2008 STI INNSBRUCK www.sti- innsbruck.at Repositories and SPARQL Semantic Web Lecture Lecture VI – xx 2009 Dieter Fensel Slides by: Federico M. Fac

Upload: amy

Post on 11-Jan-2016

42 views

Category:

Documents


0 download

DESCRIPTION

Repositories and SPARQL. Semantic Web Lecture Lecture VI – xx 2009 Dieter Fensel. Slides by: Federico M. Facca. Where are we?. Overview. Introduction and Motivation Technical Solution RDF Repositories SPARQL Illustration by a large example Extensions. Introduction AND MOTIVATION. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Repositories and SPARQL

www.sti-innsbruck.at © Copyright 2008 STI INNSBRUCK www.sti-innsbruck.at

Repositories and SPARQL

Semantic Web Lecture Lecture VI – xx 2009

Dieter FenselSlides by: Federico M. Facca

Page 2: Repositories and SPARQL

www.sti-innsbruck.at

Where are we?

# Date Title

1 Introduction

2 Semantic Web Architecture

3 RDF and RDF Schema

4 Web of hypertext (RDFa, Microformats) and Web of data

5 Semantic Annotation

6 Repositories and SPARQL

7 The Web Ontology Language

8 Rule Interchange Format

9 Web-scale reasoning

10 Social Semantic Web

11 Ontologies and the Semantic Web

12 Semantic Web Services

13 Tools

14 Applications

15 Exam

2

Page 3: Repositories and SPARQL

www.sti-innsbruck.at

Overview

• Introduction and Motivation• Technical Solution

– RDF Repositories– SPARQL

• Illustration by a large example• Extensions

3

Page 4: Repositories and SPARQL

www.sti-innsbruck.at

INTRODUCTION AND MOTIVATION

5

Page 5: Repositories and SPARQL

www.sti-innsbruck.at

Motivation

• Having RDF data available is not enough– Need tools to process, transform, and reason with the

information– Need a way to store the RDF data and interact with it

• Are existing storage systems appropriate to store RDF data?

• Are existing query languages appropriate to query RDF data?

6

Page 6: Repositories and SPARQL

www.sti-innsbruck.at

Databases and RDF

• Relational database are a well established technology to store information and provide query support (SQL)

• How can we store the following RDF data in a relational database?<rdf:Description rdf:about="949318">

<rdf:type rdf:resource="&uni;lecturer"/><uni:name>Dieter Fensel</uni:name><uni:title>University Professor</uni:title>

</rdf:Description>

7

Page 7: Repositories and SPARQL

www.sti-innsbruck.at

Databases and RDF

• Relational database are a well established technology to store information and provide query support (SQL)

• How can we store the following RDF data in a relational database?<rdf:Description rdf:about="949318">

<rdf:type rdf:resource="&uni;lecturer"/><uni:name>Dieter Fensel</uni:name><uni:title>University Professor</uni:title>

</rdf:Description>

• Relational “Traditional” approach

8

Lecturer

id name title

949318 Dieter Fensel University Professor

Page 8: Repositories and SPARQL

www.sti-innsbruck.at

Databases and RDF

• Relational database are a well established technology to store information and provide query support (SQL)

• How can we store the following RDF data in a relational database?<rdf:Description rdf:about="949318">

<rdf:type rdf:resource="&uni;lecturer"/><uni:name>Dieter Fensel</uni:name><uni:title>University Professor</uni:title>

</rdf:Description>

• Relational “Triple” based approach

9

Resources

Id URI

101 949318

102 rdf:type

103 uni:lecturer

104 …

Statement

Subject Predicate ObjectURI ObjectLiteral

101 102 103 null

101 104 201

101 105 202

103 … … null

Literals

Id Value

201 Dieter Fensel

202 University Professor

203 …

… …

Page 9: Repositories and SPARQL

www.sti-innsbruck.at

Why native RDF repositories?

• What happens if I want to find the names of all the lecturers?

• Relation “Traditional” approach:SELECT NAME FROM LECTURER

• Relational “Triple” based approach:SELECT L.Value FROM Literals AS L

INNER JOIN Statement AS S ON S.ObjectLiteral=L.IDINNER JOIN Resources AS R ON R.ID=S.PredicateINNER JOIN Statement AS S1 ON S1.Predicate=S.PredicateINNER JOIN Resources AS R1 ON R1.ID=S1.PredicateINNER JOIN Resources AS R2 ON R2.ID=S1.ObjectURIWHERE R.URI = “uni:name”AND R1.URI = “rdf:type”AND R2.URI = “uni:lecturer”

10

Page 10: Repositories and SPARQL

www.sti-innsbruck.at

Query Languages

• Querying and inferencing is the very purpose of information representation in a machine-accesible way

• A query language is a language that allows a user to retrieve information from a “data source”– E.g. data sources

• A simple text file• XML file• A database• The “Web”

• Query languages usually includes insert and update operations

11

Page 11: Repositories and SPARQL

www.sti-innsbruck.at

Example of Query Languages

• SQL – query language for relational databases

• XQuery, XPointer and XPath – query languages for XML data sources

• SPARQL – query language for RDF graphs

• RDQL – query language for RDF in Jena models

12

Page 12: Repositories and SPARQL

www.sti-innsbruck.at

XPath: a simple query language for XML trees

• The basis for most XML query languages– Selection of document parts– Search context: ordered set of nodes

• Used extensively in XSLT– XPath itself has non-XML syntax

• Navigate through the XML Tree– Similar to a file system (“/“, “../“, “ ./“, etc.)– Query result is the final search context, usually a set of nodes– Filters can modify the search context– Selection of nodes by element names, attribute names, type, content, value,

relations• Several pre-defined functions

• Version 1.0, W3C Recommendation 16 November 1999• Version 2.0, W3C Recommendation 23 January 2007

13

Page 13: Repositories and SPARQL

www.sti-innsbruck.at

Other XML Query Languages

• XQuery– Building up on the same functions and data types

as XPath– With XPath 2.0 these two languages get closer– XQuery is not XML based, but there is an XML notation

(XQueryX)– XQuery 1.0, W3C Recommendation 23 January 2007

• XLink 1.0, W3C Recommendation 27 June 2001– Defines a standard way of creating hyperlinks in XML documents

• XPointer 1.0, W3C Candidate Recommendation– Allows the hyperlinks to point to more specific parts (fragments)

in the XML document

• XSLT 2.0, W3C Recommendation 23 January 2007

14

Page 14: Repositories and SPARQL

www.sti-innsbruck.at

Why a New Language?

• RDF description (1):

<rdf:Description rdf:about="949318"><rdf:type rdf:resource="&uni;lecturer"/><uni:name>Dieter Fensel</uni:name><uni:title>University Professor</uni:title>

</rdf:Description>

• XPath query:

/rdf:Description[rdf:type="http://www.mydomain.org/uni-ns#lecturer"]/uni:name

15

Page 15: Repositories and SPARQL

www.sti-innsbruck.at

Why a New Language?

• RDF description (2):

<uni:lecturer rdf:about="949318">

<uni:name>Dieter Fensel</uni:name>

<uni:title>University Professor</uni:title>

</uni:lecturer>

• XPath query:

//uni:lecturer/uni:name

16

Page 16: Repositories and SPARQL

www.sti-innsbruck.at

Why a New Language?

• RDF description (3):

<uni:lecturer rdf:about="949318"

uni:name=“Dieter Fensel"

uni:title=“University Professor"/>

• XPath query:

//uni:lecturer/@uni:name

17

Page 17: Repositories and SPARQL

www.sti-innsbruck.at

Why a New Language?

• What is the difference between these three definitions?

• RDF description (1):<rdf:Description rdf:about="949318">

<rdf:type rdf:resource="&uni;lecturer"/><uni:name>Dieter Fensel</uni:name><uni:title>University Professor</uni:title>

</rdf:Description>

• RDF description (2):<uni:lecturer rdf:about="949318">

<uni:name>Dieter Fensel</uni:name><uni:title>University Professor</uni:title>

</uni:lecturer>

• RDF description (3):<uni:lecturer rdf:about="949318"

uni:name=“Dieter Fensel" uni:title=“University Professor"/>

18

Page 18: Repositories and SPARQL

www.sti-innsbruck.at

Why a New Language?

• All three description denote the same thing:#949318, rdf:type, <uni:lecturer>#949318, <uni:name>, “Dieter Fensel”#949318, <uni:title>, “University Professor”

• But the queries are different depending on a the particular serialization:

/rdf:Description[rdf:type="http://www.mydomain.org/uni-ns#lecturer"]/uni:name

//uni:lecturer/uni:name

//uni:lecturer/@uni:name

19

Page 19: Repositories and SPARQL

www.sti-innsbruck.at

TECHNICAL SOLUTION

20

Page 20: Repositories and SPARQL

www.sti-innsbruck.at

RDF REPOSITORIESEfficient storage of RDF data

21

Page 21: Repositories and SPARQL

www.sti-innsbruck.at

Different Architectures

• Based on their implementation, can be divided into 3 broad categories : In-memory, Native, Non-native Non-memory.

• In – Memory : RDF Graph is stored as triples in main –memory. Eg. Storing an RDF graph using Jena API/ Sesame API.

• Native : Persistent storage systems with their own implementation of databases. Eg. Sesame Native, Virtuoso, AllegroGraph, Oracle 11g.

• Non-Native Non-Memory : Persistent storage systems set-up to run on third party DBs. Eg. Jena SDB.

22

Page 22: Repositories and SPARQL

www.sti-innsbruck.at

Implications

• Scalability• Different query languages supported to varying degrees.

– Sesame – SeRQL, Oracle 11g – Own query language.

• Different level of inferencing.– Sesame supports RDFS inference, AllegroGraph – RDFS++,– Oracle 11g – RDFS++, OWL Prime

• Lack of interoperability and portability.– More pronounced in Native stores.

23

Page 23: Repositories and SPARQL

www.sti-innsbruck.at

What is Jena?

• Jena is a complete Java Framework for RDF, DAML and OWL

• Developed HP Labs• Jena supports

– Triple storage– Reasoning

• Current Jena release: 2.5.7• Available at http://jena.sourceforge.net

24

Page 24: Repositories and SPARQL

www.sti-innsbruck.at

Jena’s Architecture

25

The RDF API

ARP

RDF Filter

n-triples

Readers

XML

XML

n-triples

Writers

Mem RDB BDBStores

The DAML API

RDQL

Applications

Jena 1 Architecture

The RDF 2003 API

Ontology API

OWL Full

OWL DL

OWL Lite

DAML+OIL

RDFS

Rule Systems

RDQL

Applications

OWL

RDFS OWL Lite

External reasoners

Fast path query

Reification Event handling

The RDF 2003 API

Jena SPI

[http://jena.sourceforge.net/]

Page 25: Repositories and SPARQL

www.sti-innsbruck.at

Jena SDB

• SDB basically is a Java Loader.• Multiple stores supported: MySQL, PostgreSQL, Oracle,

DB2.• Takes incoming triples and breaks them down into

components ready for the database. • Multiple layouts• Integration with the Joseki server.• SPARQL supported.

26

Page 26: Repositories and SPARQL

www.sti-innsbruck.at

What is Sesame?

• Sesame is an open source Java framework for storing, querying and reasoning with RDF and RDF Schema

• It can be used as:– Standalone Server: A database for RDF and RDF Schema– Java Library: For applications that need to work with RDF

internally

• Sesame is similar to Jena– Supports triple storage– Supports reasoning– Supports Web services

• Available at http://openrdf.org

27

Page 27: Repositories and SPARQL

www.sti-innsbruck.at

Sesame’s Architecture

Repository

Repository Abstraction Layer (RAL)

Admin Module Export ModuleQuery Module

HTTP Protocol Handler SOAP Protocol Handler

Sesa

me

SO

AP

HTTP

Clients Clients

28

Page 28: Repositories and SPARQL

www.sti-innsbruck.at

Sesame’s Repository

• DBMSs– Currently, Sesame is able to use

• PostgreSQL• MySQL• Oracle (9i or newer)

• Existing RDF stores (e.g. Jena)• RDF files• RDF network services

– Using multiple sesame server to retrieve results for queries– This opens up the possibility of a highly distributed architecture

for RDF storing and querying

29

Page 29: Repositories and SPARQL

www.sti-innsbruck.at

Sesame’s Repository Abstraction Layer (RAL)

• RAL offers stable, high-level interface for talking to repositories

• It is defined by an API that offers these functionalities:

– Add data

– Retrieve data

– Delete data

• Data is returned in streams (Scalability)

– Only small amount of data is kept in memory

– Suitable for use in highly constrained environments such as portable

devices

• Caching data (Performance)

– E.g. caching RDF schema data which is needed very frequently

30

Page 30: Repositories and SPARQL

www.sti-innsbruck.at

Sesame’s Admin Module

• Allows inserting or deleting RDF data in repository

• Retrieves its information from an RDF(S) source, and

parses it using an RDF parser

• Checks each (S, P, O) statement for consistency and

infers implied information if necessary for instance:– If P equals type, it infers that O must be a class.

– If P equals subClassOf, it infers that S and O must be classes.

– If P equals subPropertyOf, then it infers that both S and O must be

properties.

– If P equals domain or range, then it infers that S must be a property and

O must be a class

31

Page 31: Repositories and SPARQL

www.sti-innsbruck.at

Sesame’s Query Module

• Evaluates RQL queries posed by the user• It is independent of the underlying repository

– Can not use optimizations and query evaluations offered by specific DBMSs

• RQL queries are translated into a set of calls to the RAL– e.g. when a query contains a join operation over two subqueries,

each of the subqueries is evaluated, and the join operation is then executed by the query engine on the results

32

Page 32: Repositories and SPARQL

www.sti-innsbruck.at

Sesame’s RDF Export Module

• This module allows for the extraction of the complete schema and/or data from a model in RDF format

• It supplies the basis for using Sesame with other RDF tools

33

Page 33: Repositories and SPARQL

www.sti-innsbruck.at

Which RDF store to choose for an app?

• Frequency of loads that the application would perform.• Single scaling factor and linear load times.• Level of inferencing.• Support for which query language. W3C

recommendations.• Special system needs. Eg. Allegograph needs 64 bit

processor.

34

Page 34: Repositories and SPARQL

www.sti-innsbruck.at

SPARQLA language to query RDF data

35

Page 35: Repositories and SPARQL

www.sti-innsbruck.at

Querying RDF

• SPARQL– RDF Query language– Based on RDQL– Uses SQL-like syntax

• Example:PREFIX uni: <http://example.org/uni/>

SELECT ?name

FROM <http://example.org/personal>

WHERE { ?s uni:name ?name.

?s rdf:type uni:lecturer }

36

Page 36: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries

PREFIX uni: <http://example.org/uni/>

SELECT ?name

FROM <http://example.org/personal>

WHERE { ?s uni:name ?name. ?s rdf:type uni:lecturer }

• PREFIX– Prefix mechanism for abbreviating URIs

• SELECT– Identifies the variables to be returned in the query answer– SELECT DISTINCT– SELECT REDUCED

• FROM– Name of the graph to be queried– FROM NAMED

• WHERE– Query pattern as a list of triple patterns

• LIMIT• OFFSET• ORDER BY

37

Page 37: Repositories and SPARQL

www.sti-innsbruck.at

Example RDF Graph

<http://example.org/#john> <http://.../vcard-rdf/3.0#FN> "John Smith“

<http://example.org/#john> <http://.../vcard-rdf/3.0#N> :_X1_:X1 <http://.../vcard-rdf/3.0#Given> "John"_:X1 <http://.../vcard-rdf/3.0#Family> "Smith“

<http://example.org/#john> <http://example.org/#hasAge> "32“

<http://example.org/#john> <http://example.org/#marriedTo> <#mary>

<http://example.org/#mary> <http://.../vcard-rdf/3.0#FN> "Mary Smith“

<http://example.org/#mary> <http://.../vcard-rdf/3.0#N> :_X2_:X2 <http://.../vcard-rdf/3.0#Given> "Mary"_:X2 <http://.../vcard-rdf/3.0#Family> "Smith"

<http://example.org/#mary> <http://example.org/#hasAge> "29"

38

Page 38: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: All Full Names

“Return the full names of all people in the graph”

PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>SELECT ?fullNameWHERE {?x vCard:FN ?fullName}

result:

fullName================="John Smith""Mary Smith"

39

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 39: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Properties

“Return the relation between John and Mary”

PREFIX ex: <http://example.org/#>

SELECT ?p

WHERE {ex:john ?p ex:mary}

result:

p

=================<http://example.org/#marriedTo>

40

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 40: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Complex Patterns

“Return the spouse of a person by the name of John Smith”

PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>

PREFIX ex: <http://example.org/#>

SELECT ?y

WHERE {?x vCard:FN "John Smith".

?x ex:marriedTo ?y}

result:

y

=================<http://example.org/#mary>

41

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 41: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Complex Patterns

“Return the spouse of a person by the name of John Smith”

PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>

PREFIX ex: <http://example.org/#>

SELECT ?y

WHERE {?x vCard:FN "John Smith".

?x ex:marriedTo ?y}

result:

y

=================<http://example.org/#mary>

42

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 42: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Blank Nodes

“Return the first name of all people in the KB”

PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>SELECT ?name, ?firstNameWHERE {?x vCard:N ?name .

?name vCard:Given ?firstName}

result:

name firstName=================_:a "John"

_:b "Mary"

43

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 43: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Blank Nodes

“Return the first name of all people in the KB”

PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>SELECT ?name, ?firstNameWHERE {?x vCard:N ?name .

?name vCard:Given ?firstName}

result:

name firstName=================_:a "John"

_:b "Mary"

44

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 44: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Building RDF Graph

“Rewrite the naming information in original graph by using the foaf:name”

PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>

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

CONSTRUCT { ?x foaf:name ?name }

WHERE { ?x vCard:FN ?name }

result:

#john foaf:name “John Smith"

#marry foaf:name “Marry Smith"

45

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 45: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Building RDF Graph

“Rewrite the naming information in original graph by using the foaf:name”

PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>

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

CONSTRUCT { ?x foaf:name ?name }

WHERE { ?x vCard:FN ?name }

result:

#john foaf:name “John Smith"

#marry foaf:name “Marry Smith"

46

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/“ xmlns:ex="http://example.org“> <rdf:Description rdf:about=ex:john> <foaf:name>John Smith</foaf:name> </rdf:Description> <rdf:Description rdf:about=ex:marry> <foaf:name>Marry Smith</foaf:name> </rdf:Description> </rdf:RDF>

Page 46: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Testing if the Solution Exists

“Are there any married persons in the KB?”

PREFIX ex: <http://example.org/#>

ASK { ?person ex:marriedTo ?spouse }

result:

yes

=================

47

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 47: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Constraints (Filters)

“Return all people over 30 in the KB”

PREFIX ex: <http://example.org/#>

SELECT ?x

WHERE {?x hasAge ?age .

FILTER(?age > 30)}

result:

x

=================<http://example.org/#john>

48

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 48: Repositories and SPARQL

www.sti-innsbruck.at

SPARQL Queries: Optional Patterns

“Return all people and (optionally) their spouse”

PREFIX ex: <http://example.org/#>SELECT ?person, ?spouseWHERE {?person ex:hasAge ?age .OPTIONAL { ?person ex:marriedTo ?spouse } }

result:

?person ?spouse=============================<http://example.org/#mary><http://example.org/#john> <http://example.org/#mary>

49

@prefix ex: <http://example.org/#> .@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> .ex:john vcard:FN "John Smith" ; vcard:N [ vcard:Given "John" ; vcard:Family "Smith" ] ; ex:hasAge 32 ; ex:marriedTo :mary .ex:mary vcard:FN "Mary Smith" ; vcard:N [ vcard:Given "Mary" ; vcard:Family "Smith" ] ; ex:hasAge 29 .

Page 49: Repositories and SPARQL

www.sti-innsbruck.at

ILLUSTRATION BY A LARGER EXAMPLE

An example of usage of SPARQL

59

Page 50: Repositories and SPARQL

www.sti-innsbruck.at

A RDF Graph Modeling Movies

movie1

movie:Movie

“Edward ScissorHands”

“1990”

rdf:type

movie:title

movie:year

movie:Genre

movie:Romance movie:Comed

y

rdf:type rdf:type

movie:genre

movie:genre

movie:Role

“Edward ScissorHands”

r1

actor1movie:playedBy

movie:characterName

rdf:typemovie:hasPart

[http://www.openrdf.org/conferences/eswc2006/Sesame-tutorial-eswc2006.ppt]

60

Page 51: Repositories and SPARQL

www.sti-innsbruck.at

Example Query 1

• Select the movies that has a character called “Edward Scissorhands”

PREFIX movie: <http://example.org/movies/>

SELECT DISTINCT ?x ?tWHERE {

?x movie:title ?t ;movie:hasPart ?y .?y movie:characterName ?z .FILTER (?z = “Edward

Scissorhands”@en) }

61

Page 52: Repositories and SPARQL

www.sti-innsbruck.at

Example Query 2

• Create a graph of actors and relate them to the movies they play in (through a new ‘playsInMovie’ relation)

PREFIX movie: <http://example.org/movies/>PREFIX foaf: <http://xmlns.com/foaf/0.1/>

CONSTRUCT {?x foaf:firstName ?fname.?x foaf:lastName ?lname.?x movie:playInMovie ?m}

WHERE {?m movie:title ?t ;movie:hasPart ?y .?y movie:playedBy ?x .

?x foaf:firstName ?fname.?x foaf:lastName ?lname.

}

62

Page 53: Repositories and SPARQL

www.sti-innsbruck.at

Example Query 3

• Find all movies which share at least one genre with “Gone with the Wind”

PREFIX movie: <http://example.org/movies/>

SELECT DISTINCT ?x2 ?t2WHERE {

?x1 movie:title ?t1.?x1 movie:genre ?g1.?x2 movie:genre ?g2.?x2 movie:title ?t2.FILTER (?t1 = “Gone with the Wind”@en

&&?x1!=?x2 && ?g1=?g2)

}

63

Page 54: Repositories and SPARQL

www.sti-innsbruck.at

EXTENSIONS

64

Page 55: Repositories and SPARQL

www.sti-innsbruck.at

Massive Data Inference in RDF Repositories

• Present common implementations:– Make a number of small queries to propagate the effects of rule

firing.– Each of these queries creates an interaction with the database.– Not very efficient

• Approaches– Snapshot the contents of the database-backed model into RAM

for the duration of processing by the inference engine.– Performing inferencing in-stream.

• Precompute the inference closure of ontology and analyze the in-coming data-streams, add triples to it based on your inference closure.

• Assumes rigid separation of the RDF Data(A-box) and the Ontology data(T-box)

• Even this may not work for very large ontologies – BioMedical Ontologies

65

Page 56: Repositories and SPARQL

www.sti-innsbruck.at

Extending SPARQL

• SPARQL is still under continuous development. Current investigate possible extensions includes:– Better support for OWL semantics– RDF data insert and update– Aggregate functions– Standards XPath functions– Manipulation of Composite Datasets– Access to RDF lists

66

Page 57: Repositories and SPARQL

www.sti-innsbruck.at

WRAP-UPThat’s almost all for day…

67

Page 58: Repositories and SPARQL

www.sti-innsbruck.at

Things to keep in mind(or summary)

• RDF Repositories– Optimized solutions for storing RDF– Adopts different implementation techniques– Choice has to be lead by multiple factors

• In general there is no a solution better than another

• SPARQL– Query language for RDF represented data– More powerful than XPath based languages– Supported by a communication protocol

68

Page 59: Repositories and SPARQL

www.sti-innsbruck.at

Bibliography

• Mandatory reading– Semantic Web Primer

• Chapter 3 (Sections 3.8)– SPARQL Query Language for RDF

• http://www.w3.org/TR/rdf-sparql-query• Chapters 1 to 11

• Further reading– RDF SPARQL Protocol

• http://www.w3.org/TR/rdf-sparql-protocol/

69

Page 60: Repositories and SPARQL

www.sti-innsbruck.at

Next Lecture

70

# Date Title

1 Introduction

2 Semantic Web Architecture

3 RDF and RDF Schema

4 Web of hypertext (RDFa, Microformats) and Web of data

5 Semantic Annotation

6 Repositories and SPARQL

7 The Web Ontology Language

8 Rule Interchange Format

9 Web-scale reasoning

10 Social Semantic Web

11 Ontologies and the Semantic Web

12 Semantic Web Services

13 Tools

14 Applications

15 Exam

Page 61: Repositories and SPARQL

www.sti-innsbruck.at

Questions?

71