0% found this document useful (0 votes)
56 views

Semantic Web RDF Website

The document discusses RDF (Resource Description Framework), which is a framework for describing resources on the web in a way that is readable by computers. It describes RDF as a data model where resources are identified by URIs and information is stored as subject-predicate-object statements. These statements can be represented as a graph. The document provides examples of using RDF to describe resources and properties, and defines key RDF concepts like URIs, properties, and containers. It also discusses RDF serialization formats and how RDF fits into the semantic web.

Uploaded by

gustavicich
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Semantic Web RDF Website

The document discusses RDF (Resource Description Framework), which is a framework for describing resources on the web in a way that is readable by computers. It describes RDF as a data model where resources are identified by URIs and information is stored as subject-predicate-object statements. These statements can be represented as a graph. The document provides examples of using RDF to describe resources and properties, and defines key RDF concepts like URIs, properties, and containers. It also discusses RDF serialization formats and how RDF fits into the semantic web.

Uploaded by

gustavicich
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Interoperability of Embedded Systems Introduction to Semantic Web technologies

Postgraduate Degree in Information Engineering

Adding and querying semantics: RDF/RDFS and SPARQL


Outline Introduction Data model Syntax
Statements, properties attributes and containers

RDFS: RDF Schema Short SPARQL tutorial

What is RDF?

RDF stands for Resource Description Framework

RDF is a framework for describing resources on the web


RDF is designed to be read and understood by computers RDF is not designed for being displayed to people

RDF is a part of the W3C's Semantic Web Activity


RDF is a W3C Recommendation since 2004

RDF - Examples of Use

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)

Describing content and rating for web pictures


Describing content for search engines Describing electronic libraries ...

RDF is Written in XML?

RDF is a data model

Resources are identified using URIs


Information is a set of statements (subject - predicate object)

Subject and predicate are always resources (i.e. identified by URIs)


Objects may be URIs or literal

Every RDF document corresponds to an oriented and labeled graph

RDF can be Written in XML

Many serialization formats exist for the RDF data model:

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

RDF and "The Semantic Web"

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

RDF is a W3C Recommendation

RDF became a W3C Recommendation on February 2004

RDF documents consists of set of triples defining a knowledge base

Each triple have a subject a predicate and an object

In RDF data sets each triple may belong to a named graph or to the default un-named graph.

RDF Resource, Property, and Property Value

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

A Resource is anything identified by a URI

such as "http://www.w3.org/RDF/"

A Property is a Resource that in triples is used to connect the subject with the object

such as "http://example.org#author" or "http://www.example.com/homepage"

A Property value is the value of a Property

A literal such as Mario Rossi Or a resurce lice http://www.arces.unibo.it"

RDF URIs

Unlike conventional hypertext, RDF URIs can refer to any identifiable thing

including things that may not be directly retrievable on the Web

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

RDF Resource, Property, and Property Value

The following RDF document could describe the resource The example is simplified, rdf namespace is omitted

http://arces.it

<?xml version="1.0"?> <rdf:RDF xmlns=http://example.org#>

RDF document and default namespace A set of statements begin

<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

each consisting of a subject, a predicate and an object

A set of such triples form an RDF graph


This can be illustrated by a node and directed-arc diagram in which each triple is represented as a node-arc-node link

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

RDF Global Graph

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

Merging is a very powerful feature of RDF

Metadata may be defined by several (independent) parties and combined by an application

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

Suppose we have two records from a CD-list:

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 graphical view of the RDF document:

The <rdf:RDF> Element

<rdf:RDF> is the root element of an RDF document

It defines the XML document to be an RDF document


It also contains a reference to the RDF namespace:

The <rdf:Description> Element

The <rdf:Description> element may identify the subject resource with the about attribute

It contains statements that describe the subject

The <rdf:Description> Element

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

The property elements can also be defined as predicates

Properties as Resources

The statements objects can also be existing resources

In the example, the property cd:artist identifies the object through the rdf:resource attribute

The RDF Container Element

RDF Container classes:

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

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 <rdf:Seq> Element

The <rdf:Seq> element is a subclass of rdfs:Container

It is used to describe an ordered list of values

(for example in alphabetical order)

It may contain duplicate values

The <rdf:Alt> Element

It is used to describe a list of alternative values

the user is supposed to select only one of the 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

The rdf:parseType="Collection" Attribute

A container says that the containing resources are members

it does not say that other members are not allowed

RDF collections are used to describe groups that can ONLY contain the specified members

A collection is described by the attribute rdf:parseType="Collection"

The rdf:parseType="Collection" Attribute

RDF List
Ordered opened and closed (using rdf:nil ) lists are represented in RDF through

rdf:List rdf:first rdf:rest rdf:nil

The example below represents the ordered and closed list 3, 2, 1.


3 rdf:first rdf:rest _b1 _b2 rdf:rest _b3 rdf:rest rdf:nil 2 1

rdf:type rdf:List

RDF Schema (RDFS)


RDF Schema (RDFS) is an extension to RDF

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 describes resources with properties, and values

RDF is domain-independent
RDF user communities need the ability to define application-specific classes and properties

RDF Schema provides a mechanism for describing specific domains

RDF Schema

RDF Schema

variously abbreviated as RDFS, RDF(S), RDF-S, or RDF/S


is a set of classes and properties provides basic elements for the description of ontologies, otherwise called RDF vocabularies, intended to structure RDF resources RDF Schema provides a type system for RDF

RDF Schema

The resources in the RDF Schema vocabulary have URI references with the namespace

http://www.w3.org/2000/01/rdf-schema# conventionally associated with the prefix rdfs:

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

RDFS schema vocabulary: classes


Classes describe abstract concepts or categories or set to which individual may belong. An individual is bound to the classes it belongs to through the rdf:type property

rdfs:Resource: rdfs:Class: rdfs:Literal: rdfs:Datatype: rdfs:Container: rdfs:ContainerMembershipProperty:

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, ...

RDFS schema vocabulary: properties


Properties are relationships defined in the domain terminology and used to specify domain assertions in the form of triples. Properties are represented as labeled arcs when drawing of an RDF documents and the are always oriented towards the statement object

rdfs:domain: rdfs:range: rdfs:subClassOf: rdfs:subPropetyOf: rdfs:member: rdfs:label: rdfs:comment: rdfs:seeAlso: rdfs:isDefinedBy:

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

rdfs:Literal is an instance of rdfs:Class


rdfs:Literal is a subclass of rdfs:Resource

rdfs:Datatype is the class of datatypes

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

RDF containers are resources that are used to represent collections

The rdfs:Container class is a super-class of the RDF Container classes (discussed earlier)

rdf:Bag
rdf:Seq rdf:Alt

Collections

RDF containers are open

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)

rdf:nil (it is an instance of rdf:Property)

Short SPARQL tutorial

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

Short SPARQL tutorial

A SPARQL Query is pure text.


Queries can be classified in

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

The WHERE Clause

The WHERE clause is the most important to be understood.


It contains an abstract description of a graph called GroupGraphPattern in the official grammar description

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

The WHERE Clause


Triples are separated by .

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

The WHERE Clause

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

Details in the suggested internet address

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

a http://ns#uri_0 http://ns#uri_0 http://ns#uri_0 http://ns#uri_0 http://ns#uri_1 http://ns#uri_1 http://ns#uri_1

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

Filtering is used to restrict the admitted values of literals


SELECT ?a ?c WHERE { { ?a <http://ns#age> ?c } UNION { ?a <http://ns#name> ?c . FILTER regex(?c, John ) } } Many filtering options available, read documentation for detail
a http://ns#uri_0 http://ns#uri_0 http://ns#uri_1 http://ns#uri_1 c Alfredo 31 John 44

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 xmlns="http://www.w3.org/2005/sparql-results#"> <head> </head> <boolean>true</boolean> </sparql>

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.

Construct { ?a <http://ns#home_belong_to> ?c } WHERE { { ?c <http://ns#home> ?a }

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

This is a possible response (by ARQ libraries)

<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

DESCRIBE ?x WHERE { ?x <http://ns#name> ?y }


This is a possible response (by ARQ libraries)

<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

Subquery: a SPARQL 1.1 query feature (not standardized yet)


Select ?a ?b where { ?a <http://ns#age> ?b . { Select ?a Where { ?a <http://ns#home> ?c } } }

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

Select (SUM(STRLEN(?b)) as ?RolesLenght) where { ?a <http://ns#role> ?b } Having ( SUM(STRLEN(?b)) >0 )


RolesLenght 13 The response is a single group of results on which the functions STRLEN and SUM are Applied.

Select (SUM(STRLEN(?b)) as ?RolesLenght) where { ?a <http://ns#role> ?b } Group by ?b Having ( SUM(STRLEN(?b)) >0 )


RolesLenght 8 5 The response is made up of as many groups as the number of different roles. The STRLEN and SUM functions are applied separately on each group

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 Schema (RDFS) provides basic vocabulary for RDF

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.

You might also like