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 miroirs f:original f:nom f:traducteur f:auteur f:titre …isbn/ f:nom Ghosh, Amitav The Glass Palace 2000 London Harper Collins a:title a:year a:city a:p_name a:name a:homepage a:author a:publisher …isbn/ X …foaf/Person r:type r:type foaf:namew:reference 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 graphs nodes 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, …) (,, )
6 Resources can use any URI RDF triples form a directed, labelled graph (the best way to think about them!) RDF triples (cont.)
7 A simple RDF example (in dc:. dc:title "Le palais des ; dc:. dc:title "Le palais des ; my:original. my:original dc:title …isbn/ Le palais des miroirs …isbn/ X
8 Note: dc:. dc:title "Le palais des ; dc:. dc:title "Le palais des ; my:original. is expanded as: Le palais des mirroirs Le palais des mirroirs
9 = Same RDF example (in RDF/XML) Le palais des mirroirs Le palais des mirroirs my:original dc:title …isbn/ Le palais des miroirs …isbn/ X
10 = Same RDF example (in RDFa) The book entitled “ Le palais des mirroirs ” is the French translation of the “ Glass Palace ”. The book entitled “ Le palais des mirroirs ” is the French translation of the “ Glass Palace ”. my:original dc:title …isbn/ Le palais des miroirs …isbn/ X RDFa is a mechanism to allow embedding RDF meta-data within a HTML page
11 URIs made the merge possible URIs ground RDF semantics information 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: dc: rdf: rdfs: owl: geonames: dbpedia: (
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
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
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:publisher …isbn/ X
19 One solution: create an extra URI HarpersCollins HarpersCollins The resource will be “visible” on the Web care should be taken to define unique URI-s
20 Or Internal identifier (“blank nodes”) HarpersCollins HarpersCollins Internal = these resources are not visible outside a:publisher _:A234. _:A234 a:p_name "HarpersCollins". a:publisher _:A234. _:A234 a:p_name "HarpersCollins". London Harper Collins a:city a:p_name a:publisher …isbn/ X
21 Blank nodes require attention when merging blanks 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 example Task – to build a knowledge base for an online camera shop using RDF
23 Closer look – An dbpedia:. :Nikon_D300 rdf:type :DSLR. :Nikon_D300 :manufactured_by dbpedia:Nikon. :Nikon_D300 :model "D300". :Nikon_D300 :weight dbpedia:. :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 foaf:. :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 foaf:. :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 foaf:. :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 foaf:. :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 foaf:. :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”. ### This info can visible to all foaf:. :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”. ### 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: Use Notation3 (N3) to rdf conversion Notation3 is very similar to Turtle format though not identical Use - right click on the link, then select Save linked file ashttp://www-module.cs.york.ac.uk/arin/camera.rdf.turtle
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. :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. :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 :Nikon_D300 :manufactured_by :model :weight :reviewed_by