![Page 1: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/1.jpg)
1
ARIN – KR Practical 1, Part 2
RDF
Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and errors are mine.
Suresh Manandhar, Dimitar Kazakov
![Page 2: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/2.jpg)
2
Lecture Overview
Overview RDF
RDF examples
RDF tools
![Page 3: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/3.jpg)
3
Need a language to describe graphs
Besse, Christianne
Le palais des miroirsf:original
f:nom
f:traducteur
f:auteur
f:titre
http://…isbn/2020386682
f:nom
Ghosh, Amitav http://www.amitavghosh.com
The Glass Palace
2000
London
Harper Collins
a:title
a:year
a:city
a:p_name
a:namea:homepage
a:author
a:publisher
http://…isbn/000651409X
http://…foaf/Personr:type
r:type
http://dbpedia.org/../Amitav_Ghosh
http://dbpedia.org/../The_Hungry_Tide
http://dbpedia.org/../The_Calcutta_Chromosome
http://dbpedia.org/../Kolkata
http://dbpedia.org/../The_Glass_Palace
r:type
foaf:name w:reference
w:author_of
w:author_of
w:author_of
w:born_in
w:isbn
w:long w:lat
![Page 4: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/4.jpg)
4
RDF stands for Resource Description
Framework
RDF is a language for describing labelled
graphsnodes are URIs (all web applications understand these)
edges can have labels which are also URIs
allows namespaces
+ additional datatypes:Containers
Strings, Decimals, Floats etc from XML Schema
RDF provides this
![Page 5: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/5.jpg)
5
RDF triples
An RDF Triple (subject,predicate,object) is such that: “s”, “p” are URI-s, ie, resources on the Web; “o” is a URI or a
literal“s”, “p”, and “o” stand for “subject”, “property” or “predicate”, and
“object” here is the complete triple:
RDF is a general model for such triples (with machine
readable formats like RDF/XML, Turtle, N3, RDFa,
Json, …)
(<http://…isbn…6682>, <http://…/original>, <http://…isbn…409X>)
![Page 6: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/6.jpg)
6
Resources can use any URIhttp://www.mysite.com
http://www.example.org/file.html#home
http://www.example.org/form?a=b&c=d
RDF triples form a directed, labelled graph
(the best way to think about them!)
RDF triples (cont.)
![Page 7: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/7.jpg)
7
A simple RDF example (in Turtle)
@prefix my: <http://mysite.com/>@prefix dc: <http://dublincore.org/documents/dces/> .
<http://…/isbn/2020386682> dc:title "Le palais des mirroirs"@fr ; my:original <http://…/isbn/000651409X> .
my:originaldc:titl
e
http://…isbn/2020386682
Le palais des miroirs http://…isbn/000651409X
![Page 8: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/8.jpg)
8
Note: Turtle
@prefix my: <http://mysite.com/>@prefix dc: <http://dublincore.org/documents/dces/> .
<http://…/isbn/2020386682> dc:title "Le palais des mirroirs"@fr ; my:original <http://…/isbn/000651409X> .
is expanded as:
<rdf:Description rdf:about="http://…/isbn/2020386682"> <dc:title xml:lang="fr">Le palais des mirroirs</dc:title> <my:original rdf:resource="http://…/isbn/000651409X"/></rdf:Description>
![Page 9: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/9.jpg)
9
= Same RDF example (in RDF/XML)
<rdf:Description rdf:about="http://…/isbn/2020386682"> <dc:title xml:lang="fr">Le palais des mirroirs</dc:title> <my:original rdf:resource="http://…/isbn/000651409X"/></rdf:Description>
my:originaldc:titl
e
http://…isbn/2020386682
Le palais des miroirs http://…isbn/000651409X
![Page 10: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/10.jpg)
10
= Same RDF example (in RDFa)
<p about="http://…/isbn/2020386682">The book entitled“<span property=“dc:title" lang="fr">Le palais des mirroirs</span>” is the French translation of the “<span rel=“my:original" resource="http://…/isbn/000651409X">GlassPalace</span>”</p> .
my:originaldc:titl
e
http://…isbn/2020386682
Le palais des miroirs http://…isbn/000651409X
RDFa is a mechanism to allow embedding RDF meta-data within a HTML page
![Page 11: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/11.jpg)
11
URIs made the merge possible
URIs ground RDF semanticsinformation can be retrieved using existing tools
this makes the “Semantic Web”, well… “Semantic Web”
URIs play a fundamental role
![Page 12: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/12.jpg)
12
RDF principles
Every node is a URI or a literal
Every edge is a URI
i.e. ground all data without exception
![Page 13: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/13.jpg)
13
Namespaces
Namespaces are URIs that publish a
vocabulary of terms
For example, the Dublin Core is a well
known namespace for common meta-data
items such as author, title etc.
![Page 14: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/14.jpg)
14
Some common namespaces
foaf: http://xmlns.com/foaf/spec/
dc: http://dublincore.org/documents/dces/
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs: http://www.w3.org/2000/01/rdf-schema#
owl: http://www.w3.org/2002/07/owl#
geonames: http://www.geonames.org/ontology#
dbpedia: http://dbpedia.org/resource/
(http://mappings.dbpedia.org/server/ontology/classes/
http://dbpedia.org/Datasets/Properties/)
![Page 15: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/15.jpg)
15
Dublin Core Elements
Title
Author/creator
Subject/keywords
Description
Publisher
Other Contributor
Date
Resource type
Format
Resource Identifier
Source
Language
Relation
Coverage
Rights management
http://dublincore.org/documents/dces/
![Page 16: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/16.jpg)
16
RDF Elements
Syntax names
rdf:RDF, rdf:Description,
rdf:ID, rdf:about,
rdf:parseType,
rdf:resource, rdf:li,
rdf:nodeID, rdf:datatype
Class names
rdf:Seq, rdf:Bag, rdf:Alt,
rdf:Statement, rdf:Property,
rdf:XMLLiteral, rdf:List
Property names
rdf:subject, rdf:predicate,
rdf:object, rdf:type,
rdf:value,
rdf:first, rdf:rest_n
http://www.w3.org/1999/02/22-rdf-syntax-ns#
![Page 17: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/17.jpg)
17
For new concepts
Create your own namespace
![Page 18: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/18.jpg)
18
Consider the following statement:“the publisher is a «thing» that has a name and an address”
Until now, nodes were identified with a URI.
But…
…what is the URI of «thing»?
“Internal” nodes
London
Harper Collins
a:city
a:p_name
a:publisherhttp://…isbn/000651409X
![Page 19: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/19.jpg)
19
One solution: create an extra URI
<rdf:Description rdf:about="http://…/isbn/000651409X"> <a:publisher rdf:resource="urn:uuid:f60ffb40-307d-…"/></rdf:Description><rdf:Description rdf:about="urn:uuid:f60ffb40-307d-…"> <a:p_name>HarpersCollins</a:p_name> <a:city>HarpersCollins</a:city></rdf:Description>
The resource will be “visible” on the Web care should be taken to define unique URI-s
![Page 20: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/20.jpg)
20
Or Internal identifier (“blank nodes”)<rdf:Description rdf:about="http://…/isbn/000651409X"> <a:publisher rdf:nodeID="A234"/></rdf:Description><rdf:Description rdf:nodeID="A234"> <a:p_name>HarpersCollins</a:p_name> <a:city>HarpersCollins</a:city></rdf:Description>
Internal = these resources are not visible outside
<http://…/isbn/2020386682> a:publisher _:A234._:A234 a:p_name "HarpersCollins".
London
Harper Collins
a:city
a:p_name
a:publisherhttp://…isbn/000651409X
![Page 21: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/21.jpg)
21
Blank nodes require attention when mergingblanks nodes with identical nodeID-s in different graphs are different
implementations must be careful…
Many applications prefer not to use blank
nodes and define new URI-s “on-the-fly”
From a logic point of view, blank nodes
represent an “existential” statement “there is a resource such that…”
More on blank nodes
![Page 22: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/22.jpg)
22
Closer look – An exampleTask – to build a knowledge base for an online
camera shop using RDF
![Page 23: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/23.jpg)
23
Closer look – An example
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-
ns#> .
@prefix : <http://www.shop.com/camera#> .
@prefix dbpedia: <http://www.dbpedia.org/resource/> .
:Nikon_D300 rdf:type :DSLR.
:Nikon_D300 :manufactured_by dbpedia:Nikon.
:Nikon_D300 :model "D300".
:Nikon_D300 :weight "0.6_kg".
Task – to build a knowledge base for an online camera
shop using RDF
![Page 24: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/24.jpg)
24
Closer look – An example
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
.
@prefix : <http://www.shop.com/camera#> .
@prefix dbpedia: <http://www.dbpedia.org/resource/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
:Nikon_D300 rdf:type :DSLR.
:Nikon_D300 :manufactured_by dbpedia:Nikon.
:Nikon_D300 :model "D300".
:Nikon_D300 :weight "0.6_kg".
:Nikon_D300 :reviewed_by _:x1.
_:x1 foaf:givenname "John".
_:x1 foaf:family_name "Smith”.
Blank node – to add reviewer “John Smith”
![Page 25: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/25.jpg)
25
Closer look – An example
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://www.shop.com/camera#> .
@prefix dbpedia: <http://www.dbpedia.org/resource/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
:Nikon_D300 rdf:type :DSLR.
:Nikon_D300 :manufactured_by dbpedia:Nikon.
:Nikon_D300 :model "D300".
:Nikon_D300 :weight "0.6_kg".
:Nikon_D300 :reviewed_by _:x1.
_:x1 foaf:givenname "John".
_:x1 foaf:family_name "Smith".
:Nikon_D300 :bought_by _:x1.
Co-reference – Buyer and reviewer are the same
![Page 26: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/26.jpg)
26
Closer look – An example
![Page 27: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/27.jpg)
27
Closer look – An example
### This info can visible to all customers
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://www.shop.com/camera#> .
@prefix dbpedia: <http://www.dbpedia.org/resource/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
:Nikon_D300 rdf:type :DSLR.
:Nikon_D300 :manufactured_by dbpedia:Nikon.
:Nikon_D300 :model "D300".
:Nikon_D300 :weight "0.6_kg".
:Nikon_D300 :reviewed_by :Reviewer_1.
:Reviewer_1 foaf:givenname "John".
:Reviewer_1 foaf:family_name "Smith”.
Use separate ids – for buyer and reviewer
Public info vs Private info
![Page 28: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/28.jpg)
28
Closer look – An example
### This info is stored in private internal db
:Nikon_D300 :bought_by :Cust_5636.
:Cust_5636 foaf:givenname ”Sally".
:Cust_5636 foaf:family_name ”Douglas”.
:Cust_5636 :address_line1 ”Heslington Lane”.
![Page 29: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/29.jpg)
29
Converting Turtle to RDF/XML
cwm --n3 camera.rdf.turtle --rdf > camera.rdf.rdf
Use Python script cwm (available on your machine, and also
from:
http://www.w3.org/2000/10/swap/doc/cwm.html)
Use Notation3 (N3) to rdf conversion
Notation3 is very similar to Turtle format though not identical
Use http://www-module.cs.york.ac.uk/arin/camera.rdf.turtle - right
click on the link, then select Save linked file as
![Page 30: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/30.jpg)
30
![Page 31: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/31.jpg)
31
Using RDF/XML validator
![Page 32: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/32.jpg)
32
Using RDF/XML validator
![Page 33: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/33.jpg)
33
Visualising RDF graph
rdfdot -ttl camera.rdf.turtle > camera.rdf.dot
Use RDF to dot converter from CPAN (Perl Repository):
RDF-Trine-Exporter-GraphViz
Comes with command-line tool: rdfdot (you’ve got it)
Use Graphviz visualiser to view the graph
![Page 34: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/34.jpg)
34
Visualising RDF graph
Use Graphviz visualiser to view the graph
![Page 35: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/35.jpg)
35
Turtle shortcuts
:Nikon_D300 rdf:type :DSLR.
:Nikon_D300 :manufactured_by dbpedia:Nikon.
:Nikon_D300 :model "D300".
:Nikon_D300 :weight "0.6_kg".
:Nikon_D300 :reviewed_by :Reviewer_1.
Use of semicolon;
The following two are equivalent:
:Nikon_D300 rdf:type :DSLR;
:manufactured_by dbpedia:Nikon;
:model "D300”;
:weight "0.6_kg”;
:reviewed_by :Reviewer_1.
![Page 36: 1 ARIN – KR Practical 1, Part 2 RDF Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and](https://reader034.vdocuments.us/reader034/viewer/2022051614/551c27d1550346ad4f8b5e97/html5/thumbnails/36.jpg)
36
Using shared vocabularies/ontologies
“Knowledge Engineering” is the task of maintaining
and designing reusable knowledge bases
Using shared vocabularies allows
applications/databases to be more resilient to future
changes
In our example, we could be more careful with the
using any vocabulary that is specific to only site
specific, e.g.: :Nikon_D300
:manufactured_by
:model
:weight
:reviewed_by