Semantic Semantic Web Web Information Information Management Management

steelsquareInternet and Web Development

Oct 20, 2013 (3 years and 11 months ago)

88 views

Semantic Web Information
Semantic Web Information
Management
Management
Norberto Fernández
Norberto Fernández
Telematics Engineering Department
Telematics Engineering Department
berto@ it.uc3m.es
berto@ it.uc3m.es
1
GIMI / MIMI - 2009/2010Motivation
Motivation
n Module 1: An ontologymodels a domain of
n Module 1: An ontologymodels a domain of
knowledge…
knowledge…
n Module 2: … using the ontology as vocabulary,
n
Module 2: … using the ontology as vocabulary,
we represent (meta)data in RDF…
we represent (meta)data in RDF…
n …, OK, so we have tons of triples representing
n …, OK, so we have tons of triples representing
all our information: What do we do with them?
all our information: What do we do with them?
nn RDF storage
RDF storage
Semantic Web Information management
n RDF querying
n RDF querying
2
GIMI / MIMI - 2009/2010Introduction
Introduction
n Module 3: Semantic Web information
n Module 3: Semantic Web information
management
management
nn RDF querying
RDF querying
nn W We e w wi il ll l s se ee e t th hi is s i in n t th he eo or re et ti ic ca al l l le es ss so on ns s
n SPARQL: http://www.w3.org/TR/rdf-sparql-query/
n SPARQL: http://www.w3.org/TR/rdf-sparql-query/
n RDF storage
n
RDF storage
n We will see this mainlyin lab
n We will see this mainlyin lab
nn Jena: http://jena.sourceforge.net/
Jena: http://jena.sourceforge.net/
GIMI / MIMI - 2009/2010 3RDF Querying
RDF Querying
GIMI / MIMI - 2009/2010 4Query Languages for RDF
Query Languages for RDF
n Several proposals out there…
n Several proposals out there…
n RDQL, Triple, SeRQL, RQL, RDFQL, N3, etc.
n RDQL, Triple, SeRQL, RQL, RDFQL, N3, etc.
n http://www.aifb.uni-karlsruhe.de/WBS/pha/rdf-query/
n http://www.aifb.uni-karlsruhe.de/WBS/pha/rdf-query/
n But nowadays there is also a W3C
n But nowadays there is also a W3C
recommendation: SPARQL
recommendation: SPARQL
GIMI / MIMI - 2009/2010 5SPARQL
SPARQL
n Pronounced “sparkle”
n Pronounced “sparkle”
nn Formerlyan acronym:
Formerlyan acronym:
n SPARQL Protocol And RDF Query Language
n SPARQL Protocol And RDF Query Language
n Defined by the RDF Data Access Working Group of
n Defined by the RDF Data Access Working Group of
the W3C
the W3C
nn Three related specifications:
Three related specifications:
n SPARQL Query Language for RDF
n SPARQL Query Language for RDF
n Query language
n Query language
n SPARQL Protocol for RDF
n SPARQL Protocol for RDF
n Protocol to access SPARQL endpoints
n Protocol to access SPARQL endpoints
n SPARQL Query Results XML Format
n SPARQL Query Results XML Format
n Representing query results in XML
n Representing query results in XML
n W3C recommendations since January2008
n W3C recommendations since January2008
GIMI / MIMI - 2009/2010 6SPARQL Syntax: IRIs (I)
SPARQL Syntax: IRIs (I)
n Subset of URIs used in SPARQL queries as
n Subset of URIs used in SPARQL queries as
resources references
resources references
n RDF URI references containing "<", ">",
n
RDF URI references containing "<", ">",
double quote, space, "{ ", "} ", "|", "\", "^", and
double quote, space, "{ ", "} ", "|", "\", "^", and
"`" are not IRIs
"`" are not IRIs
n The behavior of a SPARQL queryagainst RDF
n
The behavior of a SPARQL queryagainst RDF
statements composed of such RDF URI
statements composed of such RDF URI
references is not defined
references is not defined
GIMI / MIMI - 2009/2010 7SPARQL Syntax: IRIs (II)
SPARQL Syntax: IRIs (II)
n Three mechanisms to represents IRIs:
n Three mechanisms to represents IRIs:
Absolute IRI
Relative IRI
Prefixed name
GIMI / MIMI - 2009/2010 8SPARQL Syntax: Variables
SPARQL Syntax: Variables
n Most forms of SPARQL querycontain a set of
n Most forms of SPARQL querycontain a set of
triple patterns called a basic graphpattern.
triple patterns called a basic graphpattern.
Triple patterns are like RDF triples except that
Triple patterns are like RDF triples except that
each of the subject, predicate and object may be
each of the subject, predicate and object may be
a variable
a variable
n Use ? Or $ to denote variables
n Use ? Or $ to denote variables
Variable
n Example:
n Example:
Basic graph pattern (in this case, simply a triple pattern)
GIMI / MIMI - 2009/2010 9SPARQL Syntax: Literals
SPARQL Syntax: Literals
nn Sometimes literals are included as part of SPARQL
Sometimes literals are included as part of SPARQL
queries
queries
n Literal syntax:
n Literal syntax:
nn "chat" (a string)
"chat" (a string)
n 'chat'@ fr (a string with language tag "fr")
n 'chat'@ fr (a string with language tag "fr")
nn "xyz"^^http://example.org/ns/userDatatype (user datatype)
"xyz"^^http://example.org/ns/userDatatype (user datatype)
n "abc"^^appNS:appDataType (another user datatype)
n "abc"^^appNS:appDataType (another user datatype)
n 1, which is the same as "1"^^xsd:integer
n 1, which is the same as "1"^^xsd:integer
nn 1.300, which is the same as "1.300"^^xsd:decimal
1.300, which is the same as "1.300"^^xsd:decimal
n 1.0e6, which is the same as "1.0e6"^^xsd:double
n 1.0e6, which is the same as "1.0e6"^^xsd:double
n true, which is the same as "true"^^xsd:boolean
n true, which is the same as "true"^^xsd:boolean
GIMI / MIMI - 2009/2010 10SPARQL Syntax: Hello World query
SPARQL Syntax: Hello World query
Data
SPARQL Query
Results
Basic graph pattern
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 11SPARQL: Another example
SPARQL: Another example
RDF Data
(N3 format)
SPARQL query
Results
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 12SPARQL: Queries with literals
SPARQL: Queries with literals
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 13SPARQL: Abbreviations
SPARQL: Abbreviations
n Predicate-object lists
n Predicate-object lists
n For triples with the same subject
n For triples with the same subject
n Object lists
n Object lists
n For triples with the same subject and predicate
n For triples with the same subject and predicate
n Abbreviation for rdf:typeà a
n Abbreviation for rdf:typeà a
GIMI / MIMI - 2009/2010 14SPARQL: Restrictions (Filters)
SPARQL: Restrictions (Filters)
n SPARQL FILTERs restrict solutions to those
n SPARQL FILTERs restrict solutions to those
for which the filter expression evaluates to
for which the filter expression evaluates to
TRUE
TRUE
n Filters can use functions (like regex or lang)
n Filters can use functions (like regex or lang)
and operators:
and operators:
nn =, !=, <, <=, >=, >, &&, ||
=, !=, <, <=, >=, >, &&, ||
nn Restriction on solutions over the whole group of
Restriction on solutions over the whole group of
graph patterns in which the filter appears
graph patterns in which the filter appears
n The order of the filter in the group does not matter
n The order of the filter in the group does not matter
GIMI / MIMI - 2009/2010 15SPARQL: Filters (I)
SPARQL: Filters (I)
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 16SPARQL: Filters (II)
SPARQL: Filters (II)
n Filtering using regular expresions (regex)
n Filtering using regular expresions (regex)
n Works for string literals without language tag. In
n Works for string literals without language tag. In
order to be used with other literalsà function str
order to be used with other literalsà function str
GIMI / MIMI - 2008/2009 17SPARQL: Filters (III)
SPARQL: Filters (III)
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 18SPARQL: Optional (I)
SPARQL: Optional (I)
n Regular, complete structures cannot be assumed
n Regular, complete structures cannot be assumed
in all RDF graphs
in all RDF graphs
nn It is useful to be able to have queries that allow
It is useful to be able to have queries that allow
information to be added to the solution where
information to be added to the solution where
the information is available, but do not reject the
the information is available, but do not reject the
solution because some part of the querypattern
solution because some part of the querypattern
does not match à Optional matching
does not match à Optional matching
n A graph pattern may have zero or more optional
n A graph pattern may have zero or more optional
graph patterns
graph patterns
GIMI / MIMI - 2009/2010 19SPARQL: Optional (II)
SPARQL: Optional (II)
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 20SPARQL: Union (I)
SPARQL: Union (I)
n SPARQL provides a means of combining graph
n SPARQL provides a means of combining graph
patterns so that one of several alternative graph
patterns so that one of several alternative graph
patterns may match
patterns may match
n If more than one of the alternatives matches, all
n If more than one of the alternatives matches, all
the possible pattern solutions are found
the possible pattern solutions are found
n Alternative graph patterns are represented with
n
Alternative graph patterns are represented with
the keyword union
the keyword union
GIMI / MIMI - 2009/2010 21SPARQL: Union (II)
SPARQL: Union (II)
Source:
http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 22Specifying the RDF Dataset (I)
Specifying the RDF Dataset (I)
n ManyRDF data stores hold multiple RDF
n ManyRDF data stores hold multiple RDF
graphs and record information about each
graphs and record information about each
graph, allowing an application to make queries
graph, allowing an application to make queries
that involve information from more than one
that involve information from more than one
graph
graph
nn A SPARQL querymay specifythe dataset to be
A SPARQL querymay specifythe dataset to be
used for matching by using the FROM clause
used for matching by using the FROM clause
and the FROM NAMED clause
and the FROM NAMED clause
GIMI / MIMI - 2009/2010 23Specifying the RDF Dataset (II)
Specifying the RDF Dataset (II)
n FROM
n FROM
n An optional clause that provides the URI of the
n An optional clause that provides the URI of the
dataset to use, pointing to a local file or a URL of a
dataset to use, pointing to a local file or a URL of a
graph somewhere on the Web
graph somewhere on the Web
n FROM NAMED
n FROM NAMED
n Loads a graph and gives it a name (an IRI)
n Loads a graph and gives it a name (an IRI)
n This name can be accessed from queries using
n This name can be accessed from queries using
GRAPH
GRAPH
GIMI / MIMI - 2009/2010 24Specifying the RDF Dataset (III)
Specifying the RDF Dataset (III)
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 25SPARQL: Order By
SPARQL: Order By
n Establishes the order of a solution sequence
n Establishes the order of a solution sequence
n ASC() or DESC()
n ASC() or DESC()
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 26SPARQL: Distinct
SPARQL: Distinct
n Eliminates duplicate solutions
n Eliminates duplicate solutions
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 27SPARQL: Limit
SPARQL: Limit
n Puts an upper bound on the number of
n Puts an upper bound on the number of
solutions returned
solutions returned
n A LIMIT of 0 would cause no results to be
n
A LIMIT of 0 would cause no results to be
returned. A limit may not be negative
returned. A limit may not be negative
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 28SPARQL: Offset
SPARQL: Offset
n Causes the solutions generated to start after the
n
Causes the solutions generated to start after the
specified number of solutions
specified number of solutions
n An OFFSET of zero has no effect
n An OFFSET of zero has no effect
n Using LIMIT and OFFSET requires the order
n Using LIMIT and OFFSET requires the order
to be made predictable by using ORDER BY
to be made predictable by using ORDER BY
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 29SPARQL: Construct (I)
SPARQL: Construct (I)
n CONSTRUCT
n CONSTRUCT
n The CONSTRUCT query form returns a single
n The CONSTRUCT query form returns a single
RDF graph specified by a graph template. The result
RDF graph specified by a graph template. The result
is an RDF graph formed by taking each query
is an RDF graph formed by taking each query
solution in the solution sequence, substituting for
solution in the solution sequence, substituting for
the variables in the graph template, and combining
the variables in the graph template, and combining
the triples into a single RDF graph by set union
the triples into a single RDF graph by set union
GIMI / MIMI - 2009/2010 30SPARQL: Construct (II)
SPARQL: Construct (II)
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 31SPARQL: Ask (I)
SPARQL: Ask (I)
n ASK
n ASK
n Applications can use the ASK query form to test
n Applications can use the ASK query form to test
whether or not a query pattern has a solution. No
whether or not a query pattern has a solution. No
information is returned about the possible query
information is returned about the possible query
solutions, just whether or not a solution exists
solutions, just whether or not a solution exists
nn The result is thus “yes”/“no”
The result is thus “yes”/“no”
GIMI / MIMI - 2009/2010 32SPARQL: Ask (II)
SPARQL: Ask (II)
Source: http://www.w3.org/TR/rdf-sparql-query/
GIMI / MIMI - 2009/2010 33SPARQL Protocol for RDF
SPARQL Protocol for RDF
n Defines the protocol for issuing SPARQL
n Defines the protocol for issuing SPARQL
queries over remote repositories and receiving
queries over remote repositories and receiving
the results
the results
n Defined using WSDL (as a Web Service)
n Defined using WSDL (as a Web Service)
nn The service contains one interface, SparqlQuery,
The service contains one interface, SparqlQuery,
which contains one operation, query
which contains one operation, query
nn Bindings to HTTP and to SOAP are also defined
Bindings to HTTP and to SOAP are also defined
GIMI / MIMI - 2009/2010 34SPARQL Protocol for RDF
SPARQL Protocol for RDF
n The queryoperation…
n
The queryoperation…
nn … receives a query-request message that contains
… receives a query-request message that contains
the query in SPARQL (a string) and information
the query in SPARQL (a string) and information
about the RDF datasets where the query is
about the RDF datasets where the query is
performed (default-graph-uri, named-graph-uri)
performed (default-graph-uri, named-graph-uri)
n … returns a query-result message that contains..
n … returns a query-result message that contains..
nn SELECT and ASK queriesà a result set represented as
SELECT and ASK queriesà a result set represented as
an SPARQL results document in XML format (see next)
an SPARQL results document in XML format (see next)
n CONSTRUCT queriesà an RDF document
n CONSTRUCT queriesà an RDF document
n Faults are also defined
n Faults are also defined
nn malformed-query, query-request-refused
malformed-query, query-request-refused
GIMI / MIMI - 2009/2010 35SPARQL Query Results XML
SPARQL Query Results XML
Format
Format
n Defines an XML document format for
n Defines an XML document format for
representing the results of SPARQL SELECT
representing the results of SPARQL SELECT
and ASK queries
and ASK queries
n Three parts:
n Three parts:
nn Sparql element
Sparql element
n Header
n Header
nn Results
Results
GIMI / MIMI - 2009/2010 36Source: http://www.w3.org/TR/rdf-sparql-XMLres/
GIMI / MIMI - 2009/2010 37Implementations
Implementations
n Implementations
n Implementations
n A list of related tools (clients, servers, parsers, …)
n A list of related tools (clients, servers, parsers, …)
n http://esw.w3.org/topic/SparqlImplementations
n http://esw.w3.org/topic/SparqlImplementations
n In the lab session we will use Jena with ARQ
n In the lab session we will use Jena with ARQ
n http://jena.sourceforge.net/ARQ/
n http://jena.sourceforge.net/ARQ/
GIMI / MIMI - 2009/2010 38Applications
Applications
n SPARQL Endpoints:
n SPARQL Endpoints:
n DBLP: http://dblp.l3s.de/d2r/
n DBLP: http://dblp.l3s.de/d2r/
n DBPedia: http://dbpedia.org/sparql
n DBPedia: http://dbpedia.org/sparql
n Garlik.com
n Garlik.com
n DataPatrol: reports on personal information online
n DataPatrol: reports on personal information online
n Uses SPARQL to build the reports
n Uses SPARQL to build the reports
n Thousands of users
n Thousands of users
n Billion triples in several repositories
n Billion triples in several repositories
n Reports generated in fewseconds
n Reports generated in fewseconds
GIMI / MIMI - 2009/2010 39RDF Storage
RDF Storage
GIMI / MIMI - 2009/2010 40Approaches to store RDF (I)
Approaches to store RDF (I)
n Howdo we store the RDF triples in a relational
n Howdo we store the RDF triples in a relational
database?
database?
n Triple store
n
Triple store
n Each RDF statement is stored as a single row in a
n Each RDF statement is stored as a single row in a
three column 'statement' table
three column 'statement' table
nn Typically, a fourth column is added to indicate if the
Typically, a fourth column is added to indicate if the
object is a literal or a URI
object is a literal or a URI
GIMI / MIMI - 2009/2010 41Approaches to store RDF (II)
Approaches to store RDF (II)
n Normalized triple store
n Normalized triple store
n Triple store plus two additional tables:
n Triple store plus two additional tables:
n Resources table
n Resources table
nn Literals table
Literals table
n The statement table stores the subject, predicate and
n The statement table stores the subject, predicate and
object as references to the values in the resources
object as references to the values in the resources
and literals tables
and literals tables
n Less space (each literal or URI stored only once)
n
Less space (each literal or URI stored only once)
nn But complex queries (3-way join among the tables)
But complex queries (3-way join among the tables)
n Jena 1 uses this approach
n Jena 1 uses this approach
GIMI / MIMI - 2009/2010 42Approaches to store RDF (III)
Approaches to store RDF (III)
n Denormalized triple store
n Denormalized triple store
n Hybrid of the standard triple store and the
n Hybrid of the standard triple store and the
normalized triple store
normalized triple store
n Three tables (statements, literals, resources)
n Three tables (statements, literals, resources)
n Short URIs/literals are directly stored in the
n Short URIs/literals are directly stored in the
statements table, long ones in the respective tables
statements table, long ones in the respective tables
n A threshold defines “long” vs “short” (Jena 2: 256)
n A threshold defines “long” vs “short” (Jena 2: 256)
n More space than normalized
n More space than normalized
nn But in several cases the queries can be directly solved
But in several cases the queries can be directly solved
using only the information in the statements table
using only the information in the statements table
nn Used by Jena 2
Used by Jena 2
GIMI / MIMI - 2009/2010 43References (I)
References (I)
nn SPARQL Query Language for RDF
SPARQL Query Language for RDF
n W3C Recommendation 15 January 2008
n W3C Recommendation 15 January 2008
nn http://www.w3.org/TR/rdf-sparql-query/
http://www.w3.org/TR/rdf-sparql-query/
n SPARQL Protocol for RDF
n SPARQL Protocol for RDF
nn W3C Recommendation 15 January 2008
W3C Recommendation 15 January 2008
n http://www.w3.org/TR/rdf-sparql-protocol/
n http://www.w3.org/TR/rdf-sparql-protocol/
n SPARQL Query Results XML Format
n SPARQL Query Results XML Format
n W3C Recommendation 15 January 2008
n W3C Recommendation 15 January 2008
n http://www.w3.org/TR/rdf-sparql-XMLres/
n http://www.w3.org/TR/rdf-sparql-XMLres/
nn Jena2 Database Interface - Database Layout
Jena2 Database Interface - Database Layout
n http://jena.sourceforge.net/DB/layout.html
n http://jena.sourceforge.net/DB/layout.html
GIMI / MIMI - 2009/2010 44References (II)
References (II)
n Semantics and Complexity of SPARQL
n Semantics and Complexity of SPARQL
n ISWC 2006: J. Perez, M. Arenas, C. Gutierrez
n ISWC 2006: J. Perez, M. Arenas, C. Gutierrez
n http://arxiv.org/abs/cs.DB/0605124
n http://arxiv.org/abs/cs.DB/0605124
nn SPARQL - Where are we? Current state, theory and
SPARQL - Where are we? Current state, theory and
practice
practice
n ESWC 2007 Tutorial
n ESWC 2007 Tutorial
n http://axel.deri.ie/~axepol/sparqltutorial/
n http://axel.deri.ie/~axepol/sparqltutorial/
nn SPARQL Tutorial
SPARQL Tutorial
n Jena @ sourceforge
n Jena @ sourceforge
n http://jena.sourceforge.net/ARQ/Tutorial/
n http://jena.sourceforge.net/ARQ/Tutorial/
GIMI / MIMI - 2009/2010 45