1 arin – kr practical 1, part 2 rdf some of these slides are based on tutorial by ivan herman...
TRANSCRIPT
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
2
Lecture Overview
Overview RDF
RDF examples
RDF tools
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
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
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>)
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.)
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
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>
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
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
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
12
RDF principles
Every node is a URI or a literal
Every edge is a URI
i.e. ground all data without exception
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.
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/)
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/
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#
17
For new concepts
Create your own namespace
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
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
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
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
22
Closer look – An exampleTask – to build a knowledge base for an online
camera shop using RDF
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
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”
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
26
Closer look – An example
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
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”.
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
30
31
Using RDF/XML validator
32
Using RDF/XML validator
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
34
Visualising RDF graph
Use Graphviz visualiser to view the graph
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.
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