Semantic Web RDF Website
Semantic Web RDF Website
What is RDF?
RDF provides a common framework for expressing information so it can be exchanged between applications without loss of meaning. Examples of use:
Describing properties for shopping items, such as price and availability Describing time schedules for web events Describing information about web pages (content, author, created and modified date)
Notation 3 (N3)
Turtle RDF/XML
an XML-based syntax
By using XML, RDF information can easily be exchanged between different types of computers using different types of operating systems and application languages During this course we will use the RDF/XML serialization format
The RDF language is a part of the W3C's Semantic Web Activity W3C's "Semantic Web Vision" is a future where:
Web information has exact meaning Web information can be understood and processed by computers Computers can integrate information from the web
In RDF data sets each triple may belong to a named graph or to the default un-named graph.
RDF identifies things using Web identifiers (URIs), and describes resources with properties and property values
This enables to represent RDF statements about resources as a graph of nodes and arcs representing the resources, and their properties and values
such as "http://www.w3.org/RDF/"
A Property is a Resource that in triples is used to connect the subject with the object
RDF URIs
Unlike conventional hypertext, RDF URIs can refer to any identifiable thing
RDF in addition to describing such things as Web pages can also describe cars, businesses, people, news events, etc.
In addition, RDF properties themselves have URIs, to precisely identify the relationships that exist between the linked items
In RDF is also possible to define resources with unknown URI, this resources are called blank nodes
The following RDF document could describe the resource The example is simplified, rdf namespace is omitted
http://arces.it
<rdf:Description
Specify subject
Subject Predicates Literal object Resource object
rdf:about="http://arces.it">
<author>Mario Rossi</author> <homepage>http://www.unibo.it/home</homepage> </rdf:Description> </rdf:RDF>
http://www.unibo.it/home
http://arces.it
Mario Rossi
RDF Graphs
The underlying structure of any expression in RDF is a collection of triples
RDF Graphs
The direction of the arc is significant: it always points toward the object The nodes of an RDF graph are its subjects and objects The assertion of an RDF triple says that some relationship, indicated by the predicate, holds between the things denoted by subject and object
The meaning of an RDF graph is the conjunction (logical AND) of the statements corresponding to all the triples it contains
As Linked Data URIs are globally unique and can be dereferenced into sets of RDF triples
It is possible to imagine all Linked Data as one giant global graph Linked Data applications operate on top of this giant global graph and retrieve parts of it by dereferencing URIs as required
Blank nodes
<rdf:RDF xmlns=http://ns#> <rdf:Description rdf:about=http://ns#person_A> <know> <rdf:Description> <homePage> <rdf:Description rdf:about=http://ns#PersonB_home.html> </rdf:Description> </homePage> http://ns#fullName> <fullName>John Doe</ex:fullName> </rdf:Description> </know> <fullName>Mario Rossi<full name> </rdf:Description> </rdf:RDF> Mario Rossi http://ns#fullName
http://ns#person_AC
http://ns#know
http://ns#homePage
John Doe
http://ns#person_A
Reification
Syntactic sugar used:
rdf:Statement rdf:subject rdf:predicate rdf:object Given the triple < URI_sub, URI_pred, URI_obj> the reification is operated by creating a statement instance and relating it to the subject, the predicate and the object of the statement to be reified. This allows to have a more abstract view of the knowledge base e.g. giving the possibility to assert that a certain statement is trustable or not. Ntriple syntax for reification _:statement_bn rdf:type rdf:Statement . _: statement_bn rdf:subject < URI_sub > . _: statement_bn rdf:predicate < URI_pred > . _: statement_bn rdf:object < URI_obj > . rdf:subject rdf:predicate URI_pred
URI_sub URI_obj
rdf:type
Rdf:Statement
rdf:object
RDF Example
RDF Example
The first line of the RDF document is the XML declaration The XML declaration is followed by the root element of RDF documents: <rdf:RDF>
The xmlns:rdf namespace, specifies that elements with the rdf prefix are from the namespace "http://www.w3.org/1999/02/22-rdfsyntax-ns#".
The xmlns:cd namespace, specifies that elements with the cd prefix are from the namespace "http://www.recshop.fake/cd#".
The <rdf:Description> element contains the description of the resource identified by the rdf:about attribute
The elements: <cd:artist>, <cd:country>, <cd:company>, etc. are properties of the resource.
RDF Example
The <rdf:Description> element may identify the subject resource with the about attribute
The elements, artist, country, company, price, and year, are defined in the http://www.recshop.fake/cd# namespace
This namespace is outside RDF (and not a part of RDF) The elements, artist, country, company, price, and year, must be defined by someone else (company, organization, person, etc. )
Properties as Attributes
Properties as Resources
In the example, the property cd:artist identifies the object through the rdf:resource attribute
rdf:Bag
rdf:Seq rdf:Alt
Note - We will talk about RDFS (RDF Schema) Vocabulary Description Language later Now let's focus on container elements
The <rdf:Bag> element is a subclass of rdfs:Container It is used to describe a list of values that do not have to be in a specific order It may contain duplicate values
The first member of the container the value of the rdf:_1 property, is the default choice.
RDF Terms
In the previous examples we have talked about "list of values" when describing the container elements In RDF these "values" are called members So, we have the following:
A container is a resource that contains things The contained things are called members
RDF collections are used to describe groups that can ONLY contain the specified members
RDF List
Ordered opened and closed (using rdf:nil ) lists are represented in RDF through
rdf:type rdf:List
W3C references: Primer: http://www.w3.org/TR/2004/REC-rdf-primer-20040210/ Concepts: http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/ Syntax: http://www.w3.org/TR/2004/REC-rdf-syntax-grammar-20040210/ Semantics: http://www.w3.org/TR/2004/REC-rdf-mt-20040210/ Vocabulary: http://www.w3.org/TR/2004/REC-rdf-schema-20040210/ Test Cases: http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/
RDF Schema
RDF is domain-independent
RDF user communities need the ability to define application-specific classes and properties
RDF Schema
RDF Schema
RDF Schema
The resources in the RDF Schema vocabulary have URI references with the namespace
Vocabulary descriptions (schemas) written in the RDF Schema language are legal RDF graphs
RDF software that is not written to also process the additional RDF Schema vocabulary can still interpret a schema as a legal RDF graph consisting of various resources and properties But it will not "understand" the additional built-in meanings of the RDF Schema terms
the class of everything the class of all classes the class of literal values the class of data types the class of rdf containers i.e. rdf:Bag, rdf:Seq, rdf:Alt the class of rdf selectors i.e. the properties rdf:_1, rdf:_2, ...
defines the domain of a property defines the range of a property associates a class with its super-class associates a property with its super-property superproperty of rdf:_1, rdf:_2, etc. associates a resource to a human readable label ssociatres a resource to a human readable description associates a resource to another one which provides additional details associates a resource to another one which provides the definition.
Classes
The rdfs:subClassOf property may be used to state that one class is a subclass of another Example
<rdfs:class rdf:about="person"/>
In order to define a student class as a subclass of the class person, you have to specify the statement: <rdfs:subClassOf rdf:resource="#person"/>
Classes
The class rdfs:Literal is the class of literal values such as strings and integers
All instances of rdfs:Datatype correspond to the RDF model of a datatype rdfs:Datatype is both an instance of and a subclass of rdfs:Class Each instance of rdfs:Datatype is a subclass of rdfs:Literal
Properties
Properties are instances of the class rdf:Property and describe a relation between subject resources and object resources rdfs:range is an instance of rdf:Property that defines the super-class of the values of a property rdfs:domain is an instance of rdf:Property that is used to define the super-class of the possible subjects for a given property
Properties
Example
<rdfs:property rdf:ID="#attends">
<rdfs:domain rdf:domain="#student"> <rdfs:range rdf:range="#course">
</rdfs:property>
The property #attends can be used in statements whose subject belongs to the class #student and whose object belong to he class #course
Containers
The rdfs:Container class is a super-class of the RDF Container classes (discussed earlier)
rdf:Bag
rdf:Seq rdf:Alt
Collections
The RDF Collection vocabulary of classes and properties can describe a closed collection
A collection is represented as a list of items
rdf:List - used to build descriptions of lists and other list-like structures (it is an instance of rdf:Class) rdf:first (it is an instance of rdf:Property) rdf:rest (it is an instance of rdf:Property)
Plenty of resources and tutorial can be found on the web like on W3C site and in http://www.cambridgesemantics.com/semantic-university/sparqlby-example SPARQL queries data represented as an oriented graph: very different from relational databases data model. Usage is simple but the approach of accessing a new data model can be something hard the first times. SPARQL 1.1 is in development, it will add many features to the original specification. Some of its parts are currently supported by major semantic web frameworks like Jena The main resource to learn SPARL grammar is: http://www.w3.org/TR/rdf-sparql-query/#rGraphTerm
SELECT
ASK
CONSTRUCT DESCRIBE
The SPARQL results set can be represented in XML by using the XML schema provided by W3C to wrap the results of SELECT and ASK queries XML is not mandatory but often useful when representing results
Besides the operators defined on graphs is important to understand that the basic expressive unit is that of the triples.
Triples are specified with subject, predicate and object separated by spaces
There are shortcuts to express triples with recurring subjects or object by using ; and ,
; after the subject tell that couples of predicates and objects will follw, sharing the same subject
, after an object tell that another objects will follow sharing the same subject and predicate
IRI are eclosed between < and > Qualified names does't need enclosing characters Strings are double quoted other data types may be not, in general the literals are represented in this way: quoted_literal^^IRI details
SPARQL Examples
Initial knowledge base:
Subject
Predicate
Object
http://ns#uri_0
http://ns#uri_0
http://ns#name
http://ns#home
Alfredo
http://ns/Alf_home.html
http://ns#uri_0
http://ns#uri_0 http://ns#uri_1 http://ns#uri_1 http://ns#uri_1
http://ns#role
http://ns#age http://ns#name http://ns#role http://ns#age
Admin
31 John User 44
SPARQL Examples
SELECT ?a ?b ?c WHERE { ?a ?b ?c } This query defines the variable a, b and c, which in the query must be preceded by ? or $ and then specifies in the WHERE clause the graph pattern against which all the triples will be matched, each triple matching the graph pattern is included in the results. In this case all the triples match so the result will be the entire data set, if we suppose N stated triples:
a http://ns#uri_0 http://ns#uri_0 http://ns#uri_0 b http://ns#name http://ns#home http://ns#role c Alfredo http://ns/Alf_home.html Admin
http://ns#uri_0
http://ns#uri_1 http://ns#uri_1 http://ns#uri_1
http://ns#age
http://ns#name http://ns#role http://ns#age
31
John User 44
SPARQL Examples
SELECT ?a WHERE { ?a ?b ?c } variables in the SELECT clause are the ones included in the result set
SPARQL Examples
The triples in the WHERE clause are considered in a conjunctive way by default: SELECT ?a ?b ?c WHERE { ?a ?b ?c . ?a <http://ns#name> ?c}
a http://ns#uri_0 http://ns#uri_1
b http://ns#name http://ns#name
c Alfredo John
SPARQL Examples
Disjunction is obtained through the UNION pattern SELECT ?a ?c WHERE { { ?a <http://ns#age> ?c } UNION { ?a <http://ns#name> ?c } }
a c
http://ns#uri_0
http://ns#uri_0 http://ns#uri_1 http://ns#uri_1
Alfredo
31 John 44
SPARQL Examples
SPARQL Examples
Optional patterns can be specified with the OPTIONAL keyword SELECT ?a ?c ?d WHERE { { ?a <http://ns#age> ?c } UNION { ?a <http://ns#name> ?c} . OPTIONAL { ?a <http://ns#home> ?d } }
a http://ns#uri_0 http://ns#uri_0 http://ns#uri_1 c Alfredo 31 John d http://ns/Alf_home.html http://ns/Alf_home.html
http://ns#uri_1
44
SPARQL Examples
ASK queries are used to receive the information if at least one solution exists for the specified patterns ASK WHERE { { ?a <http://ns#age> ?c } UNION { ?a <http://ns#name> ?b } }
SPARQL Examples
CONSTRUCT queries specifies at least two graph patterns: one is a template in which are present variables, like in a WHERE clause, but the data set is not queried against this graph pattern. The second is a normal WHERE clause. What happens is that the data are queried against the WHERE clause and the value of the variables, for each solution, are substituted into the template and the resulting graph (template with substituted values) is returned as a query answer.
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j.0="http://ns#"> <rdf:Description rdf:about="http://ns/Alf_home.html"> <j.0:home_belong_to rdf:resource="http://ns#uri_0" /> </rdf:Description> </rdf:RDF>
SPARQL Examples
DESCRIBE queries return an RDF graph representing a description of the specified resource.
The description is built using the rules decided by the SPARQL end point manager, there is no standard defining it
DESCRIBE <http://ns#uri_0>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j.0="http://ns#"> <rdf:Description rdf:about="http://ns#subj0"> <j.0:home>http://ns#Alf_home.html</j.0:home> <j.0:role>Admin</j.0:role> <j.0:age>31</j.0:age> <j.0:name>Alfredo</j.0:name> </rdf:Description> </rdf:RDF>
SPARQL Examples
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j.0="http://ns#"> <rdf:Description rdf:about="http://ns#uri_1"> <j.0:role>User</j.0:role> <j.0:age>44</j.0:age> <j.0:name>John</j.0:name> </rdf:Description> <rdf:Description rdf:about="http://ns#uri_0"> <j.0:home>http://ns/Alf_home.html</j.0:home> <j.0:role>Admin</j.0:role> <j.0:age>31</j.0:age> <j.0:name>Alfredo</j.0:name> </rdf:Description> </rdf:RDF>
SPARQL
Other samples
I want URI and age only for that URI with an associated home
a http://ns#uri_0
b 31
SPARQL
Aggregates and Groups: a SPARQL 1.1 query feature (not standardized yet) We add to the knowledge base:
Subject Predicate Object
http://ns#uri_2
http://ns#uri_2
http://ns#name
http://ns#role
Mark
User
SPARQL
Negation: Many possible approaches such as I want URI and name only for that URI without an associated home. This solution is valid in standard SPARQL
OPTIONAL + !BOUND : Select ?a ?c Where { ?a <http://ns#name> ?c . Optional { ?a <http://ns#home> ?b } . Filter (!Bound(?b)) } a http://ns#uri_1 http://ns#uri_2 c John Mark
Same objective and result, but with a feature of SPARQL 1.1 Query language Not exists: Select ?a ?c Where { ?a <http://ns#name> ?c . Filter not exists { ?a <http://ns#home> ?b } } a http://ns#uri_1 http://ns#uri_2 c John Mark
SPARQL
In this short tutorial we will not investigate the support for other features of SPARQL among them the named graphs for which clear documentation can be found in the main documentation page. This because SIB versions currently doesn't support natively them, so it is difficult to verify in concrete applications during the course http://www.w3.org/TR/rdf-sparql-query/
RDF Summary
RDF also allows for the re-use, extendibility and refinement of established resource description standards since these will be available in machinereadable form
Using RDFS it is for example possible to create hierarchies of classes and properties RDF knowledge bases can be queried using the SPARQL language.
Acknowledgments
This tutorial is based on the material developed within RECOCAPE, an FP7 international cooperation project of the capacities programme.