Διδάσκων: Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής...

207
ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ, ΑΠΘ ΜΕΤΑΠΤΥΧΙΑΚΟ ΠΡΟΓΡΑΜΜΑ ΣΠΟΥΔΩΝ Κατεύθυνση Πληροφοριακών Συστημάτων - 1ο Εξάμηνο Σημασιολογικός Ιστός lpis.csd.auth.gr/mtpx/sw/index.htm Διδάσκων: Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ Μαθήματα: 5-6

description

ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ , ΑΠΘ ΜΕΤΑΠΤΥΧΙΑΚΟ ΠΡΟΓΡΑΜΜΑ ΣΠΟΥΔΩΝ Κατεύθυνση Πληροφοριακών Συστημάτων - 1 ο Εξάμηνο Σημασιολογικός Ιστός lpis .csd.auth.gr/mtpx/sw/index.htm. Διδάσκων: Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ. Μαθήματα: 5-6. Chapter 3 Describing Web Resources in RDF . - PowerPoint PPT Presentation

Transcript of Διδάσκων: Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής...

Page 1: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ, ΑΠΘ ΜΕΤΑΠΤΥΧΙΑΚΟ ΠΡΟΓΡΑΜΜΑ ΣΠΟΥΔΩΝ

Κατεύθυνση Πληροφοριακών Συστημάτων - 1ο Εξάμηνο

Σημασιολογικός Ιστόςlpis.csd.auth.gr/mtpx/sw/index.htm

Διδάσκων: Ν. ΒασιλειάδηςΑναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Μαθήματα: 5-6

Page 2: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3Describing Web Resources in RDF

Grigoris AntoniouFrank van Harmelen

Page 3: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-3

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

Page 4: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-4

Drawbacks of XML

XML is a universal metalanguage for defining markup

It provides a uniform framework for interchange of data and metadata between applications

However, XML does not provide any means of talking about the semantics (meaning) of data

E.g., there is no intended meaning associated with the nesting of tags– It is up to each application to interpret the nesting.

Page 5: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-5

<faculty><lecturers><lecturer><name>John Smith</name><teaches><course><name>Algorithms</name><student>aem153</student> <student>aem202</student>…</course></teaches></lecturer></lecturers>

</faculty>

Nesting of tag A in B can be interpreted as:– Α is a part of Β– Α is a subset of Β– Α is a member of Β– Α is a property of Β

Nesting of Tags in XML

Page 6: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-6

Nesting of Tags in XML

David Billington is a lecturer of Discrete Maths<course name="Discrete Maths">

<lecturer>David Billington</lecturer></course><lecturer name="David Billington">

<teaches>Discrete Maths</teaches></lecturer>Opposite nesting, same information!

Page 7: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-7

Basic Ideas of RDF

All information is represented as a set of Statements

Basic building block (statement): object-attribute-value triple (or triplet)– Sentence about Billington is such a statement

RDF has been given a syntax in XML– This syntax inherits the benefits of XML– Other syntactic representations of RDF possible

Page 8: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-8

Basic Ideas of RDF (2)

The fundamental concepts of RDF are:– Resources (objects, sometimes values)– Properties (attributes)– Statements (triplets)

Page 9: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-9

Resources

We can think of a resource as an object, a “thing” we want to talk about– E.g. authors, books, publishers, places, people,

hotels Every resource has a URI, a Universal

Resource Identifier A URI can be

– a URL (Web address) or – some other kind of unique identifier

Page 10: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-10

URIs

An identifier does not necessarily enable access to a resource.

URI schemes have been defined not only for web-locations – E.g. telephone numbers, ISBN numbers (urn:isbn:960-

7013-28-Χ), geographic locations, etc. There has been a long discussion about the nature

of URIs, even touching philosophical questions – E.g., what is an appropriate unique identifier for a person?– We assume that a URI is the identifier of a Web resource.

Page 11: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-11

Properties

Properties describe relations between resources– E.g. “written by”, “age”, “title”, etc.

Properties are a special kind of resources– Also identified by URIs

Advantages of using URIs:– Α global, worldwide, unique naming scheme– Reduces the homonym problem of distributed data

representation

Page 12: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-12

Statements

Statements assert the properties of resources– Similar to a statement in natural language

A statement is an object-attribute-value triple– It consists of a resource, a property, and a value– NL view: subject - predicate - object

Values can be resources or literals – Literals are atomic values (strings)

Page 13: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-13

Three Views of a Statement

A triple A piece of a graph A piece of XML codeThus an RDF document can be viewed as: A set of triples A graph (semantic net) An XML document

Page 14: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-14

Statements as Triples

( http://www.cit.gu.edu.au/~db, http://www.mydomain.org/site-owner, “David Billington” )

The triple (x,P,y) can be considered as a logical formula P(x,y) (atomic proposition)– Binary predicate P relates object x to object y – RDF offers only binary predicates (properties)

Page 15: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Turtle syntax

Terse RDF Triple Language (Turtle) is a text based syntax for RDF. – The file extension used for Turtle text files is “.ttl”

<http://www.cit.gu.edu.au/~db> <http://www.mydomain.org/site-owner> “David Billington” .

3-15 A Semantic Web Primer, 2nd EditionChapter 3

Page 16: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-16

Statements as Graphs

A directed graph with labeled nodes and arcs– from the resource (the subject of the statement) – to the value (the object of the statement)

Known in AI as a semantic net The value of a statement may be a resource

– Ιt may be linked to other resources

Page 17: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-17

A Set of Triples as a Semantic Net

Page 18: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Note on the example

In this case, David Bilington should be a resource– NOT a literal

<http://www.cit.gu.edu.au/~db> <http://www.mydomain.org/site-owner> <http://www.cit.gu.edu.au/faculty#DavidBilington> .

3-18 Chapter 3 A Semantic Web Primer, 2nd Edition

Page 19: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-19

Statements in XML Syntax

Graphs are a powerful tool for human understanding but

The Semantic Web vision requires machine-accessible and machine-processable representations

There is a 3rd representation based on XML– But XML is not a part of the RDF data model– E.g. serialisation of XML is irrelevant for RDF

Page 20: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-20

Statements in XML (2)

<rdf:RDFxmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-

ns#"xmlns:ex="http://www.mydomain.org/my-rdf-ns">

<rdf:Description rdf:about="http://www.cit.gu.edu.au/~db">

<ex:site-owner> David Billington </ex:site-owner>

</rdf:Description></rdf:RDF>

subject

predicateobject

Page 21: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-21

Statements in XML (3)

An RDF document is represented by an XML element with the tag rdf:RDF

The content of this element is a number of descriptions, which use rdf:Description tags.

Every description makes a statement about a resource, identified in 3 ways:– an about attribute, referencing an existing resource– an ID attribute, creating a new resource– without a name, creating an anonymous resource

Page 22: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-22

Statements in XML (4)

The rdf:Description element makes a statement about the resource http://www.cit.gu.edu.au/~db

Within the description– the property is used as a tag– the content is the value of the property

Page 23: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-23

Data Types

Data types are used in programming languages to allow interpretation

In RDF, typed literals are used, if necessary<http://www.cit.gu.edu.au/faculty#DavidBilington>

<http://www.mydomain.org/age>“27”^^<http://www.w3.org/2001/XMLSchema#integer> .

Page 24: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-24

Data Types (2)

^^-notation indicates the type of a literal In practice, the most widely used data typing

scheme will be the one by XML Schema – But the use of any externally defined data typing

scheme is allowed in RDF documents XML Schema predefines a large range of

data types– E.g. Booleans, integers, floating-point numbers,

times, dates, etc.

Page 25: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-25

A Critical View of RDF: Properties

Properties are special kinds of resources – Properties can be used as the object in an object-

attribute-value triple (statement)– They are defined independent of resources

This possibility offers flexibility But it is unusual for modelling languages and

OO programming languages– It can be confusing for modellers

Page 26: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-26

A Critical View of RDF: XML Syntax

The XML-based syntax of RDF is well suited for machine processing

It is not particularly human-friendly– The Semantic Web will not be programmed in

RDF, but rather with user-friendly tools that will automatically translate higher representations (e.g. icons) into RDF.

Page 27: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-27

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

Page 28: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-28

XML-Based Syntax of RDF

An RDF document consists of an rdf:RDF element– The content of that element is a number of

descriptions A namespace mechanism is used

– Disambiguation– Namespaces are expected to be RDF documents

defining resources that can be reused– Large, distributed collections of knowledge

Page 29: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-29

Example of University Courses

<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">

]><rdf:RDF

xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:uni="http://www.mydomain.org/uni-ns#">

<rdf:Description rdf:about=“http://...#T949318"><uni:name>David Billington</uni:name><uni:title>Associate Professor</uni:title><uni:age rdf:datatype="&xsd;integer">27</uni:age>

</rdf:Description>

Page 30: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-30

Example of University Courses (2)

<rdf:Description rdf:about=“http://...# CIT1111"><uni:courseName>Discrete

Maths</uni:courseName><uni:isTaughtBy>David

Billington</uni:isTaughtBy></rdf:Description>

<rdf:Description rdf:about=“http://...# CIT2112"><uni:courseName>Programming

III</uni:courseName><uni:isTaughtBy>Michael Maher</uni:isTaughtBy>

</rdf:Description>

</rdf:RDF>

Page 31: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-31

ENTITY definition

Entities are like macros (e.g. #define) in programming languages

If something is declared as an ENTITY, it can be used in the XML document with (&) in front and (;) at the back– E.g. &xsd;

Page 32: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-32

rdf:about versus rdf:ID

An element rdf:Description has– An rdf:about attribute indicating that the resource

has been “defined” elsewhere, or– An rdf:ID attribute indicating that the resource is

defined here Formally, there is no such thing as “defining” an

object in one place and referring to it elsewhere – Sometimes is useful (for human readability) to have

a defining location, while other locations state “additional” properties

Page 33: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-33

Referencing with rdf:about

For a correct RDF document, all occurrences of course and staff ID’s (e.g. CIT3112) should be represented by references to the external namespace

<rdf:Description rdf:about="http://www.mydomain.org/uni-ns#CIT3112">

… or with an entity declaration<rdf:Description rdf:about="&uni;CIT3112">

Page 34: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Referencing with rdf:about

The use of “#” in front of a “local name” indicates that the resource is a part of the current document

<rdf:Description rdf:about="#CIT3112">

– The full URI of the resource is obtained by the URI of the current document, plus “#CIT3112”

3-34 A Semantic Web Primer, 2nd EditionChapter 3

Page 35: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-35

Property Elements

Content of rdf:Description elements<rdf:Description rdf:about=" http://...# CIT3116">

<uni:courseName>Knowledge Representation</uni:courseName><uni:isTaughtBy>Grigoris Antoniou</uni:isTaughtBy>

</rdf:Description> uni:courseName and uni:isTaughtBy define

two property-value pairs for CIT3116 (two RDF statements)– read conjunctively

Page 36: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-36

Data Types

The attribute rdf:datatype="&xsd;integer" is used to indicate the data type of the value of the age property

<rdf:Description rdf:about="http://...#T949318"><uni:name>David Billington</uni:name><uni:title>Associate Professor</uni:title><uni:age rdf:datatype="&xsd;integer">27<uni:age>

</rdf:Description>

Page 37: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-37

Data Types (2)

The age property has been defined to have "&xsd;integer" as its range– It is still required to indicate the type of the value of

this property each time it is used– This is to ensure that an RDF processor can assign

the correct type of the property value even if it has not "seen" the corresponding RDF Schema definition before

– This scenario is quite likely to occur in the unrestricted WWW

Page 38: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Languages

RDF/XML permits the use of the xml:lang attribute to allow the identification of content language.

Can be used on any property element to indicate that the included content is in the given language. – Typed literals are not affected by this attribute.

<rdf:Description rdf:about="http://...#T997913"><uni:name xml:lang=“en”>Nick Bassiliades</uni:name><uni:name xml:lang=“el”>Νίκος Βασιλειάδης</uni:name>

</rdf:Description>

Chapter 3 A Semantic Web Primer, 2nd Edition3-38

Page 39: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-39

The rdf:resource Attribute

The relationships between courses and lecturers (in the example) were not formally defined but existed implicitly through the use of the same name

The use of the same name may just be a coincidence for a machine

We can denote that two entities are the same using the rdf:resource attribute

Page 40: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-40

The rdf:resource Attribute (2)

<rdf:Description rdf:about="http://...#CIT1111"><uni:courseName>Discrete Mathematics</uni:courseName><uni:isTaughtBy

rdf:resource=“http://...#T949318"/></rdf:Description><rdf:Description rdf:about="http://...#T949318">

<uni:name>David Billington</uni:name><uni:title>Associate Professor</uni:title>

</rdf:Description>

Page 41: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-41

Referencing Externally Defined Resources

E.g., to refer the externally defined resource CIT1111:http://www.mydomain.org/uni-ns#CIT1111 as the value of rdf:about– www.mydomain.org/uni-ns is the URI where the

definition of CIT1111 is found A description with an ID defines a fragment

URI, which can be used to reference the defined description

Page 42: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

The rdf:resource Attribute (3)

<rdf:Description rdf:about="http://...#CIT1111"><uni:courseName>Discrete Mathematics</uni:courseName><uni:isTaughtBy rdf:resource=“#T949318"/>

</rdf:Description><rdf:Description rdf:ID=“T949318">

<uni:name>David Billington</uni:name><uni:title>Associate Professor</uni:title>

</rdf:Description>

3-42 A Semantic Web Primer, 2nd EditionChapter 3

Page 43: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-43

Nested Descriptions: Example

<rdf:Description rdf:about=“http://.../uni-ns#CIT1111"><uni:courseName>Discrete

Maths</uni:courseName><uni:isTaughtBy>

<rdf:Description rdf:ID=“T949318"><uni:name>David

Billington</uni:name><uni:title>Associate

Professor</uni:title></rdf:Description>

</uni:isTaughtBy></rdf:Description>

Page 44: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-44

Nested Descriptions

Descriptions may be defined within other descriptions

Other courses, such as CIT3112, can still refer to the new resource with ID T949318

Although a description may be defined within another description, its scope is global

Page 45: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-45

Introducing some Structure to RDF Documents using the rdf:type Element

In the examples, the descriptions fall into 2 categories: courses and lecturers.

This is clear to human readers It has not been formally declared anywhere It is not accessible to machines In RDF it is possible to make such

statements using the rdf:type element.

Page 46: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-46

Example of using the rdf:type Element

<rdf:Description rdf:ID="CIT1111"><rdf:type rdf:resource="http://www.mydomain.org/uni-

ns#course"/><uni:courseName>Discrete Maths</uni:courseName><uni:isTaughtBy rdf:resource="#T949318"/>

</rdf:Description><rdf:Description rdf:ID="T949318">

<rdf:type rdf:resource="http://www.mydomain.org/uni-ns#lecturer"/>

<uni:name>David Billington</uni:name><uni:title>Associate Professor</uni:title>

</rdf:Description>

Page 47: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-47

Abbreviated Syntax Simplification rules:

1. Childless property elements within description elements may be replaced by XML attributes

2. For description elements with a typing element we can use the name specified in the rdf:type element instead of rdf:Description

These rules create syntactic variations of the same RDF statement– They are equivalent according to the RDF data

model, although they have different XML syntax

Page 48: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-48

Abbreviated Syntax: Example

<rdf:Description rdf:ID="CIT1111"><rdf:type

rdf:resource="http://www.mydomain.org/uni-ns#course"/>

<uni:courseName>Discrete Maths</uni:courseName>

<uni:isTaughtBy rdf:resource="#T949318"/></rdf:Description>

Page 49: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-49

Application of First Simplification Rule

<rdf:Description rdf:ID="CIT1111"uni:courseName="Discrete Maths">

<rdf:type rdf:resource="http://www.mydomain.org/

uni-ns#course"/><uni:isTaughtBy rdf:resource="#T949318"/>

</rdf:Description>

Page 50: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-50

Application of 2nd Simplification Rule

<uni:course rdf:ID="CIT1111"uni:courseName="Discrete Maths">

<uni:isTaughtBy rdf:resource="#T949318"/></uni:course>

Page 51: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-51

RDF Collections

Collect a number of resources together and make statements for them as a whole

RDF collections: groups containing only the specified members– list structure in the RDF graph – constructed using a predefined collection vocabulary:

rdf:List, rdf:first, rdf:rest and rdf:nil It is like Prolog/LISP lists or linked lists in data

structures

Page 52: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-52

RDF Collections (2)A list with 3 elements<rdf:Description rdf:about="#CIT2112">

<uni:isTaughtBy><rdf:List>

<rdf:first><rdf:Description rdf:about="#T949111"/></rdf:first>

<rdf:rest><rdf:List>

<rdf:first><rdf:Description rdf:about="#T949352"/></rdf:first>

<rdf:rest><rdf:List>

<rdf:first><rdf:Description rdf:about="#T949318"/></rdf:first>

<rdf:rest><rdf:Description rdf:about="rdf:nil"/></rdf:rest></rdf:List>

</rdf:rest></rdf:List>

Page 53: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

3-53

RDF Collections (3)A list with 3 elements

#T949111 #T949352 #T949318 rdf:nilrdf:rest

rdf:first

rdf:rest rdf:rest

rdf:first rdf:first

rdf:List

rdf:List

rdf:List

Chapter 3 A Semantic Web Primer, 2nd Edition

Page 54: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-54

RDF Collections (4)A list with 3 elements Shorthand syntax:

– "Collection" value for the rdf:parseType attribute:

<rdf:Description rdf:about="#CIT2112"><uni:isTaughtBy

rdf:parseType="Collection"><rdf:Description

rdf:about="#T949111"/><rdf:Description

rdf:about="#T949352"/><rdf:Description

rdf:about="#T949318"/></uni:isTaughtBy>

</rdf:Description>

Page 55: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Parsing RDF/XML

There are many RDF parsers, i.e. tools that take as input and RDF/XML document and output a set of RDF triples– These are called “explicit triplets”

The most prominent one is the W3C RDF parser/validator– http://www.w3.org/RDF/Validator/

3-55 A Semantic Web Primer, 2nd EditionChapter 3

Page 56: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

W3C RDF Validation/Parsing

3-56A Semantic Web Primer, 2nd EditionChapter 3

Page 57: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

RDF Validation Results - Triples

3-57 A Semantic Web Primer, 2nd EditionChapter 3

<http://www.mydomain.org/uni-ns#T949318> <http://www.mydomain.org/uni-ns#name> "David Billington" .<http://www.mydomain.org/uni-ns#T949318> <http://www.mydomain.org/uni-ns#title> "Associate Professor" .<http://www.mydomain.org/uni-ns#T949318>

<http://www.mydomain.org/uni-ns#age> "27"^^<http://www.w3.org/2001/XMLSchema#integer> .

<http://www.mydomain.org/uni-ns#CIT1111> <http://www.mydomain.org/uni-ns#courseName> "Discrete Maths" .<http://www.mydomain.org/uni-ns#CIT1111>

<http://www.mydomain.org/uni-ns#isTaughtBy> <http://www.mydomain.org/uni-ns#T949318> .

Page 58: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

RDF Validation Results - Graph

3-58 A Semantic Web Primer, 2nd EditionChapter 3

Page 59: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

@prefix uni: <http://www.mydomain.org/uni-ns#>. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. uni:CIT1111 uni:courseName "Discrete Maths";

uni:isTaughtBy uni:T949318. uni:T949318 uni:age "27"^^<&xsd;integer>;

uni:name "David Billington"; uni:title "Associate Professor".

Turtle syntax

3-59 A Semantic Web Primer, 2nd Edition

The sign “;” indicates that the subsequent triples share the same subject with the first triple

This is how namespaces are declared

Chapter 3

Page 60: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Turtle syntax (or N3)

You can use – http://www.rdfabout.com/demo/validator/– http://rdf-translator.appspot.com/

Other features of Turtle syntax:– Allows to abbreviate common data types

uni:T949318 uni:age 27 .– Named graphs: a way to treat a set of triples as a

single resource

3-60 A Semantic Web Primer, 2nd EditionChapter 3

Page 61: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Named Graphs

@prefix uni: <http://www.mydomain.org/uni-ns#>. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix dc: <http://purl.org/dc/terms/>.{

<http://www.mydomain.org/lecturers.ttl#> dc:creator <http://www.csd.auth.gr/~nbassili>

}<http://www.mydomain.org/lecturers.ttl#>{

uni:CIT1111 uni:courseName "Discrete Maths"; uni:isTaughtBy uni:T949318.

uni:T949318 uni:age "27"^^<&xsd;integer>; uni:name "David Billington"; uni:title "Associate Professor".

}3-61 A Semantic Web Primer, 2nd EditionChapter 3

Page 62: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-62

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

Page 63: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-63

Basic Ideas of RDF Schema

RDF is a universal language that lets users describe resources in their own vocabularies – RDF does not assume, nor does it define

semantics of any particular application domain The user can do so in RDF Schema using:

– Classes and Properties– Class Hierarchies and Inheritance– Property Hierarchies

Page 64: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-64

Classes and their Instances

We must distinguish between– Concrete “things” (individual objects) in the

domain: Discrete Maths, David Billington etc.– Sets of individuals sharing properties called

classes: lecturers, students, courses etc. Individual objects that belong to a class are

referred to as instances of that class The relationship between instances and

classes in RDF is through rdf:type

Page 65: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-65

Why Classes are Useful

Impose restrictions on what can be stated in an RDF document using the schema – Disallow nonsense from being stated– As in programming languages, eg A+1, where A is an array

Infer what class an instance belongs to by observing what has been stated for the instance that is usually stated for instances of a certain class

Group instances with similar properties together– E.g. for querying

Page 66: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-66

Nonsensical Statements disallowed through the Use of Classes

Discrete Maths is taught by Concrete Maths– We want courses to be taught by lecturers only – Restriction on values of the property “is taught by”

(range restriction) Room MZH5760 is taught by David Billington

– Only courses can be taught– This imposes a restriction on the objects to which

the property can be applied (domain restriction)

Page 67: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-67

Class Hierarchies

Classes can be organised in hierarchies– A is a subclass of B if every instance of A

is also an instance of B – Then B is a superclass of A

A subclass graph need not be a tree – A class may have multiple superclasses

Page 68: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-68

Class Hierarchy Example

Page 69: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-69

Inheritance in Class Hierarchies

Range restriction: Courses must be taught by academic staff members only

Michael Maher is a professor – He inherits the ability to teach from the class of

academic staff members This is done in RDF Schema by fixing the

semantics of “is a subclass of”– It is not up to an application (RDF processing

software) to interpret “is a subclass of”

Page 70: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-70

Differences with Object-Oriented Programming

In OO programming, an object class defines the properties that apply to it. – To add new properties we modify the class.

In RDFS, properties are defined globally– Not encapsulated as attributes in class definitions– Define new properties for an existing class without changing

the class Use classes defined by others and adapt them to our

requirements through new properties. – Another idiosyncratic feature of RDF/RDFS.

Page 71: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-71

Property Hierarchies

Hierarchical relationships for properties– E.g., “is taught by” is a subproperty of “involves” – If a course C is taught by an academic staff member A, then

C also involves Α The converse is not necessarily true

– E.g., A may be the teacher of the course C, or – a tutor who marks student homework but does not teach C

P is a subproperty of Q, if Q(x,y) is true whenever P(x,y) is true

– E.g. father is a subproperty of parent

Page 72: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-72

RDF Layer vs RDF Schema Layer

Discrete Mathematics is taught by David Billington

The schema is itself written in a formal language, RDF Schema, that can express its ingredients: – subClassOf, Class, Property,

subPropertyOf, Resource, etc.

Page 73: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

RDF Layer vs RDF Schema Layer (2)

Chapter 33-73 A Semantic Web Primer, 2nd Edition

Page 74: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-74

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

Page 75: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

RDF Schema in RDF

The modeling primitives of RDF Schema are defined using resources and properties (RDF itself is used!)

To declare that “lecturer” is a subclass of “academic staff member”– Define resources lecturer, academicStaffMember– State that they are classes– define property subClassOf (already done in RDFS

namespace)– Write triple (lecturer, subClassOf, academicStaffMember)

We use the XML-based syntax of RDFChapter 3 A Semantic Web Primer, 2nd Edition3-75

Page 76: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-76

Core Classes

rdfs:Resource, the class of all resources

rdfs:Class, the class of all classes rdfs:Literal, the class of all literals

(strings) rdf:Property, the class of all properties.

Page 77: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-77

Core Properties

rdf:type, relates a resource to its class – The resource is declared to be an instance of that

class rdfs:subClassOf, relates a class to one of its

superclasses– All instances of a class are instances of its

superclass rdfs:subPropertyOf, relates a property to

one of its superproperties

Page 78: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-78

Core Properties (2)

rdfs:domain, specifies the domain of a property P– The class of those resources that may appear as

subjects in a triple with predicate P– If the domain is not specified, then any resource can

be the subject rdfs:range, specifies the range of a property P

– The class of those resources that may appear as values in a triple with predicate P

Page 79: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-79

Examples (abbreviated syntax)

<rdfs:Class rdf:about="#lecturer"><rdfs:subClassOf rdf:resource="#staffMember"/>

</rdfs:Class>

<rdf:Property rdf:ID="phone"><rdfs:domain

rdf:resource="#staffMember"/><rdfs:range

rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>

</rdf:Property>

Page 80: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-80

Examples (long syntax)

<rdf:Description rdf:about="#lecturer"><rdf:type rdf:resource =“http://www.w3.org/2000/01/rdf-schema#Class”/><rdfs:subClassOf rdf:resource="#staffMember"/>

</rdf:Description>

<rdf:Description rdf: rdf:ID="phone"><rdf:type rdf:resource =“http://www.w3.org/1999/02/22-rdf-syntax-ns#Property”/><rdfs:domain rdf:resource="#staffMember"/><rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>

</rdf:Description>

Page 81: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-81

Relationships Between Core Classes and Properties

rdfs:subClassOf and rdfs:subPropertyOf are transitive, by definition

rdfs:Class is a subclass of rdfs:Resource– Because every class is a resource

rdfs:Resource is an instance of rdfs:Class – rdfs:Resource is the class of all resources, so it is a

class Every class is an instance of rdfs:Class

– For the same reason

Page 82: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-82

Subclass Hierarchy of some Modeling Primitives of RDF Schema

rdfs:Resource

rdfs:Class rdf:Property rdfs:Literal

rdfs:Datatype rdf:XMLLiteral

Page 83: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-83

Instance Relationships of some Modeling Primitives of RDFS

rdfs:Class

rdfs:Resource rdf:Property rdfs:Literal

rdfs:Datatype rdf:XMLLiteral

Page 84: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-84

Instance Relationships of Some Core Properties of RDF and RDF Schema

rdf:Property

rdfs:domain

rdf:range

rdf:type

rdfs:subClassOf rdfs:subPropertyOf

Page 85: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Collections

rdf:List, the class of all Lists rdf:first, the first item of the list (property) rdf:rest, the rest of the items of the list, not

including the first item (property)– This is always a list

rdf:nil, the empty list (special instance of the rdf:List class)

3-85 Chapter 3 A Semantic Web Primer, 2nd Edition

Page 86: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-86

Utility Properties

rdfs:seeAlso relates a resource to another resource that explains it

rdfs:isDefinedBy is a subproperty of rdfs:seeAlso and relates a resource to the place where its definition, typically an RDF schema, is found

rdfs:comment. Comments, typically longer text, can be associated with a resource

rdfs:label. A human-friendly label (name) is associated with a resource

Page 87: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-87

Example: A University

<rdfs:Class rdf:ID=“Lecturer"><rdfs:comment>

The class of lecturers. All lecturers are academic staff members.</rdfs:comment><rdfs:subClassOf

rdf:resource="#AcademicStaffMember"/></rdfs:Class>

Page 88: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-88

Example: A University (2)

<rdfs:Class rdf:ID=“AcademicStaffMember"><rdfs:comment> The class of academic staff members</rdfs:comment><rdfs:subClassOf rdf:resource="#StaffMember"/>

</rdfs:Class>

<rdfs:Class rdf:ID=“StaffMember"><rdfs:comment>The class of staff members </rdfs:comment>

</rdfs:Class>

Page 89: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-89

Example: A University (3)

<rdfs:Class rdf:ID=“Course"><rdfs:comment>The class of courses</rdfs:comment>

</rdfs:Class>

<rdf:Property rdf:ID="involves"><rdfs:comment>It relates only courses to lecturers</rdfs:comment><rdfs:domain rdf:resource="#Course"/><rdfs:range rdf:resource="#Lecturer"/>

</rdf:Property>

Page 90: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-90

Example: A University (4)

<rdf:Property rdf:ID="isTaughtBy"><rdfs:comment>

Inherits its domain ("course") and range ("lecturer") from its superproperty "involves"</rdfs:comment><rdfs:subPropertyOf rdf:resource="#involves"/>

</rdf:Property>

Page 91: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-91

Example: A University (5)

<rdf:Property rdf:ID="phone"><rdfs:comment>

It is a property of staff membersand takes literals as values.

</rdfs:comment><rdfs:domain rdf:resource="#StaffMember"/><rdfs:range rdf:resource=“&xsd;integer"/>

</rdf:Property>

Page 92: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-92

Class Hierarchy for the Motor Vehicles Example

Page 93: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-93

Example: Motor Vehicles (1)

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-

ns#"xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">

<rdfs:Class rdf:ID=“MotorVehicle"/><rdfs:Class rdf:ID=“Van">

<rdfs:subClassOf rdf:resource="#MotorVehicle"/></rdfs:Class><rdfs:Class rdf:ID=“Truck">

<rdfs:subClassOf rdf:resource="#MotorVehicle"/></rdfs:Class>

Page 94: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-94

Example: Motor Vehicles (2)

<rdfs:Class rdf:ID=“PassengerVehicle"><rdfs:subClassOf rdf:resource="#MotorVehicle"/>

</rdfs:Class><rdfs:Class rdf:ID=“MiniVan">

<rdfs:subClassOf rdf:resource="#PassengerVehicle"/>

<rdfs:subClassOf rdf:resource="#Van"/></rdfs:Class>

</rdf:RDF>

Page 95: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-95

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

Page 96: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-96

The Namespace of RDF<http://www.w3.org/1999/02/22-rdf-syntax-ns#>

<rdfs:Class rdf:ID="Property"rdfs:comment="The class of properties"/>

<rdfs:Class rdf:ID="List"><rdfs:comment>The class of RDF Lists </rdfs:comment><rdfs:subClassOf rdf:resource=“&rdfs;Resource"/>

</rdfs:Class>

<rdf:List rdf:ID="nil"><rdfs:comment>The empty list, with no items in it. If the rest of a list is

nil then the list has no more items in it </rdfs:comment>

</rdf:List>

Page 97: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

The Namespace of RDF (2)<rdf:Property rdf:ID="type"> <rdfs:comment> The subject is an instance of a class </rdfs:comment> <rdfs:range rdf:resource=“&rdfs;Class"/> <rdfs:domain rdf:resource="&rdfs;Resource"/></rdf:Property>

<rdf:Property rdf:ID="first"> <rdfs:comment> The first item in the subject RDF list </rdfs:comment> <rdfs:domain rdf:resource="#List"/> <rdfs:range rdf:resource="&rdfs;Resource"/></rdf:Property>

<rdf:Property rdf:ID="rest"> <rdfs:comment> The rest of the subject RDF list after the first item </rdfs:comment> <rdfs:domain rdf:resource="#List"/> <rdfs:range rdf:resource="#List"/></rdf:Property>3-97 A Semantic Web Primer, 2nd EditionChapter 3

Page 98: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-98

The Namespace of RDF Schema<http://www.w3.org/2000/01/rdf-schema#>

<rdfs:Class rdf:ID="Resource"rdfs:comment="The most general class"/>

<rdfs:Class rdf:ID="Class"rdfs:comment="The concept of classes. All classes

are resources"/><rdfs:subClassOf rdf:resource="#Resource"/>

</rdfs:Class>

<rdf:Property rdf:ID="comment"rdfs:comment="Use this for descriptions"/><rdfs:domain rdf:resource="#Resource"/><rdfs:range rdf:resource="#Literal"/>

</rdf:Property>

Page 99: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition3-99

The Namespace of RDF Schema (2) <http://www.w3.org/2000/01/rdf-schema#>

<rdf:Property rdf:ID="subPropertyOf"><rdfs:domain rdf:resource="http://www.w3.org/

1999/02/22-rdf-syntax-ns#Property"/><rdfs:range rdf:resource="http://www.w3.org/

1999/02/22-rdf-syntax-ns#Property"/></rdf:Property>

<rdf:Property rdf:ID="subClassOf"><rdfs:domain rdf:resource="#Class"/><rdfs:range rdf:resource="#Class"/>

</rdf:Property>

Page 100: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-100

Namespace versus Semantics

Consider rdfs:subClassOf – The namespace specifies only that it applies to

classes and has a class as a value– The meaning of being a subclass not expressed

The meaning cannot be expressed in RDF– If it could, RDF Schema would be unnecessary

External definition of semantics required– Respected by RDF/RDFS processing software

Page 101: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-101

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

Page 102: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-102

Semantics based on Inference Rules

The semantics of RDF can be formally described using inference rules of the form:

IF E contains certain triplesTHEN add to E certain additional triples

where E is an arbitrary set of RDF triples– Usually the set of explicit triples of an RDF document

Page 103: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Inference rules (or entailments)

Inference rules add new triples to an existing set of triples so that a query can retrieve the correct set of triples according to RDF/S semantics

Entailments are “materialized” conclusions of inference rules

3-103 A Semantic Web Primer, 2nd EditionChapter 3

Page 104: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Inference / Query Process

3-104 A Semantic Web Primer, 2nd Edition

Original (explicit) set

of triples

RDF document

translationRDF/S

Inference rules

inpu

t

Inferred (implicit) set

of triples

output

Set of all triples

Query

Chapter 3

input

Page 105: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

A simple rule language

The condition of a rule contains patterns of triples that are “searched” (or “matched”) against the current set of triples– Both explicit and implicit

If the condition of the rule is true (i.e. there are triples that match the pattern), then the pattern of triples of the conclusion are added to the current set of triples (or triple DB)

3-105 A Semantic Web Primer, 2nd EditionChapter 3

Page 106: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Constants and Variable

Constants are RDF/S “reserved” names (classes/properties)– They could also be literals or resource names

Variables begin with ?– They denote any value that could match the

pattern in this place– Variables are logical ones: once they match with a

value, they keep it throughout rule evaluation3-106 A Semantic Web Primer, 2nd EditionChapter 3

Page 107: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-107

Examples of Inference Rules (1)

Any resource ?p that is used in the property position of a triple can be inferred to be a member of the class rdf:Property.

IF ?x ?p ?y .THEN ?p rdf:type rdf:Property .Example (explicit triple): uni:CIT1111 uni:courseName "Discrete Maths" .Conclusion (implicit triple): uni:courseName rdf:type rdf:Property .

Page 108: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-108

Examples of Inference Rules (2a)

Definition of the meaning of rdfs:subClassOf IF ?x rdf:type ?u . AND ?u rdfs:subClassOf ?v .THEN ?x rdf:type ?v .Example (explicit triple): uni:CIT1111 rdf:type uni:PostGraduateCourse .uni:PostGraduateCourse rdfs:subClassOf uni:Course .Conclusion (implicit triple): uni:CIT1111 rdf:type uni:Course .

Page 109: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Examples of Inference Rules (2b)

Transitivity of the subclass relation IF ?u rdfs:subClassOf ?v . AND

?v rdfs:subclassOf ?w .THEN ?u rdfs:subClassOf ?w .

Example (explicit triple): uni:Lecturer rdfs:subClassOf uni:Faculty .uni:Faculty rdfs:subClassOf uni:Staff .Conclusion (implicit triple): uni:Lecturer rdfs:subClassOf uni:Staff .3-

109A Semantic Web Primer, 2nd EditionChapter 3

Page 110: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-110

Examples of Inference Rules (3a)

Any resource ?y which appears as the value of a property ?p can be inferred to be a member of the range of ?p– This shows that range definitions in RDF Schema

are not used to restrict the range of a property, but rather to infer the membership of the range

IF ?x ?p ?y. AND ?p rdfs:range ?u .THEN ?y rdf:type ?u .

Page 111: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Examples of Inference Rules (3b)

IF ?x ?p ?y. AND ?p rdfs:range ?u .THEN ?y rdf:type ?u .Example (explicit triple): uni:T949348 uni:teaches uni:CIT1111 .uni:teaches rdfs:range uni:Course .Conclusion (implicit triple): uni:CIT1111 rdf:type uni:Course .3-

111 A Semantic Web Primer, 2nd EditionChapter 3

Page 112: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Other entailment rules (a)

DomainIF ?x ?p ?y . AND ?p rdfs:domain ?u .THEN ?x rdf:type ?u .Example (explicit triple): uni:T949348 uni:teaches uni:CIT1111 .uni:teaches rdfs:domain uni:Faculty .Conclusion (implicit triple): uni:T949348 rdf:type uni:Faculty .3-

112 A Semantic Web Primer, 2nd EditionChapter 3

Page 113: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Other entailment rules (b)

Every node of the semantic net is a ResourceIF ?x ?p ?y .THEN ?x rdf:type rdfs:Resource .IF ?x ?p ?y .THEN ?y rdf:type rdfs:Resource .Example (explicit triple): uni:T949348 uni:teaches uni:CIT1111 .Conclusion (implicit triple): uni:T949348 rdf:type rdfs:Resource .uni:CIT1111 rdf:type rdfs:Resource .3-

113 A Semantic Web Primer, 2nd EditionChapter 3

Page 114: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Sub-property entailment rules (a)

What it means to be a subpropertyIF ?a rdfs:subPropertyOf ?b . AND ?x ?a ?y .THEN ?x ?b ?y.Example (explicit triple): uni:CIT1111 uni:isTaughtBy uni:T949348 .uni:isTaughtBy rdfs:subPropertyOf uni:involves .Conclusion (implicit triple): uni:CIT1111 uni:involves uni:T949348 .3-

114 A Semantic Web Primer, 2nd EditionChapter 3

Page 115: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Sub-property entailment rules (b)

Transitivity of subproperty relationIF ?u rdfs:subPropertyOf ?v . AND

?v rdfs:subPropertyOf ?w .THEN ?u rdfs:subPropertyOf ?w .Example (explicit triple): ex:father rdfs:subPropertyOf ex:parent .ex:parent rdfs:subPropertyOf ex:ancestor .Conclusion (implicit triple): ex:father rdfs:subPropertyOf ex:ancestor .3-

115 A Semantic Web Primer, 2nd EditionChapter 3

Page 116: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Sub-property inheritance of domain/range (a)

IF ?a rdfs:subPropertyOf ?b . AND ?b rdfs:domain ?u .

THEN ?a rdfs:domain ?u .

IF ?a rdfs:subPropertyOf ?b . AND ?b rdfs:range ?u .

THEN ?a rdfs:range ?u .3-116 A Semantic Web Primer, 2nd EditionChapter 3

Page 117: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Sub-property inheritance of domain/range (b)

Example (explicit triple): uni:isTaughtBy rdfs:subPropertyOf uni:involves .uni:involves rdfs:domain uni:Course .uni:involves rdfs:range uni:Staff .Conclusion (implicit triple): uni:isTaughtBy rdfs:domain uni:Course .uni:isTaughtBy rdfs:range uni:Staff .

3-117 A Semantic Web Primer, 2nd EditionChapter 3

Page 118: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

RDF/RDFS inference

uni:Lecturer rdf:type rdfs:Class .uni:Course rdf:type rdfs:Class .uni:teaches rdf:type rdf:Property .uni:teaches rdfs:domain uni:Lecturer .uni:teaches rdfs:range uni:Course .uni:smith rdf:type uni:Lecturer .uni:smith uni:teaches uni:math .Conclusion: uni:math rdf:type uni:Course .

3-118 A Semantic Web Primer, 2nd Edition

IF ?x ?p ?y. and?p rdfs:range ?u.

THEN ?y rdf:type ?u.

Chapter 3

Page 119: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

RDF/RDFS inference (2)

uni:Lecturer rdf:type rdfs:Class .uni:Course rdf:type rdfs:Class .uni:teaches rdf:type rdfs:Property .uni:teaches rdfs:domain uni:Lecturer .uni:teaches rdfs:range uni:Course .uni:smith rdf:type uni:Lecturer .uni:smith uni:teaches uni:jones .Conclusion: uni:jones rdf:type uni:Course . !!

3-119 A Semantic Web Primer, 2nd EditionChapter 3

Page 120: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

RDF/RDFS inference (2’)

uni:Lecturer rdf:type rdfs:Class .uni:Course rdf:type rdfs:Class .uni:teaches rdf:type rdfs:Property .uni:teaches rdfs:domain uni:Lecturer .uni:teaches rdfs:range uni:Course .uni:smith rdf:type uni:Lecturer .uni:jones rdf:type uni:Lecturer .uni:smith uni:teaches uni:jones .Conclusion: uni:jones rdf:type uni:Course . !!!!!!!!!3-

120 A Semantic Web Primer, 2nd EditionChapter 3

Page 121: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-121

RDF/RDFS inference (2’) - explanation

An instance can have multiple types simultaneously!– It can be an instance of multiple classes!– It can belong to different classes, because each

resource can have multiple roles in general!– It belongs to the intersection of the classes.

Big difference with OO programming!

Page 122: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

… BUT (being instance of multiple classes)

When a resource is an instance of two classes

… but the two classes have a hierarchical (subClassOf) relationship

then the most special class is the class of the resource

3-122 A Semantic Web Primer, 2nd EditionChapter 3

Page 123: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Example of being an instance of multiple classes when one is subclass of the other

Example (explicit triple): uni:Faculty rdfs:subClassOf uni:Staff .uni:isTaughtBy rdfs:subPropertyOf uni:involves .uni:isTaughtBy rdfs:domain uni:Course .uni:isTaughtBy rdfs:range uni:Faculty .uni:involves rdfs:domain uni:Course .uni:involves rdfs:range uni:Staff .uni:CIT1111 rdf:type uni:Course .uni:T949348 rdf:type uni:Faculty .uni:CIT1111 uni:isTaughtBy uni:T949348 .Conclusion (implicit triple): uni:CIT1111 uni:involves uni:T949348 .uni:isTaughtBy rdfs:domain uni:Course . We already know that!uni:CIT1111 rdf:type uni:Course . We already know that!uni:isTaughtBy rdfs:range uni:Staff . Faculty Staff Faculty Staff Facultyuni:T949348 rdf:type uni:Staff . We already know that! (from subclass entailment)

Faculty Staff x Faculty x Staff 3-123 A Semantic Web Primer, 2nd Edition

When an inferred triple is already present in the set of triples (either explicit or implicit), it is NOT inserted again!

Chapter 3

Page 124: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-124

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

Page 125: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-125

Why an RDF Query Language?Different XML Representations

XML at a lower level of abstraction than RDF There are various ways of syntactically

representing an RDF statement in XML Thus we would require several XQuery

queries, e.g.– //uni:Lecturer/uni:title if uni:title element– //uni:Lecturer/@uni:title if uni:title attribute– Both XML representations equivalent!

Page 126: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-126

Why an RDF Query Language?Understanding the Semantics

<uni:Lecturer rdf:ID="T949352"><uni:name>Grigoris Antoniou</uni:name>

</uni:Lecturer><uni:Professor rdf:ID="T949318">

<uni:name>David Billington</uni:name></uni:Professor><rdfs:Class rdf:about="#Professor">

<rdfs:subClassOf rdf:resource="#Lecturer"/></rdfs:Class> A query for the names of all lecturers should return both Grigoris

Antoniou and David Billington

Page 127: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

SPARQL Query Language

A W3C Recommendation for querying RDF– Specification 1.0:

http://www.w3.org/TR/rdf-sparql-query/– Specification 1.1:

http://www.w3.org/TR/2013/REC-sparql11-query-20130321/

All major RDF query tools had implemented support for SPARQL

Chapter 3 A Semantic Web Primer, 2nd Edition

3-127

Page 128: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Triple stores

To perform a SPARQL query, one needs software to execute the query.

In memory: Apache Jena (Java library) On disk: Called Triple Store or Graph Store (a

database for RDF) – Sesame (70 million), OpenLink Virtuoso (>15.4 billion),

OWLIM (>12 b), Apache Jena (200 m), AllegroGraph (1 trillion), IBM DB2, Oracle, 4store (15 b), Bigdata (12.7 b), YARS2 (7 b), Mulgara (500 m), …3-

128 A Semantic Web Primer, 2nd EditionChapter 3

Page 129: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Loading triples

Before one can query a triple store, it needs to be populated with RDF.

Most triple stores provide bulk upload options.

SPARQL Update: provides a series of mechanisms for inserting, loading, and deleting RDF into a triple store.

3-129 A Semantic Web Primer, 2nd EditionChapter 3

Page 130: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

SPARQL protocol

A triple store can be queried by sending SPARQL queries using the SPARQL protocol.

Each triple store provides an endpoint, where SPARQL queries can be submitted.

Clients can send queries to an endpoint using the HTTP protocol. – You can issue a SPARQL query to an endpoint by

entering it into the browser’s URL bar – It’s preferable to have a client designed specifically

for SPARQL.3-130 A Semantic Web Primer, 2nd EditionChapter 3

Page 131: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Dbpedia SPARQL endpointhttp://dbpedia.org/sparql

3-131 A Semantic Web Primer, 2nd Edition

More endpoints can be found at:http://ckan.org/

Chapter 3

Page 132: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Basic Idea

SPARQL is based on matching graph patterns Simplest graph pattern = triple pattern

– like an RDF triple – a variable can be in the position of the subject,

predicate, or object Combining triple patterns gives a basic graph

pattern– An exact match to a graph is needed

Chapter 3 A Semantic Web Primer, 2nd Edition

3-132

Page 133: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Basic Query Example

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

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

SELECT ?c

WHERE

{

?c rdf:type rdfs:Class .

}

Chapter 3 A Semantic Web Primer, 2nd Edition

3-133

Page 134: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Query Explanation

Retrieve all triple patterns – where the property is rdf:type, and – the object is rdfs:Class– i.e. Retrieve all classes

SPARQL allows to define prefixes for namespaces – Use prefixes in the query pattern, to make queries

shorter and easier to read

Chapter 3 A Semantic Web Primer, 2nd Edition

3-134

Page 135: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Get all instances of a class

PREFIX uni: <http://www.mydomain.org/uni-ns#>SELECT ?iWHERE{?i rdf:type uni:Course .

}

Chapter 3 A Semantic Web Primer, 2nd Edition

3-135

Page 136: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

SPARQL and RDF Semantics

SPARQL makes no explicit commitment to support RDFS semantics.

The result depends on whether the system answering the query supports RDFS semantics. – If yes, then result will include all instances of the

subclasses of Course. – If not, it will only retrieve those instances that are

explicitly of type Course.

Chapter 3 A Semantic Web Primer, 2nd Edition

3-136

Page 137: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

rdf:type

This property is used very often SPARQL provides a shorthand notation: the

keyword ’a’

SELECT ?cWHERE { ?c a rdfs:Class . }

3-137 Chapter 3 A Semantic Web Primer, 2nd Edition

Page 138: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Using select-from-where

SELECT specifies the projection:– the number and order of retrieved data

FROM specifies the source being queried – Optional– When not specified, assume querying the knowledge

base of a particular system. WHERE imposes constraints on solutions

– Graph pattern templates and boolean constraints

Chapter 3 A Semantic Web Primer, 2nd Edition

3-138

Page 139: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

ExampleRetrieve all phone numbers of staff members

SELECT ?x ?yWHERE{?x uni:phone ?y .

} ?x, ?y

– variables ?x uni:phone ?y

– A resource-property-value triple patternChapter 3 A Semantic Web Primer, 2nd Edition

3-139

Page 140: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Implicit Join

Retrieve all lecturers and their phone numbersSELECT ?x ?yWHERE{?x rdf:type uni:Lecturer ; uni:phone ?y .

}

Chapter 3 A Semantic Web Primer, 2nd Edition

3-140

Collects all instances of class Lecturer and binds result to variable ?x

Syntax shortcut: a semicolon ; indicates that the following triple pattern shares its subject with the previous one.

• Collects all triples with predicate phone• Implicit join: restrict the 2nd pattern only

to those triples whose subject is ?x

Page 141: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Equivalent Query

SELECT ?x ?yWHERE{?x rdf:type uni:Lecturer .?x uni:phone ?y .

}

Chapter 3 A Semantic Web Primer, 2nd Edition

3-141

Page 142: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Retrieve all information about (1)

SELECT ?x ?p ?oWHERE{?x rdf:type uni:Lecturer ;

?p ?o .}

3-142 A Semantic Web Primer, 2nd EditionChapter 3

Page 143: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Retrieve all information about (2)

SELECT ?p ?oWHERE {uni:T949352 rdf:type uni:Lecturer ;

?p ?o . }OrSELECT ?p ?oWHERE { uni:T949352 ?p ?o . }

3-143 A Semantic Web Primer, 2nd EditionChapter 3

Page 144: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Limiting results

On large data sets we may write queries that can return millions of triples.– E.g. ?i rdf:type dbo:Place

It is good practice to limit the number of answers a query returns – Public endpoints (e.g. DBPedia)

3-144 A Semantic Web Primer, 2nd EditionChapter 3

Page 145: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

LIMIT

PREFIX dbo: <http://dbpedia.org/ontology/> .SELECT ?iWHERE{?i rdf:type dbo:Place .

} LIMIT 100

3-145 A Semantic Web Primer, 2nd EditionChapter 3

Page 146: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

FILTER construct

SELECT ?x ?yWHERE{?x rdf:type uni:Lecturer ; uni:age ?y .FILTER (?y > 30)

}3-146

• FILTER condition: a Boolean constraint / expression that filters / restricts the results

A Semantic Web Primer, 2nd EditionChapter 3

Page 147: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

SPARQL built-in filter functions

Logical: !, &&, || Math: +, -, *, / Comparison: =, !=, >, <, ... SPARQL tests: isURI, isBlank, isLiteral, bound SPARQL accessors: str, lang, datatype Strings (SPARQL 1.1): STRLEN, SUBSTR, UCASE, LCASE,

STRSTARTS, STRENDS, CONTAINS, CONCAT, … More math (SPARQL 1.1): abs, round, ceil, floor, RAND Date/time (SPARQL 1.1): now, year, month, day, hours, minutes,

seconds, timezoneChapter 3 A Semantic Web Primer, 2nd Edition

3-147

Page 148: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Optional Patterns

The graph patterns so far are mandatory– Either the knowledge base matches the complete

pattern, in which case an answer is returned, or– it doesn’t, in which case the query does not

produce a result. However, in many cases we may wish to be

more flexible.

Chapter 3 A Semantic Web Primer, 2nd Edition

3-148

Page 149: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

ExampleRDF fragment

<uni:Lecturer rdf:about="#T949352"><uni:name>Grigoris Antoniou</uni:name>

</uni:Lecturer><uni:Professor rdf:about="#T949318"><uni:name>David Billington</uni:name><uni:email>[email protected]</uni:email>

</uni:Professor>

Chapter 3 A Semantic Web Primer, 2nd Edition

3-149

Page 150: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Optional patterns - Example

This fragment contains information on two lecturers. – For one lecturer it only lists the name– For the other it also lists the e-mail address.

We want to query for all lecturers and their e-mail addresses

Chapter 3 A Semantic Web Primer, 2nd Edition

3-150

Page 151: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Querying with mandatory patterns

SELECT ?name ?emailWHERE{ ?x rdf:type uni:Lecturer ; uni:name ?name ; uni:email ?email .

}

Chapter 3 A Semantic Web Primer, 2nd Edition

3-151

Page 152: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Querying with mandatory patternsResult

?name ?emailDavid Billington [email protected]

Chapter 3 A Semantic Web Primer, 2nd Edition

3-152

• Despite the fact that Grigoris Antoniou is listed as a lecturer, the query does not return his name.

• The query pattern does not match because he has no e-mail address.

Page 153: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Querying with optional patterns

SELECT ?name ?emailWHERE{ ?x rdf:type uni:Lecturer ;uni:name ?name .OPTIONAL { ?x uni:email ?email }

}

Chapter 3 A Semantic Web Primer, 2nd Edition

3-153

Meaning: "give all the names of lecturers, and if known also their e-mail addresses"

Page 154: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Querying with optional patternsResult

Chapter 3 A Semantic Web Primer, 2nd Edition

3-154

?name ?emailGrigoris AntoniouDavid Billington [email protected]

Page 155: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Querying alternatives We want a contact detail for all lecturers

– This can be either a phone or an e-mailSELECT ?name ?contactWHERE{ ?x rdf:type uni:Lecturer ;

uni:name ?name.{?x uni:phone ?contact.}UNION{?x uni:email ?contact.}

}Chapter 3 A Semantic Web Primer, 2nd Edition

3-155

Page 156: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results of UNION

?name ?contactJohnSmith [email protected]

Harald 9922

nbassili 97913

nbassili [email protected]

Chapter 3 A Semantic Web Primer, 2nd Edition

3-156

People with both contact details will be included twice in the result

Page 157: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Querying alternatives If we don’t want the same person twice we must choose the most

preferred contact detail (e.g. phone) and write a different query

SELECT ?x ?contactWHERE{ ?x rdf:type :Faculty . {?x :phone ?contact.} UNION {?x :email ?contact. OPTIONAL { ?x :phone ?p. } FILTER(!bound(?p)) }} Chapter 3 A Semantic Web Primer, 2nd Edition

3-157

In case the lecturer has also a phone, filter him out!

(Variable ?p should not be bound)

Only one of these 2 can be true!

Page 158: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Explanation - 1

Someone has ONLY phoneSELECT ?x ?contactWHERE{ ?x rdf:type :Faculty . {?x :phone ?contact.} UNION {?x :email ?contact. OPTIONAL { ?x :phone ?p. } FILTER(!bound(?p)) }}

Chapter 3 A Semantic Web Primer, 2nd Edition

3-158

TRUE

FALSE

Page 159: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Explanation - 2

Someone has ONLY emailSELECT ?x ?contactWHERE{ ?x rdf:type :Faculty . {?x :phone ?contact.} UNION {?x :email ?contact. OPTIONAL { ?x :phone ?p. } FILTER(!bound(?p)) }}

3-159

TRUE

FALSE

FALSE (but optional)

?p does not have a valuebound(?p) FALSE!bound(?p) TRUE

TRUE

Page 160: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Explanation - 3

Someone has BOTH phone AND emailSELECT ?x ?contactWHERE{ ?x rdf:type :Faculty . {?x :phone ?contact.} UNION {?x :email ?contact. OPTIONAL { ?x :phone ?p. } FILTER(!bound(?p)) }}

3-160

TRUE

TRUE

TRUE

?p has a valuebound(?p) TRUE!bound(?p) FALSE

FALSE

Page 161: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results of UNION + OPTIONAL + FILTER

?name ?contactJohnSmith [email protected]

Harald 9922

nbassili 97913

Chapter 3 A Semantic Web Primer, 2nd Edition

3-161

Page 162: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

SPARQL 1.1 Property Paths

A property path is a possible route through a graph between two graph nodes. – Trivial property path of length 1 = a triple pattern

The ends of the path may be RDF terms or variables– Variables can only be used at the ends of the path

Property paths allow for more concise expressions for some SPARQL basic graph patterns – Ability to match connectivity of two resources by an

arbitrary length path

Chapter 3 A Semantic Web Primer, 2nd Edition

3-162

Page 163: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Simple Paths: Sequence

Find the name of any people that Alice knows.

{ ?x foaf:mbox <mailto:alice@example> . ?x foaf:knows/foaf:name ?name . }

This is equivalent to:

{ ?x foaf:mbox <mailto:alice@example> . ?x foaf:knows ?y. ?y foaf:name ?name . }

Chapter 3 A Semantic Web Primer, 2nd Edition

3-163

Page 164: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Complex Paths

Find the names of all the people that can be reached from Alice by foaf:knows

{ ?x foaf:mbox <mailto:alice@example> . ?x foaf:knows+/foaf:name ?name . }

Chapter 3 A Semantic Web Primer, 2nd Edition

3-164

1 or more

Page 165: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Limited Inference Capabilities

All classes and super-classes ?c of a resource:

{ uni:nick rdf:type/rdfs:subClassOf* ?c }

All direct and indirect instances ?x of a class:

{ ?x rdf:type/rdfs:subClassOf* uni:Person }

Chapter 3 A Semantic Web Primer, 2nd Edition

3-165

0 or more

Page 166: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Limited Inference Capabilities (2)

?x rdf:type/rdfs:subClassOf* ?yIs equivalent to

?x rdf:type ?y .OR (UNION)

?x rdf:type ?x1 . ?x1 rdfs:subClassOf ?y .OR (UNION)

?x rdf:type ?x1 . ?x1 rdfs:subClassOf ?x2 . ?x2 rdfs:subClassOf ?y .

OR (UNION)?x rdf:type ?x1 . ?x1 rdfs:subClassOf ?x2 . ?x2 rdfs:subClassOf ?x3 . ?x3 rdfs:subClassOf ?y .

OR (UNION)

…3-166 Chapter 3 A Semantic Web Primer, 2nd Edition

Page 167: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

DISTINCT - rationale

Find all Greek cities with a University

select ?c where { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . }

3-167 A Semantic Web Primer, 2nd EditionChapter 3

Page 168: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Result

3-168 A Semantic Web Primer, 2nd Edition

chttp://dbpedia.org/resource/Corfuhttp://dbpedia.org/resource/Ioanninahttp://dbpedia.org/resource/Patrashttp://dbpedia.org/resource/Piraeushttp://dbpedia.org/resource/Karditsahttp://dbpedia.org/resource/Larissahttp://dbpedia.org/resource/Trikalahttp://dbpedia.org/resource/Voloshttp://dbpedia.org/resource/Athenshttp://dbpedia.org/resource/Athenshttp://dbpedia.org/resource/Sparta...

duplicates

Chapter 3

Page 169: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

DISTINCT

Find all Greek cities with a University

select DISTINCT ?c where { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . }

3-169 A Semantic Web Primer, 2nd EditionChapter 3

Page 170: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results

3-170 A Semantic Web Primer, 2nd Edition

chttp://dbpedia.org/resource/Corfuhttp://dbpedia.org/resource/Ioanninahttp://dbpedia.org/resource/Patrashttp://dbpedia.org/resource/Piraeushttp://dbpedia.org/resource/Karditsahttp://dbpedia.org/resource/Larissahttp://dbpedia.org/resource/Trikalahttp://dbpedia.org/resource/Voloshttp://dbpedia.org/resource/Athenshttp://dbpedia.org/resource/Thessaloniki…

No duplicates

unordered

Chapter 3

Page 171: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

ORDER BY

Find all Greek cities with a University

select DISTINCT ?c where { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . } ORDER BY ?c

3-171 A Semantic Web Primer, 2nd EditionChapter 3

Page 172: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results

3-172 A Semantic Web Primer, 2nd Edition

No duplicates

Ordered

chttp://dbpedia.org/resource/Agriniohttp://dbpedia.org/resource/Alexandroupolihttp://dbpedia.org/resource/Argostolihttp://dbpedia.org/resource/Athenshttp://dbpedia.org/resource/Atticahttp://dbpedia.org/resource/Chaniahttp://dbpedia.org/resource/Corfuhttp://dbpedia.org/resource/Corinthhttp://dbpedia.org/resource/Cretehttp://dbpedia.org/resource/Didymoteichohttp://dbpedia.org/resource/Drama,_Greece…

How many?

Chapter 3

Page 173: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

COUNT

Find how many Greek cities have a University

select count(?c) as ?TotalCities where { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . }

3-173 A Semantic Web Primer, 2nd Edition

TotalCities68

Result

Can’t be!!!

Chapter 3

Page 174: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

COUNT DISTINCT

Find how many Greek cities have a University

select count(DISTINCT ?c) as ?TotalCities where { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . }

3-174 A Semantic Web Primer, 2nd Edition

TotalCities38

Result

Chapter 3

Page 175: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

NOT EXISTS

Find cities with no Universitiesselect ?c where { ?c rdf:type dbo:City . ?c dbo:country dbr:Greece . FILTER NOT EXISTS {

?u rdf:type dbo:University . ?u dbo:city ?c .

}}3-

175

Page 176: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results

You don’t want to know!!

Why?– Because most Greek cities are not instances of dbo:City !

– Because many Greek cities do not have the dbo:country property!3-

176

chttp://dbpedia.org/resource/North_College_Thessaloniki__Thessaloniki__1

Page 177: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

DBPedia: the Truth!

DBPedia has a lot of wrong information and a lot of information is missing

Not all Wikipedia properties have been correctly mapped to the corresponding DBpedia ontology property

Thus, in order to retrieve the correct information sometimes you have to become a detective!

Chapter 3 A Semantic Web Primer, 2nd Edition

3-177

Page 178: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Query that returns more results

select DISTINCT ?c where { ?u rdf:type dbo:EducationalInstitution . ?u (dbo:city | dbp:city) ?c . { ?u (dbo:country | dbp:country) dbr:Greece . } UNION { ?c (dbo:country | dbp:country) dbr:Greece . }} order by ?c

Chapter 3 A Semantic Web Primer, 2nd Edition

3-178

Page 179: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results

3-179

Page 180: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

ASK construct

Are there Greek cities with Universities? – I just want to know (true/false) – not how many /

which!ASK where { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . }

3-180

trueResult

Page 181: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

DESCRIBE construct

Give me information about Greek cities with Universities.– I want to know everything about these cities!

DESCRIBE ?c where { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . }3-

181

Page 182: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results

A huge number of triples for all instances of ?c

All triples that have ?c as a subject or as an object!

Actually a file is returned.

3-182

Page 183: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

CONSTRUCT

Creates RDF graphs (set of triples) using data resulting from a query– E.g. link each Greek city to its Universities

CONSTRUCT { ?c dbo:has-University ?u . }WHERE { ?u rdf:type dbo:University . ?u dbo:country dbr:Greece . ?u dbo:city ?c . }

3-183

Page 184: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Results

A number of triples that link each Greek city to each of its Universities.

Actually a file is returned.

3-184

Page 185: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Lecture Outline

1. Basic Ideas of RDF 2. XML-based Syntax of RDF3. Basic Concepts of RDF Schema4. Τhe Language of RDF Schema5. The Namespaces of RDF and RDF Schema6. Direct Semantics based on Inference Rules7. Querying of RDF/RDFS Documents using SPARQL8. Linked Open Data

3-185 A Semantic Web Primer, 2nd EditionChapter 3

Page 186: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Linked Open Data

Linked Data is about using the Web to – connect related data that wasn't previously linked, or – lower the barriers to linking data currently linked

using other methods Wikipedia definition

– A recommended best practice for exposing, sharing, and connecting pieces of data, information, and knowledge on the Semantic Web using URIs and RDF

Chapter 3 A Semantic Web Primer, 2nd Edition

3-186

Page 187: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Linked Data – Tim Berners Lee’s thoughts (http://www.w3.org/DesignIssues/LinkedData.html)

Semantic Web isn't just about putting data on the web It is about making links, so that a person or machine can

explore the web of data. – With linked data, when you have some of it, you can find other,

related, data. In the web of hypertext (or web of documents), links are

relationships between documents written in HTML In the web of data, links are relationships between

arbitrary things described by RDF.– The URIs identify any kind of object or concept.

Chapter 3 A Semantic Web Primer, 2nd Edition

3-187

Page 188: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Linked Data Principles

Use URIs as names for things– Real inanimate or animate things, abstract concepts, …

Use HTTP URIs so that names can be looked up– E.g. using a browser

When someone looks up a URI, provide useful information, using the standards (RDF, SPARQL)

Include links to other URIs so that more things can be discovered– Links are actually RDF properties interpreted as

hyperlinksChapter 3 A Semantic Web Primer, 2nd Edition

3-188

Don't just link the documents, link the things

Page 189: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Advantages of LOD

Linked Data is a way of publishing data on the Web that:– encourages reuse– reduces redundancy– maximises its (real and potential) inter-

connectedness– enables network effects to add value to data

Chapter 3 A Semantic Web Primer, 2nd Edition

3-189

Page 190: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Linked Data Technology Stack

URIs – as a mechanism to identify things (IDs) HTTP – as a mechanism to access things RDF – as a mechanism to describe things and

their relationships RDFS/OWL – as a mechanism to describe

vocabularies of properties and relationships of things

Chapter 3 A Semantic Web Primer, 2nd Edition

3-190

Page 191: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Linked Data Example

Chapter 3 A Semantic Web Primer, 2nd Edition

3-191

Prefixesrc: <http://richard.cyganiak.de/foaf.rdf#>rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>foaf: <http://xmlns.com/foaf/0.1/>dbpedia: <http://dbpedia.org/resource/>dp: <http://dbpedia.org/property/>skos: <http://www.w3.org/2004/02/skos/core#>

Data Merging with RDF• Mix schemas/vocabularies

within one document• Less painful data merging

Actual namespaces may vary!

Page 192: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Dbr:Berlin

select ?p ?o where {dbr:Berlin ?p ?o .

}

3-192 A Semantic Web Primer, 2nd Edition

See attached file

Chapter 3

Page 193: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Dbr:Berlin

dbr:Berlin expands to full URI:http://dbpedia.org/resource/Berlin – Unique ID that represents the resource in the Web

of Data However, if you type the above URI at a

browser, you will be re-directed at:http://dbpedia.org/page/Berlin – Manifestation (or visualization) of the resource in

the Web of Documents3-193 A Semantic Web Primer, 2nd EditionChapter 3

Page 194: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Dbr:Berlin

3-194 A Semantic Web Primer, 2nd EditionChapter 3

Page 195: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Dbpedia:Berlin

If you type at the browser:http://dbpedia.org/data/Berlin

The browser will retrieve an RDF/XML file that contains all information for Berlin– All triples with http://dbpedia.org/resource/Berlin

as a subject

3-195 A Semantic Web Primer, 2nd EditionChapter 3

Page 196: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Why Publish Linked Data?

Ease of discovery Ease of consumption

– standards-based data sharing Reduced redundancy Added value

– build ecosystems around your data/content

Chapter 3 A Semantic Web Primer, 2nd Edition

3-196

Page 197: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

The Linking Open Data cloud diagramNow

3-197

Page 198: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

The Linking Open Data cloud diagramMay 2007

Chapter 3 A Semantic Web Primer, 2nd Edition

3-198

Page 199: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

DBpedia (http://dbpedia.org)

A project aiming to extract structured content from the information created as part of the Wikipedia. – This structured information is then made available on

the Web DBpedia allows users to query relationships and

properties associated with Wikipedia resources, including links to other related datasets.

One of the more famous parts of the Linked Data project, according to TBL

Chapter 3 A Semantic Web Primer, 2nd Edition

3-199

Page 200: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

DBpedia dataset

Wikipedia articles include structured information embedded in the articles (mostly free text)– E.g. "infobox" tables, categorisation information, images, geo-

coordinates and links to external pages. – This structured information is extracted and put in a uniform dataset

which can be queried. The DBpedia project uses RDF to represent the extracted

information. – 3 billion RDF triples

580 million from the English edition 2.46 billion from other language editions (125) 50 million data links to external RDF data sets

Chapter 3 A Semantic Web Primer, 2nd Edition

3-200

Page 201: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

DBpedia challenges The same concepts can be expressed using different

properties in templates– E.g. birthplace and placeofbirth– Queries about where people were born must search for both

properties to get complete results. The DBpedia Mapping Language helps mapping

properties to an ontology– Reduces the number of synonyms

The development of the ontology and the mappings are open to public– Due to large diversity of infoboxes and properties

Chapter 3 A Semantic Web Primer, 2nd Edition

3-201

Page 202: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

GeoNames

GeoNames is a geographical database available and accessible through various Web services

Contains over 10 million geographical names corresponding to over 8 million unique features.– E.g. names of places, latitude, longitude, elevation,

population, administrative subdivision, postal codes, … Web services:

– Direct and reverse geocoding, finding places through postal codes, finding places next to a given place, and finding Wikipedia articles about neighbouring places.

Chapter 3 A Semantic Web Primer, 2nd Edition

3-202

Page 203: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

GeoNames and LOD

Each GeoNames feature is represented as a Web resource identified by a stable URI. – Provides access to the HTML wiki page or to RDF description,

using GeoNames ontology GeoNames ontology describes the GeoNames features

properties using the OWL– The classes and codes are described in SKOS (RDFS).

GeoNames data are linked to DBpedia data and other RDF Linked Data.– Through Wikipedia articles URL linked in the RDF descriptions

Chapter 3 A Semantic Web Primer, 2nd Edition

3-203

Page 204: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Geonames – Example page

Chapter 3 A Semantic Web Primer, 2nd Edition

3-204

Page 205: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-205

Summary

RDF provides a foundation for representing and processing metadata

RDF has a graph-based data model RDF has an XML-based syntax to support syntactic

interoperability. – XML and RDF complement each other because RDF

supports semantic interoperability RDF has a decentralized philosophy and allows

incremental building of knowledge, and its sharing and reuse

Page 206: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-206

Summary (2)

RDF is domain-independent RDF Schema provides a mechanism for describing

specific domains RDF Schema is a primitive ontology language

– It offers certain modelling primitives with fixed meaning Key concepts of RDF Schema are class, subclass

relations, property, subproperty relations, and domain and range restrictions

There exist query languages (SPARQL) for RDF/RDFS

Page 207: Διδάσκων:  Ν. Βασιλειάδης Αναπλ. Καθ. Τμ. Πληροφορικής ΑΠΘ

Chapter 3 A Semantic Web Primer, 2nd Edition

3-207

Points for Discussion in Subsequent Chapters

RDF Schema is quite primitive as a modelling language for the Web

Many desirable modelling primitives are missing

Therefore we need an ontology layer on top of RDF and RDF Schema