0% found this document useful (0 votes)
26 views140 pages

Chapter 5 Semantic Web

The Semantic Web is an extension of the current web that enables machines to understand the meaning of information, facilitating better cooperation between humans and computers. It utilizes various technologies and standards, such as RDF, OWL, and SPARQL, to provide a framework for sharing and reusing data across different applications. The initiative aims to address issues of data accessibility and interoperability by separating content from presentation and establishing shared semantics for web resources.

Uploaded by

elatan72112
Copyright
© © All Rights Reserved
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)
26 views140 pages

Chapter 5 Semantic Web

The Semantic Web is an extension of the current web that enables machines to understand the meaning of information, facilitating better cooperation between humans and computers. It utilizes various technologies and standards, such as RDF, OWL, and SPARQL, to provide a framework for sharing and reusing data across different applications. The initiative aims to address issues of data accessibility and interoperability by separating content from presentation and establishing shared semantics for web resources.

Uploaded by

elatan72112
Copyright
© © All Rights Reserved
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/ 140

Chapter 5 Semantic Web

What is the Semantic Web?


• The Semantic Web is not a separate web but an extension of the current one,
in which information is given well-defined meaning, better enabling computers
and people to work in cooperation.
• “The Semantic Web is a Web of actionable information- information derived
from data through a semantic theory for interpreting the symbols.”
• “The semantic theory provides an account of ‘meaning’ in which the logical
connection of terms establishes interoperability between systems”
• “The Semantic Web provides a common framework that allows data to be
shared and reused across application, enterprise, and community boundaries.”
W3C Semantic Web Activity.

Shadbot, Hall, Berners-Lee, The Semantic Web revisited, IEEE Intelligent Systems, May 2006
Web Technologies II 2
What is the Semantic Web?
• The Semantic Web builds upon
• the principles and technologies of the web
• It reuses the Web’s global indexing and naming scheme
• Semantic Web documents can be accessed through standard Web browsers as well as
through semantically aware applications
• the Web is a shared resource, and therefore, within a machine-readable Web,
meaning should be shared too.

The Semantic Web is a collection of technologies and standards that allow


machines to understand the meaning (semantics) of information on the Web.

Web Technologies II 3
What is the Web?
• Web is a global document repository.

• Principles of the Web


• Openness: anyone within the web can be provider or consumer of information. it
incorporates:
• Accessibility: accessed remotely from a wide variety of hardware and software platforms
• Nonproprietary
• Consensual control
• Usable
• Interoperability: The Web is neutral to hardware and software platforms
• Decentralized authorship and editorship: Content can appear, becoming modified, or
be removed in a non-controlled fashion.
• Enabling n:m relationship for maximum interaction

Web Technologies II 4
Web Architecture
• It is simple.
• Functional services of the Web
• A worldwide addressing schema: using URLs – resource identification and describing
its network location
• A transport layer- HTTP – supports remote access to content over a network layer
(TCP-IP). HTTP functions as a request –respond protocol in client-server computing
model.
• A platform-independent interface – enable users to easily access any online resource

Web Technologies II 5
What Are the Problems with the Web?
• Huge collection of documents
• Accessing data
• Documents are indexed and accessed via plain text (i.e. string matching algorithms).
For example: ‘‘Paris’’ can denote: the capital of France; towns in Canada, Kiribati, and
the USA.
• The current paradigm is dominated by returning single ‘‘best fit’’ documents for a
search.
• Underlying data are not available. A significant number of websites are generated
through databases but the underlying data are hidden behind the presented HTML.
(Dark Web)
• Enabling delegation of tasks such as the integration of information, data analysis, and
sense making to machines, at least partially

Web Technologies II 6
What Are the Problems with the Web?
• Semantic Web extends the Web with ‘‘meaning’’ supporting access to data
at web-scale and enabling the delegation of certain classes of tasks.
• The Web has documents at the center
• The Semantic Web places data and the semantics of data at its core.

Web Technologies II 7
What Are Semantics?
• Semantic technology provides machine-understandable (or
better machine-processable) descriptions of data,
programs, and infrastructure, enabling computers to reflect
on these artifacts.

Web Technologies II 8
Semantic Web Languages
• HTML
• It provides a number of ways to express the semantics of data. An obvious one is the
META tag
<META name = “Author” lang= “fr” content = “Arnaud Le Hors”>
• Ontobroker used the attribute of the anchor tag to encode semantic information.
• But, HTML was not designed to provide descriptions of documents beyond that of
informing the browser on how to render the contents.
• Semantic HTML
• The Extensible Markup Language (XML)
• It is a generic way to structure documents on the Web. It generalizes HTML by
allowing user-defined tags.
• It is flexible but reduces the possibilities for the type of semantic interpretation that
was possible with the predefined tags of HTML.

Web Technologies II 9
Semantic Web Languages
• The Resource Description Framework (RDF)
• It is a simple data model for semantically describing resources on the Web.
• Binary properties interlink terms forming a directed graph.
• Terms as well as properties are described using URIs.
• As a property can be a URI, it can be used as a term interlinked to another property.
• Unlike most logical languages or databases, it is not possible to distinguish the language or
schema from statements in the language or schema.
• Example: <rdf:type, rdf:type, rdf:Property>
• RDF schema (RDFS)
• It uses basic RDF statements and defines a simple ontology language.
• It defines entities such as rdfs:class, rdfs:subclass, rdfs:subproperty, rdfs:domain, and
rdfs:range, enabling one to model classes, properties with domain and range restrictions, and
hierarchies of classes and properties.
• It is RDF + some more definitions (statements) in RDF.

Web Technologies II 10
Semantic Web Languages
• The Web Ontology Language OWL
• It extends vocabulary to a full-fledged spectrum of Descriptions Logics defined in RDF,
namely, OWL Lite, OWL DL, and OWL Full.
• It allows mechanisms for defining properties to be inverse, transitive, symmetric, or
functional. Properties can be used to define the membership of instances for classes
or hierarchies of classes and of properties.
• OWL2
• Defined some of the issues around OWL.
• OWL Lite had been defined as an over expressive Description Logic. Three sub-
languages:
• OWL2EL - all the standard reasoning tasks of description logic
• OWL2QL enables efficient query answering over large instance populations
• OWL2RL restricts the expressiveness with respect to extensibility toward rule languages.

Web Technologies II 11
Semantic Web Languages
• The Rule Interchange Format (RIF)
• It complements OWL with a language framework centered on the rule paradigm.
• RIF-BLD – defines a simple logic-oriented rule language
• RIF-PRD captures most of the aspects of production rule systems
• RIF-Core is the intersection of both of these languages
• SPARQL
• It is a query language for the graph-based data model of RDF.
• SPARQL has been developed without considering RDFS, OWL, and RIF

Web Technologies II 12
Semantic Web Languages <person>
<name>Sir Tim</name>
<phone number>01-444444 </phone number>
</person
Concept – Person
Property: Name, Phone number
How do we know that Sir Tim is then name of a person?
• Microformats : are predefined formats to add meta information to elements in HTML and
XML. It provides a language structure to present information and provide domain specific
terminologies as well.
• hCard can be used for representing people, companies, organizations, and places, using
vCard, a file format standard for electronic business cards.
• RDFa provides a set of XHTML attributes to include RDF metadata directly into HTML and XML
documents.
• GRDDL has been developed as a mechanism for Gleaning Resource Descriptions from Dialects
of Languages to derive RDFa definitions from Microformats so as to integrate information
from heterogeneous sources.
Web Technologies II 13
The Semantic Web: why?
• The traditional web is web of documents and it is meant mainly for humans
and has two major problems
• Problem 1: web documents do not distinguish between information content
and presentation
• (“solved” by XML)
• Problem 2: different web documents may represent in different ways
semantically related pieces of information
• this leads to hard problems for “intelligent” information search on the Web

Web Technologies II 14
Separating content and presentation
Problem 1: web documents do not distinguish between information content
and presentation
• Cause of the problem: the HTML language
• Current Technology solution: – stylesheets (HTML, XML), XML
• stylesheets allow for separating formatting attributes from the information
presented

.g, body, html, input, .std, h1 {


font-size: small;
font-family: arial,sans-serif;
}

Web Technologies II 15
Separating content and presentation
• XML: eXtensible Mark-up Language
• XML documents are written through a user defined set of tags
• tags are used to express the “semantics” of the various pieces of information

Web Technologies II 16
Example: HTML
<html>
<body>
<H1> Seminar: Article Review Presentation Schedule</H1>
<UL>
<LI>[email protected]</LI> <LI>[email protected]</LI>
<LI>CoSc 705 - Seminar: Article Review Presentation Schedule</LI >
<LI> The presentations of the seminar course are scheduled from July 4 - 8, 2016. Please
find attached the presentation schedule</LI>
</UL>
</body>
</html>

Web Technologies II 17
Example: XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<from>[email protected] </from>
<to>[email protected] </to>
<subject> CoSc 705 - Seminar: Article Review Presentation Schedule
</subject>
<body> The presentations of the seminar course are scheduled from July 4
- 8, 2011. Please find attached the presentation schedule </body>
</note>

Web Technologies II 18
Example: XML - DTD

Web Technologies II 19
Limitations of XML
• XML does not solve all
the problems:
• legacy HTML
documents
• different XML
documents may
express information
with the same
meaning but using
different tags

Web Technologies II 20
The need for a “Semantic” Web
• Problem 2: different web documents may represent in different ways
semantically related pieces of information different XML documents do not
share the “semantics” of information
• idea: annotate (mark-up) pieces of information to express the “meaning” of
such a piece of information the meaning of such tags is shared! ⇒ shared
semantics

Web Technologies II 21
The Semantic Web initiative
• Sir Tim Berners-Lee started provide a layered approach to structure the
Semantic Web
• Viewpoint:
• the Web = a web of data
• Goal:
• to provide a common framework to share data on
• the Web across application boundaries
• Main ideas:
• Ontology
• Standards
• “layers”

Web Technologies II 22
The Semantic Web Tower
five layers of semantics: RDF, OWL, RIF, and
layers for proof and trust

XML+ NS + XMLSchema provide syntactic descriptions


of structured objects.

Unicode a means to encode text URIs to refer to resources


Semantic Web Tower Scenario: Building a Semantic Web
representation of a bookstore.
Proof and Trust Digital Signatures , cryptographic hashing , digital certificate
Rules and Logic Layer Rule: If publication_date > 2010, classify as "Modern Book"

SELECT ?book
WHERE {
SPARQL (SPARQL Protocol ?book <http://purl.org/dc/terms/author> "John Doe" .
and RDF Query Language): }

OWL (Web Ontology Define an ontology for books:


Language) Create classes like Book, with properties such as title, author, publication date, etc

RDF (Resource Description <http://example/bookstore/books/001> <http://purl.org/dc/terms/title> "Semantic Web 101" .


Framework): <http://example/bookstore/books/001> <http://purl.org/dc/terms/author> "John Doe" .

HTTP (Hypertext Transfer retrieve book information by accessing http://example/bookstore/books/001.


Protocol):
URI (Uniform Resource URI for the bookstore: http://example/bookstore
Identifier): URI for a book: http://example/bookstore/books/001
The XML Layer
• XML (eXtensible Markup Language)
• XML documents are written through a user-defined set of tags and
their are domain-specific markup
• tags are used to express the “semantics” of the various pieces of
information
• URI (Uniform Resource Identifier)
• universal naming for Web resources
• same URI = same resource
• URIs are the “ground terms” of the SW
• W3C standards

Web Technologies II 27
The XML Layer – example
<course date=“2016”>
<title>Web Technologies II</title>
<teacher>
<name>Animaw Kerie</name>
<office>FBE, 217</office>
<email>[email protected]</email>
</teacher>
<prereq>none</prereq>
</course>

Web Technologies II 28
The XML Layer – example
• XML: document = labelled tree
• node = label + attributes/ values + contents
course
<course date=“2016”>
<title>Web Technologies II</title>
<teacher>
<name>Animaw Kerie</name> date title teacher prereq
<office>4th floor</office>
<email>[email protected]</em
ail>
</teacher> 2016 Web Tech … name office email None..
<prereq>none</prereq>
</course>
aniamw … 4th floor. [email protected]

Web Technologies 29
The RDF + RDFS layer
• RDF = a simple conceptual data model
• W3C standard (1999)
• RDF model = set of RDF triples
• triple = expression (statement)
• (subject, predicate, object)
• subject is a resource
• predicate is a property (of the resource)
• object is the value (of the property)
• an RDF model is a graph

Web Technologies II 30
The RDF + RDFS layer
The RDF + RDFS layer
• RDFS is RDF Schema
• It contains “vocabulary” for RDF: Class, domain, range, subClassOf, subPropertyOf
• It is a W3C standard (2004)
Person
subClassOf subClassOf

domain range
RDFS Student hasSupervisor Researcher

type type
hasSupervisor
RDF Frank Jeen
The Ontology - OWL layer
• Ontology is a shared conceptualization of a domain of interest
• It is a conceptual model (more expressive than RDF + RDFS)
• It is expressed in a true knowledge representation language i.e. OWL (Web
Ontology Language), the standard language for ontologies
• The ontology can be
• A simple (shallow) that contain shared vocabulary
• Deep ontology that represent (complex) relationships between “terms”

Web Technologies II 33
Ontologies: example
class-def animal
class-def plant
subclass-of NOT animal
class-def tree
subclass-of plant The use of "subclass-of NOT" denotes that a class is a subclass
class-def branch of a broader category but excludes another specified subclass.
slot-constraint is-part-of In this case, 'defined herbivore' is a subclass of 'animal' but
has-value tree explicitly not a subclass of 'carnivore'. This setup allows for
max-cardinality 1 defining specific relationships and constraints within the
class-def defined carnivore ontology, creating a structured understanding of the
subclass-of animal relationships between different types of entities in this system.
slot-constraint eats
value-type animal
class-def defined herbivore herbivores consume plants.
subclass-of animal, NOT carnivore
slot-constraint eats
value-type plant

Web Technologies II 34
Ontologies and Description Logics

• OWL is based on a fragment of first-order predicate logic (FOL)


• Description Logics (DLs) is a subclasses of FOL. It has
• only unary and binary predicates
• function-free
• quantification allowed only in restricted form
• (variable-free syntax)
• decidable reasoning
• DLs are one of the most prominent languages for Knowledge Representation

Web Technologies II 35
The proof/ rule layer
• rule: informal notion
• rules are used to perform inference over ontologies
• rules are used as a tool for capturing further knowledge (not expressible in
OWL ontologies)

Web Technologies II 36
Ontologies: the role of logic
• Ontology = logical theory
• Why?
• Declarative
• formal semantics
• reasoning (sound and complete inference techniques)
• well-established correspondence between conceptual
modeling formalisms and logic

Web Technologies II 37
Rule-based formalisms
• Prolog
• Logic programming
• Constraint (logic) programming
• Production rules
• Datalog
• ...
• RIF (Rule Interchange Format): W3C recommendation
(2010)

Web Technologies II 38
The Trust layer
• It is the top layer of the Semantic web
• It provides support for provenance/ trust
• To judge the value of the data item and how to use the data appropriately, one has to
know the origin of the data.
• provenance: it answers the following main questions
• which pieces of data were chosen and composed together?
• where do they come from? who created them?
• or which inference rules were used to create implicit statements?
• can I trust this information? trust is related to data source, authorship, certainty, …
• It is largely unexplored issue and there is no standardization effort to handle it.

Inference in the Open Provenance Model

Web Technologies II 39
Semantic Web Applications
Applications
• Intelligent Business and Management (e.g. e-commerce – matchmaking for
e-business)

Web Technologies II 41
Semantic Web Applications
• Main categories
• Search (also browsing, personalization) e.g. Taalee search engine
• Integration (also interoperability)
• Analysis (also visualization)

• drug discovery process [Borkum & Frey, Journal of Cheminformatics, 2014:


Usage and applications of Semantic Web techniques and technologies to
support chemistry research]
• Integrating applications
• Model checking, consistency and collaboration for Engineering of products
e.g. [Stefan Feldmann, Konstantin Kernschmidt, Birgit Vogel-Heuser, Springer,
2016: , Applications of Semantic Web Technologies for the Engineering of
Automated Production Systems—Three Use Cases]

Web Technologies II 42
The Building Block for the Semantic Web(
Resource Description Framework – RDF)
RDF
• It is a framework to publish statements on the Web about anything.
• It allows anyone to describe resources, in particular Web resources, such as
the author, creation date, subject, and copyright of an image.
• RDF is a data model
• it is domain-neutral, application-neutral and ready for internationalization
• it can be viewed as directed, labeled graphs or as an object-oriented model (object/
attribute/value)
• It is an abstract, conceptual layer independent of XML
• XML is a transfer syntax for RDF, not a component of RDF
• RDF data might never occur in XML form
• it provides interoperability between applications that exchange machine-
understandable information.

Web Technologies 44
RDF
• Resources are a core concept on the Semantic Web:
• everything one might refer to is considered a resource. Everything that
can be identified by a URI is considered as a resource.
• Descriptions of resources are essential for understanding and reasoning
about them.
• In the most general case, a description is a set of attributes, features,
and relations concerning the resource.
• The Framework means it provides models, languages, and syntaxes for
these descriptions.
• RDF provides a standard data structure and a model to encode data and
metadata about any subject on the Web

Web Technologies 45
RDF model
• RDF model is a set of RDF triples
• A triple is an expression (statement) of the format
(subject, predicate, object)
• Subject: resource or blank node
• Predicate: property (of the resource)
• Object: value (of the property) – literal or blank node
subject predicate object

Resource Value
property

Web Technologies 46
Triplet data model
• Example: represent the assertion ‘‘Fabien has written a page doc.html
about music’’ can be broken down into two RDF statements:
(doc.html, author, Fabien) and
(doc.html, theme, music).
• The logical view of the RDF triples is that RDF makes an open-world
assumption (i.e. what is not known to be true is simply unknown - the
absence of a triple is not significant) as opposed to the closed-world
assumption of classical systems (i.e. what is not known to be true must be
false).

Web Technologies 47
Graph-Oriented data model
• RDF triples can be seen as two vertices and one arc of a graph describing
and linking resources.
• RDF is a decentralized data representation model relying on distributed
triples that form a global graph.
• The identity of the resources is based on the URI mechanism: if two
resources have the same URI they are one and the same node in the graph.
• An RDF graph is:
• A multi-graph: a graph that can contain both multiple edges and loops
between its vertices
• A directed graph: every edge is oriented going from the end-vertex
representing the subject to the end-vertex representing the object
• A labeled graph: edges are labeled with URIs, vertices are labeled with
URIs, blank node identifiers, or literals
Web Technologies 48
English: ‘‘The report doc.html has the authors Fabien and York, the theme music and is 23-pages long.’’
Logic predicates: Triples:
Report(doc.html) (doc.html , type , Report)
creator(doc.html , Fabien (doc.html, creator , Fabien)
creator(doc.html , York) (doc.html, creator , York)
theme(doc.html , Music) (doc.html, theme , Music)
nbPages(doc.html , 23) (doc.html, nbPages, ‘‘23’’)

http://...#Report
type
creator
http://...#fabien
http://.../doc.html creator
http://...#york

theme
http://...#music
nbPages

23
Example – Graph-oriented data model
Describe a Person identified by http://www.w3.org/People/EM/contact#me, whose
name is Eric Miller, whose email address is [email protected], and whose title is Dr.
http://www.w3.org/2000/10/swap/pim/contact#Person

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

http://www.w3.org/2000/10/swap/pim/contact#fullName
http://www.w3.org/People/EM/contact#me Eric Miller

http://www.w3.org/2000/10/swap/pim/contact#mailbox

http://www.w3.org/2000/10/swap/pim/contact#personaltitle mailto:[email protected]

Dr.

50
RDF/XML
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#
xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#">
<contact:Person
rdf:about="http://www.w3.org/People/EM/contact#me">
<contact:fullName>Eric Miller</contact:fullName>
<contact:mailbox rdf:resource="mailto:[email protected]"/>
<contact:personalTitle>Dr.</contact:personalTitle>
</contact:Person>
</rdf:RDF>

51
Example:
Describe “the document at http://www.w3c.org/TR/REC-rdf-syntax is created by
Eric Miller on 1999-02-22 and is published by W3C”
Triple:
http://www.w3c.org/TR/REC-rdf-syntax creator Eric Miller
http://www.w3c.org/TR/REC-rdf-syntax date 1999-02-22
http://www.w3c.org/TR/REC-rdf-syntax publisher W3C

W3C

dc:publisher

http://www.w3.org/TR/REC-rdf-syntax/

dc:date dc:creator

52
1999-02-22 Eric Miller
Node and edge labels in RDF graphs

• node and edge labels:


• URI
• literal (string)
• blank node (anonymous label)
• but:
• a literal can only appear in object positions
• a blank node can only appear in subject or object positions
• Remark: URIs are used as predicates, i.e., graph nodes can be used as edge
labels (RDF has meta-modeling abilities)

Web Technologies 53
Blank nodes
• blank node (bnode) = RDF graph node with “anonymous label” (i.e., not associated with an URI)
Example: "Jean has a friend born the 21st of April“
ex:Jean foaf:knows _:p1
_:p1 foaf:birthDate 04-21
_:p1 is the blank node (bnode)
• bnode can be used both
as subjects and objects

Web Technologies 54
Complex values
• values of properties need not be simple strings
• the value of a property can also be a graph node (corresponding to a
resource)
• using blank nodes, arbitrarily complex tree and graph structures are possible
dc:publisher
http://www.w3.org/TR/REC-rdf-syntax/ W3C

dc:creator

p:Name
p:email
Eric Miller

mailto:[email protected]

Web Technologies II 55
RDF Graphs as XML Trees
• RDF/ XML syntax is the standardized way of serializing RDF triplet.
• The principal aim of RDF/XML is to be machine-processable and compliant
to the de facto standard of Web document formatting, XML.
• RDF/ XML syntax allows RDF documents to be easily exchanged between
very different types of systems and applications.

Web Technologies 56
<?xml version=‘‘1.0’’?>
RDF/ XML <rdf:RDF
xmlns:rdf=‘‘http://www.w3.org/1999/02/22-rdf-syntax-ns#’’
xmlns:exs= ‘‘http://example.org/schema#’’>
• There are <rdf:Description rdf:about=‘‘http://example.org/doc.html’’>
several <rdf:type rdf:resource=‘‘http://example.org/schema#Report’’/>
possibilities to <exs:theme rdf:resource=‘‘http://example.org#Music’’/>
<exs:theme rdf:resource=‘‘http://example.org#History’’/>
express the <exs:nbPages rdf:datatype= ‘‘http://www.w3.org/2001/XMLSchema#int’’> 23
same RDF </exs:nbPages>
graph (i.e. the </rdf:Description>
serialization is </rdf:RDF>
<?xml version=‘‘1.0’’?>
not unique) <rdf:RDF
xmlns:rdf=‘‘http://www.w3.org/1999/02/22-rdf-syntax-ns#’’
xmlns:exs= ‘‘http://example.org/schema#’’>
<exs:Report rdf:about=‘‘http://example.org/doc.html’’ exs:nbPages=‘‘23’’>
<exs:theme rdf:resource=‘‘http://example.org#Music’’/>
<exs:theme rdf:resource=‘‘http://example.org#History’’/>
</exs:Report>
</rdf:RDF>
Web Technologies 57
N-Triples – N3 format
• N-Triples requires one triple to be written per line.
• Every triple is provided as subject, predicate, and object that are separated
by whitespaces and terminated by a dot (.).

<http://example.org/doc.html> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://example.org/schema#Report>.
<http://example.org/doc.html> <http://example.org/schema#theme> <http://example.org#Music>.
<http://example.org/doc.html> <http://example.org/schema#theme> <http://example.org#History>.
<http://example.org/doc.html> <http://example.org/schema#nbPages> ‘‘23’’^^
<http://www.w3.org/2001/XMLSchema#integer>.

Web Technologies 58
Triple Serialization in Turtle
• Turtle (Terse RDF Triple Language) is a compact textual format for serializing an RDF graph, is
less constrained than N-Triples
• Turtle, for example, does not have the restriction of single-lined statement as in N-Triples, and
provides various abbreviations.
• Further shortcuts are supported for repeated subjects, or multiple objects.
• To abbreviate multiple statements with the same subject, Turtle provides a semicolon (;)
notation which makes it possible to list predicate–object pairs for the same subject.
• Multiple statements with the same subject–predicate pair but different objects can be similarly
abbreviated using the comma (,) notation.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix exs: <http://example.org/schema#>.
<http://example.org/doc.html> a exs:Report ;
exs:theme <http://example.org#Music> ,<http://example.org#History> ;
exs:nbPages ‘‘23’’^^xsd:int .
Web Technologies 59
Containers
• Containers are collections: allow grouping of resources (or literal values)
• It is possible to make statements about the container (as a whole) or about
its members individually
• Different types of containers exist
• rdf:Bag defines an unordered group of resources or literals.
• rdf:Seq defines an ordered group of resources or literals.
• rdf:Alt represents a group of resources or literals that are alternatives;
that is, only one of the values can be selected.
• It is also possible to create collections based on URI patterns
• Duplicate values are permitted (no mechanism to enforce unique value
constraints)
Web Technologies 60
rdf:Bag
exs:report rdf:_1
http://example.org#Fabien
rdf:type

rdf:_2
rdf:type :x http://example.org#York
dc:creator Turtle
<http://example.org/doc.html>
http://example.org/doc.html a exs:Report ;
dc:creator [ a rdf:Bag ;
rdf:_1 <http://example.org#Fabien> ;
rdf:_2 <http://example.org#York> ].
RDF/XML
<exs:Report rdf:about=‘‘http://example.org/doc.html’’>
<dc:creator>
<rdf:Bag>
<rdf:li rdf:resource=‘‘http://example.org#Fabien’’/>
<rdf:li rdf:resource=‘‘http://example.org#York’’/>
</rdf:Bag>
</dc:creator>
</exs:Report>
RDF Containers: Bag
“The lecture is attended by John, Mary and Chris”

62
RDF Containers: Seq
“[RDF-Concepts] is edited by Graham and Jeremy
(in that order)”

63
RDF Containers: Alt
“The source code for the application may be found at:
ftp1.example.org, ftp2.example.org, ftp3.example.org”

64
Reification
• It is a mechanism to make statement about statements
• Reification in RDF is represented using an RDF statement as the subject (or
object) of another RDF statement
Examples
<rdf:Description rdf:about="#949352">
<uni:name>Grigoris Antoniou</uni:name>
</rdf:Description>
reifies as
<rdf:Statement rdf:ID="StatementAbout949352">
<rdf:subject rdf:resource="#949352"/>
<rdf:predicate rdf:resource="http://www.mydomain.org/uni-ns#name"/>
<rdf:object>Grigoris Antoniou</rdf:object>
</rdf:Statement>
Web Technologies 65
Reification
• RDF provides a built-in predicate vocabulary for reification:
• rdf:subject
• rdf:predicate
• rdf:object
• rdf:statement
• Using this vocabulary (i.e., these URIs from the rdf:namespace) it is
possible to represents a triple through a blank node

Web Technologies 66
Reification
Examples Triple
<http://example.org/doc.html> a exs:Report.
Reified triple in Turtle syntax
exr:triple1 a rdf:Statement ;
rdf:subject <http://example.org/doc.html>;
rdf:predicate rdf:type ;
rdf:object exs:Report.

rdf:Statement rdf:type http://example.org/doc.html

rdf :subject

rdf :object rdf:type


rdf:predicate
exr:triple1
exs :Report
Web Technologies 67
The RDF Schema (RDFS)

68
RDFS is recommendation from W3C and it is an
extensible knowledge representation language
that one can use to create a vocabulary for
describing classes, subclasses and properties of
RDF resources.
RDF Vocabulary Description Language
• Types in RDF:
<#john, rdf:type, #Student>

• What is a “#Student”?

• We know that “#Student” identifies a category (a concept or a class), but


this is only implicitly defined in RDF

Web Technologies II 70
RDF Vocabulary Description Language
• We need a language for defining RDF types:

• Define classes:
• “#Student is a class”
• Relationships between classes:
• “#Student is a sub-class of #Person”
• Properties of classes:
• “#Person has a property hasName”

• RDF Schema is such a language

Web Technologies II 71
RDF Vocabulary Description Language
• Classes:
<#Student, rdf:type, #rdfs:Class>

• Class hierarchies:
<#Student, rdfs:subClassOf, #Person>

• Properties:
<#hasName, rdf:type, rdf:Property>

• Property hierarchies:
<#hasMother, rdfs:subPropertyOf, #hasParent>

• Associating properties with classes (a):


• “The property #hasName only applies to #Person”
<#hasName, rdfs:domain, #Person>

• Associating properties with classes (b):


• “The type of the property #hasName is #xsd:string”
<#hasName, rdfs:range, xsd:string>

Web Technologies II 72
RDFS Vocabulary
• RDFS Extends the RDF Vocabulary
• RDFS vocabulary is defined in the namespace:
http://www.w3.org/2000/01/rdf-schema#

RDFS Classes RDFS Properties


– rdfs:Resource – rdfs:domain
– rdfs:Class – rdfs:range
– rdfs:Literal – rdfs:subPropertyOf
– rdfs:Datatype – rdfs:subClassOf
– rdfs:Container – rdfs:member
– rdfs:ContainerMembershipProperty – rdfs:seeAlso
– rdfs:isDefinedBy
– rdfs:comment
– rdfs:label
Web Technologies II 73
RDFS Principles
• Resource
• All resources are implicitly instances of rdfs:Resource
• Class
• Describe sets of resources
• Classes are resources themselves - e.g. Webpages, people,
document types
• Class hierarchy can be defined through rdfs:subClassOf
• Every class is a member of rdfs:Class
• Property
• Subset of RDFS Resources that are properties
• Domain: class associated with property: rdfs:domain
• Range: type of the property values: rdfs:range
• Property hierarchy defined through: rdfs:subPropertyOf
Web Technologies II 74
RDFS Example

ex:Faculty-
Staff

Web Technologies II 75
Triples
exs:Report, rdfs:subClassOf, exs:Document.
exs:Advert, rdfs:subClassOf, exs:Document.
exs:Presentation, rdfs:subClassOf, exs:Document.
exs:PresentationReport, rdfs:subClassOf, exs:Report, exs:Presentation.

exs:Document
rdsf:subClassOf rdsf:subClassOf

rdsf:subClassOf

exs:Report exs:Advert exs:Presentation

rdsf:subClassOf

rdsf:subClassOf

exs:PresentationReport
Triples
exs:Researcher rdfs:subClassOf foaf:Person.
foaf:name rdfs:domain foaf:Person.
exs:TimBernersLee a exr:Researcher;
foaf:name ‘‘Tim Berners-Lee’’;
foaf:interest <http://www.w3.org/sw/>,
<http://www.w3.org/RDF/>.
exs:BlogEntry rdfs:subClassOf foaf:Document.
<http://example.org/blog/4 a exs:BlogEntry;
exs:mainSubject exs:TimBernersLee;
foaf:maker, exs:TimBernersLee;
foaf:topic <http://www.w3.org/sw/>,
<http://www.w3.org/RDF/> ;
rdfs:seeAlso <http://example.org/blog/feed/4>.
<http://example.org/blog/feed/4> a foaf:Document;
rdfs:comment ‘‘This blog is provided by an RSS
channel.’’.
RDFS Vocabulary Example

Web Technologies II 78
RDFS Metadata Properties
• Metadata is “data about data”
• Any meta-data can be attached to a resource, using:
• rdfs:comment
• Human-readable description of the resource, e.g.
• <ex:Person>, rdfs:comment, ”A person is any human being”
• rdfs:label
• Human-readable version of the resource name, e.g.
• <ex:Person>, rdfs:label, ”Human being”
• rdfs:seeAlso
• Indicate additional information about the resource, e.g.
• <ex:Person>, rdfs:seeAlso, <http://xmlns.com/wordnet/1.6/Human>
• rdfs:isDefinedBy
• A special kind of rdfs:seeAlso, e.g.
• <ex:Person>,rdfs:isDefinedBy,<http://xmlns.com/wordnet/1.6/Human>

Web Technologies II 79
RDF

RDFs

Web Technologies II
Web Ontology Language : OWL
Requirements for Ontology Languages
• Ontology languages allow users to write explicit, formal conceptualizations of
domain models
• The main requirements are:
• a well-defined syntax
• efficient reasoning support
• a formal semantics
• sufficient expressive power
• convenience of expression

Web Technologies II 82
Tradeoff between Expressive Power and Efficient Reasoning Support

• The richer the language is, the more inefficient the reasoning support
becomes
• Sometimes it crosses the border of noncomputability
• We need a compromise:
• A language supported by reasonably efficient reasoners
• A language that can express large classes of ontologies and knowledge

Web Technologies II 83
Reasoning About Knowledge in Ontology Languages
• Class membership
• If x is an instance of a class C, and C is a subclass of D, then we can infer that x is an
instance of D
• Equivalence of classes
• If class A is equivalent to class B, and class B is equivalent to class C, then A is
equivalent to C, too
• Consistency
• X instance of classes A and B, but A and B are disjoint
• This is an indication of an error in the ontology
• Classification
• Certain property-value pairs are a sufficient condition for membership in a class A; if
an individual x satisfies such conditions, we can conclude that x must be an instance of
A
Web Technologies II 84
Uses for Reasoning
• Reasoning support is important for
• checking the consistency of the ontology and the knowledge
• checking for unintended relationships between classes
• automatically classifying instances in classes
• Checks like the preceding ones are valuable for
• designing large ontologies, where multiple authors are involved
• integrating and sharing ontologies from various sources

Web Technologies II 85
Reasoning Support for OWL
• Semantics is a prerequisite for reasoning support
• Formal semantics and reasoning support are usually provided by
• mapping an ontology language to a known logical formalism using automated
reasoners that already exist for those formalisms
• OWL is (partially) mapped on a description logic, and makes use of reasoners
such as FaCT and RACER
• Description logics are a subset of predicate logic for which efficient reasoning
support is possible

Web Technologies II 86
Three Species of OWL
• W3C’sWeb Ontology Working Group defined OWL as three different sublanguages:
• OWL Full
• OWL DL
• OWL Lite
• Each sublanguage geared toward fulfilling different aspects of requirements.

Web Technologies II 87
OWL Full
• It uses all the OWL languages primitives
• It allows the combination of these primitives in arbitrary ways with RDF and
RDF Schema
• OWL Full is fully upward-compatible with RDF, both syntactically and
semantically
• Any legal RDF document is also a legal OWL Full document, and any valid
RDF/RDF Schema conclusion is also a valid OWL Full conclusion.
• OWL Full is so powerful that it is undecidable
– No complete (or efficient) reasoning support

Web Technologies II 88
OWL DL

• OWL DL (Description Logic) is a sublanguage of OWL Full that


restricts application of the constructors from OWL and RDF
• Application of OWL’s constructors’ to each other is disallowed
• Therefore it corresponds to a well studied description logic
• OWL DL permits efficient reasoning support
• But we lose full compatibility with RDF:
• Not every RDF document is a legal OWL DL document.
• Every legal OWL DL document is a legal RDF document.

Web Technologies II 89
OWL Lite
• An even further restriction limits OWL DL to a subset of the
language constructors
• E.g., OWL Lite excludes enumerated classes, disjointness
statements, and arbitrary cardinality.
• The advantage of this is a language that is easier to
• grasp, for users
• implement, for tool builders
• The disadvantage is restricted expressivity

Web Technologies II 90
OWL Syntactic Varieties
• OWL builds on RDF and uses RDF’s XML-based syntax
• Other syntactic forms for OWL have also been defined:
• An alternative, more readable XML-based syntax that does not
follow the RDF conventions and is thus more easily read by
human users.
• An abstract syntax, that is much more compact and readable
than the XML languages
• A graphic syntax based on the conventions of UML

Web Technologies II 91
OWL XML/RDF Syntax: Header
• OWL documents are usually called OWL ontologies and are RDF documents.
The root element of an OWL ontology is an rdf:RDF element, which also
specifies a number of namespaces:
<rdf:RDF
xmlns:owl ="http://www.w3.org/2002/07/owl#"
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd ="http://www.w3.org/2001/XLMSchema#">
• An OWL ontology may start with a collection of assertions for housekeeping
purposes using owl:Ontology element, which contains comments, version
control, and inclusion of other ontologies.

Web Technologies II 92
OWL XML/RDF Syntax: Header (2)
Example:
<owl:Ontology rdf:about="">
<rdfs:comment>An example OWL ontology </rdfs:comment>
<owl:priorVersion rdf:resource="http://www.mydomain.org/uni-ns-old"/>
<owl:imports rdf:resource="http://www.mydomain.org/persons"/>
<rdfs:label>University Ontology</rdfs:label>
</owl:Ontology>
• owl:imports, lists other ontologies whose content is assumed to be part of
the current ontology.
• owl:imports is a transitive property, if ontology A imports ontology B, and
ontology B imports ontology C, then ontology A also imports ontology C.
Web Technologies II 93
Classes
• Classes are defined using owl:Class
• owl:Class is a subclass of rdfs:Class
<owl:Class rdf:ID="associateProfessor">
<rdfs:subClassOf rdf:resource="#academicStaffMember"/>
</owl:Class>
• Disjointness is defined using owl:disjointWith
<owl:Class rdf:about="#associateProfessor">
<owl:disjointWith rdf:resource="#professor"/>
<owl:disjointWith rdf:resource="#assistantProfessor"/>
</owl:Class>

Web Technologies II 94
Classes (2)
• owl:equivalentClass defines equivalence of classes
<owl:Class rdf:ID="faculty">
<owl:equivalentClass rdf:resource=
"#academicStaffMember"/>
</owl:Class>
• owl:Thing is the most general class, which contains
everything
• owl:Nothing is the empty class

Web Technologies II 95
Properties
• In OWL there are two kinds of properties
• Object properties, which relate objects to other objects E.g. is-
TaughtBy , supervises
• Data type properties, which relate objects to datatype values
E.g. phone, title, age, etc.
• OWL does not have any predefined data types, nor does it
provide special definition facilities.
• Instead, it allows one to use XML Schema data types, thus
making use of the layered architecture of the Semantic Web

Web Technologies II 96
Datatype Properties
• OWL makes use of XML Schema data types, using the layered architecture of
the SW
<owl:DatatypeProperty rdf:ID="age">
<rdfs:range rdf:resource=
"http://www.w3.org/2001/XLMSchema#nonNegativeInte
ger"/>
</owl:DatatypeProperty>

Web Technologies II 97
Object Properties
• User-defined data types will usually be collected in an XML schema and then
used in an OWL ontology.
• Example:
<owl:ObjectProperty rdf:ID="isTaughtBy">
<owl:domain rdf:resource="#course"/>
<owl:range rdf:resource= "#academicStaffMember"/>
<rdfs:subPropertyOf rdf:resource="#involves"/>
</owl:ObjectProperty>
• More than one domain and range may be declared. In this case the
intersection of the domains, respectively ranges, is taken.

Web Technologies II 98
Inverse Properties
<owl:ObjectProperty rdf:ID="teaches">
<rdfs:range rdf:resource="#course"/>
<rdfs:domain rdf:resource= "#academicStaffMember"/>
<owl:inverseOf rdf:resource="#isTaughtBy"/>
</owl:ObjectProperty>

Web Technologies II 99
Equivalent Properties
• Equivalence of properties can be de fined through the use
of the element owl:equivalentProperty.
<owl:equivalentProperty
<owl:ObjectProperty rdf:ID="lecturesIn">
<owl:equivalentProperty rdf:resource="#teaches"/>
</owl:ObjectProperty>

Web Technologies II 100


Property Restrictions
• rdfs:subClassOf is used to specify a class C as a subclass of
another class C’; then every instance of C is also an instance
of C’.
• Suppose we wish to declare, instead, that the class C
satisfies certain conditions, that is, all instances of C satisfy
the conditions. This is equivalent to saying that C is
subclass of a class C’, where C’ collects all objects that
satisfy the conditions. That is exactly how it is done in OWL.
• Note that, in general, C’ can remain anonymous.

Web Technologies II 101


Property Restrictions (2)
• A (restriction) class is achieved through an owl:Restriction element
• This element contains an owl:onProperty element and one or more
restriction declarations
• One type defines cardinality restrictions (at least one, at most 3,…)
• The other type defines restrictions on the kinds of values the
property may take
• owl:allValuesFrom specifies universal quantification
• owl:hasValue specifies a specific value
• owl:someValuesFrom specifies existential quantification

Web Technologies II 102


owl:allValuesFrom
• Represent the following text using OWL “First year courses to be
taught by professors only”
<owl:Class rdf:about="#firstYearCourse">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#isTaughtBy"/>
<owl:allValuesFrom rdf:resource="#Professor"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Web Technologies II 103
owl:hasValue
• Represent the statement “Courses on mathematics are taught by
David Billington”
<owl:Class rdf:about="#mathCourse">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource= "#isTaughtBy"/>
<owl:hasValue rdf:resource= "#949352"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Web Technologies II 104
owl:someValuesFrom
• “ To declare that all academic staff members must teach at least
one undergraduate course”
<owl:Class rdf:about="#academicStaffMember">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#teaches"/>
<owl:someValuesFrom rdf:resource=
"#undergraduateCourse"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Web Technologies II 105
Cardinality Restrictions
• We can specify minimum and maximum number using owl:minCardinality and
owl:maxCardinality
• It is possible to specify a precise number by using the same minimum and
maximum number
• For convenience, OWL offers also owl:cardinality
<owl:Class rdf:about="#course">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#isTaughtBy"/>
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1
</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Web Technologies II 106
Special Properties
• owl:TransitiveProperty (transitive property)
• E.g. “has better grade than”, “is ancestor of”
• owl:SymmetricProperty (symmetry)
• E.g. “has same grade as”, “is sibling of”
• owl:FunctionalProperty defines a property that has at most one
value for each object
• E.g. “age”, “height”, “directSupervisor”
• owl:InverseFunctionalProperty defines a property for which two
different objects cannot have the same value,
• e.g Voter Id is assigned to one person only.

Web Technologies II 107


Special Properties (2)
<owl:ObjectProperty rdf:ID="hasSameGradeAs">
<rdf:type rdf:resource="&owl;TransitiveProperty"/>
<rdf:type rdf:resource="&owl;SymmetricProperty"/>
<rdfs:domain rdf:resource="#student"/>
<rdfs:range rdf:resource="#student"/>
</owl:ObjectProperty>

Web Technologies II 108


Boolean Combinations
• One can combine classes using Boolean operations (union, intersection,
complement)
• Example: let us say courses and staff members are disjoint classes
<owl:Class rdf:about="#course">
<rdfs:subClassOf>
<owl:Restriction>
<owl:complementOf rdf:resource= "#staffMember"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
• The same can be done using owl:disjointWith
Web Technologies II 109
Boolean Combinations (2)
• It is possible for a staff member to be a student
<owl:Class rdf:ID="peopleAtUni">
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#staffMember"/>
<owl:Class rdf:about="#student"/>
</owl:unionOf>
</owl:Class>
• The new class is not a subclass of the union, but rather equal to the
union

Web Technologies II 110


Boolean Combinations (3)
<owl:Class rdf:ID="facultyInCS">
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:about="#faculty"/>
<owl:Restriction>
<owl:onProperty rdf:resource="#belongsTo"/>
<owl:hasValue rdf:resource= "#CSDepartment"/>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
Web Technologies II 111
Nesting of Boolean Operators
• Let define admin staff to be those staff members that are neither faculty nor
technical support staff
<owl:Class rdf:ID="adminStaff">
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:about="#staffMember"/>
<owl:complementOf>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#faculty"/>
<owl:Class rdf:about="#techSupportStaff"/>
</owl:unionOf>
</owl:complementOf>
</owl:intersectionOf>

Web Technologies II 112


owl:oneOf
• Enumerations with owl:oneOf
<owl:oneOf rdf:parseType="Collection">
<owl:Thing rdf:about="#Monday"/>
<owl:Thing rdf:about="#Tuesday"/>
<owl:Thing rdf:about="#Wednesday"/>
<owl:Thing rdf:about="#Thursday"/>
<owl:Thing rdf:about="#Friday"/>
<owl:Thing rdf:about="#Saturday"/>
<owl:Thing rdf:about="#Sunday"/>
</owl:oneOf>

Web Technologies II 113


Declaring Instances
• Instances of classes are declared as in RDF:
<rdf:Description rdf:ID="949352">
<rdf:type rdf:resource= "#academicStaffMember"/>
</rdf:Description>
• Providing further information
<academicStaffMember rdf:ID="949352">
<uni:age rdf:datatype="&xsd;integer">39</uni:age>
</academicStaffMember>

Web Technologies II 114


No Unique-Names Assumption
• Unlike typical DBMS, OWL does not adopt the unique-names assumption of
database systems
• If two instances have a different name or ID does not imply that they are different individuals
• Represent: each course is taught by atmost one staff member, and that a given
course is taught by two staff members

<owl:ObjectProperty rdf:ID="isTaughtBy">
<rdf:type rdf:resource="&owl;FunctionalProperty" />
</owl:ObjectProperty>
<course rdf:ID="CIT1111">
<isTaughtBy rdf:resource="#949318"/>
<isTaughtBy rdf:resource="#949352"/>
</course>
Web Technologies II 115
Distinct Objects
• To ensure that different individuals are indeed recognized as such, we must
explicitly assert their inequality:
<lecturer rdf:about="949318">
<owl:differentFrom rdf:resource="949352"/>
</lecturer>

Web Technologies II 116


Distinct Objects (2)
• owl:allDifferent asserts pairwise inequality of all individuals in a list
<owl:allDifferent>
<owl:distinctMembers rdf:parseType="Collection">
<lecturer rdf:about="949318"/>
<lecturer rdf:about="949352"/>
<lecturer rdf:about="949111"/>
</owl:distinctMembers>
</owl:allDifferent>

• Note that owl:distinctMembers can only be used in combination with


owl:allDifferent.
Web Technologies II 117
Querying the Semantic Web:
SPARQL

118
Overview
• SPARQL [1] is a query language designed for the Semantic
Web and is the language recommended by W3C for this
use.
• SPARQL is completely integrated into the Semantic Web and
uses other W3C recommendations.
• It assumes that data are represented as RDF graphs, that
resources are identified by IRIs, and that RDF literals are
typed with XML Schema
[1] Prud’hommeaux, E., Seaborne, A. (ed.): SPARQL query language for RDF, W3C Recommendation. World
Wide Web Consortium (2008)
Web Technologies II 119
SPARQL
• SPARQL stands for “SPARQL Protocol and RDF Query Language”.

• In addition to the language, W3C has also defined:


• The SPARQL Protocol for RDF specification: it defines the
remote protocol for issuing SPARQL queries and receiving the
results.
• The SPARQL Query Results XML Format specification: it defines
an XML document format for representing the results of SPARQL
queries.

Web Technologies II
SPARQL Basics
• SPARQL is based on matching graph patterns against RDF graphs.
• What is a graph pattern?
• To define graph patterns, we must first define triple patterns:
• A triple pattern is like an RDF triple, but with the option of a variable in
place of RDF terms (i.e., IRIs, literals or blank nodes) in the subject,
predicate or object positions.

• Example:

<http://example.org/book/book1>
<http://purl.org/dc/elements/1.1/title> ?title .

• ?title is a variable.
Web Technologies II
SPARQL Basics
• SPARQL is based on matching graph patterns against RDF graphs.

• What is a graph pattern?

Web Technologies II
Anatomy of a SPARQL Query
• A SPARQL query is composed of five
parts:
• zero or more prefix declarations,
• a query result clause,
• zero or more FROM or FROM NAMED
clauses,
• a WHERE clause,
• and zero or more query modifiers.
SELECT ?subject ?predicate ?object
WHERE {
?subject ?predicate ?object .
}
Web Technologies II 123
Anatomy of a SPARQL Query (2)
• Query result clause: specifies the form of the result.
• A SPARQL query can take four forms: SELECT, ASK, CONSTRUCT, and DESCRIBE.
• SELECT queries provide answers in a tabular form as if the SPARQL query were a SQL query
executed against a relational database.
• The ASK form checks whether the SPARQL endpoint can provide at least one result; if it does,
the answer to the query is YES, otherwise the answer is NO.
• The CONSTRUCT form is similar to the SELECT form, but it provides the answer to the query as
an RDF graph.
• The DESCRIBE form is conceived to retrieve information from a SPARQL endpoint without
knowing the vocabulary in use, producing as result an RDF graph.
• The optional set of FROM or FROM NAMED clauses define the dataset against which
the query is executed.
• The WHERE clause is the core of a SPARQL query. It is specified in terms of a set of
triple patterns.

Web Technologies II 124


Examples

CONSTRUCT {
?person foaf:knows ?friend .
} SELECT Queries:
WHERE { •Used to retrieve specific variables
?person rdf:type foaf:Person . (bindings) from the data.
?person foaf:knows ?friend .
} SELECT ?name ?age
WHERE {
?person rdf:type foaf:Person .
•Determine whether a specific pattern exists in the data. ?person foaf:name ?name .
?person foaf:age ?age .
ASK { }
?person rdf:type foaf:Person .
?person foaf:name "Alice" .
}

Web Technologies II
Basic Patterns
• SPARQL is a query language for pattern matching against RDF graphs.
• A query contains at least a triple pattern.
• A triple pattern is like an RDF triple except that the subject, the predicate,
and the object may be a variable.
• Syntactically a variable is formed by a question mark ‘‘?’’ followed by a term,
for example, ?name.
• A triple pattern matches the triples in the RDF data whose RDF terms may be
substituted for the variables.

Example: ?s skos:broader dbpcat:Visitor_attractions_in_Milan .

Web Technologies II 126


Basic Patterns (2) (Example)

Example triple pattern 1: ?s skos:broader dbpcat:Visitor_attractions_in_Milan .

Example triple pattern 2: ?s ?p dbpcat:Visitor_attractions_in_Milan .


127
Basic graph pattern
• It is a set of triple patterns.
• A basic graph pattern matches a sub-graph of the RDF data when the
variables in the graph pattern substitute the RDF terms.
1. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
?s rdf:type skos:Concept . 2. @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
3. @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
?s skos:broader ?o . 4. @prefix dbpedia: <http://dbpedia.org/resource/> .
5. @prefix dbpcat: <http://dbpedia.org/resource/Category:> .
6. dbpcat:Visitor_attractions_in_Milan
7. rdf:type skos:Concept ;
8. rdfs:label “Visitor attractions in Milan”@en ;
9. skos:prefLabel “Visitor attractions in Milan”@en ;
10. skos:broader dbpcat:Milan ,
11. dbpcat:Visitor_attractions_in_Italy ,
12. dbpcat:Visitor_attractions_by_city .
13. dbpcat:Museums_in_Milan skos:broader dbpcat:Visitor_attractions_in_Milan .
14. dbpcat:Churches_in_Milan skos:broader dbpcat:Visitor_attractions_in_Milan .
15. dbpcat:Piazzas_in_Milan skos:broader dbpcat:Visitor_attractions_in_Milan .
16. dbpcat:Gardens_in_Milan skos:broader dbpcat:Visitor_attractions_in_Milan .
17. dbpedia:Biblioteca_Ambrosiana skos:subject dbpcat:Visitor_attractions_in_Milan .
18. dbpedia:Brera_Academ skos:subject dbpcat:Visitor_attractions_in_Milan .
19. dbpedia:Via_Montenapoleone skos:subject dbpcat:Visitor_attractions_in_Milan .
20. dbpedia:Castello_Sforzesco skos:subject dbpcat:Visitor_attractions_in_Milan .
Web Technologiesskos:subject dbpcat:Visitor_attractions_in_Milan . 128
21. dbpedia:Pinacoteca_di_Brer
Sample query
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?s ?o
FROM <http://dbpedia.org/data/Category:Visitor_attractions_in_Milan.rdf>
WHERE {?s rdf:type skos:Concept.
?s skos:broader ?o . }

?s ?o
dbcat:Visitor_attractions_in_Milan dbcat:Visitor_attractions_by_city
dbcat:Visitor_attractions_in_Milan dbcat:Visitor_attractions_in_Italy
dbcat:Visitor_attractions_in_Milan dbcat:Milan

129
Matching RDF Literals
• Literals in RDF contains language and data-type information and hence the
matching may not return matched graph. For instance
• “Milan Cathedral”@en (label in English), “Milan Cathedral”@it (in Italy) ,
“40000”^^xsd:integer (no of population)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?s
FROM <http://dbpedia.org/data/Milan_Cathedral.rdf>
WHERE { ?s rdfs:label “Milan Cathedral”. }

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


SELECT ?s
FROM <http://dbpedia.org/data/Milan_Cathedral.rdf>
WHERE { ?s rdfs:label “Milan Cathedral”@en. }
Web Technologies 130
RDF Term Constraints
• SPARQL allows restrictions of the solutions by constructing constraints within FILTER clauses.
• An RDF term bound to a variable appears in the results if the constraint in the FILTER expression,
applied to the term, evaluates to TRUE.

PREFIX dbpprop: <http://dbpedia.org/property/>


SELECT ?s
FROM <http://dbpedia.org/data/Milan_Cathedral.rdf>
WHERE { ?s dbpprop:capacity ?c .
FILTER (?c > 50000 ) }
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?s
FROM <http://dbpedia.org/data/Milan_Cathedral.rdf>
WHERE { ?s rdfs:label ?l .
FILTER (regex(str(?l), ‘Cathedral’ ) || (?c > 50000 ) ) }

Web Technologies 131


Optional patterns

132
Optional patterns

133
Union – to provide alternative graph pattern
Solution Modifiers Input Modifier Output
• Projection modifier: Select
• Order Modifier: Order by
• Distinct and reduced modifier: Distinct and reduced
• Limit and offset modifier: Limit, offset

Web Technologies
Query Forms CONSTRUCT, ASK, and DESCRIBE
• The CONSTRUCT query form returns an RDF graph specified by the query
designer as graph template.
• Example: the graph template at row 4 states that a church is an
ex:Big_Church if it has a capacity larger than 30,000 people.

Web Technologies 136


Query Forms CONSTRUCT, ASK, and DESCRIBE
• The CONSTRUCT query form returns an RDF graph specified by the query
designer as graph template.

Web Technologies 137


ASK Form
• ASK is applicable to check if a given query can be answered by a SPARQL
endpoint, without being interested in the actual result.
• When an ASK query is issued to a SPARQL processor, the processor answers
whether or not a solution exists.

Web Technologies 138


DESCRIBE Form
• A DESCRIBE SPARQL query returns an RDF graph determined by the SPARQL
endpoint.
• The query can have two forms: the very simple or the slightly more
complex

Web Technologies 139


end of chapter 5

Web Technologies

You might also like