370 likes | 526 Views
RDF. ARIN – KR Practical 1, Part 2. Suresh Manandhar , Dimitar Kazakov. Some of these slides are based on tutorial by Ivan Herman ( W3C ) reproduced here with kind permission. All changes and errors are mine. Lecture Overview. Overview RDF RDF examples RDF tools.
E N D
RDF ARIN – KR Practical 1, Part 2 Suresh Manandhar, Dimitar Kazakov Some of these slides are based on tutorial by Ivan Herman (W3C) reproduced here with kind permission. All changes and errors are mine.
Lecture Overview • Overview RDF • RDF examples • RDF tools
Need a language to describe graphs a:title The Glass Palace http://…isbn/000651409X a:year 2000 Le palais des miroirs f:original f:titre a:publisher a:city London a:author http://…isbn/2020386682 Harper Collins a:p_name f:auteur r:type f:traducteur a:name r:type http://…foaf/Person a:homepage f:nom f:nom r:type w:isbn Besse, Christianne Ghosh, Amitav http://www.amitavghosh.com http://dbpedia.org/../The_Glass_Palace foaf:name w:reference w:author_of http://dbpedia.org/../Amitav_Ghosh w:born_in http://dbpedia.org/../Kolkata w:author_of http://dbpedia.org/../The_Hungry_Tide w:lat w:long w:author_of http://dbpedia.org/../The_Calcutta_Chromosome
RDF provides this • RDF stands for Resource Description Framework • RDF is a language for describing labelledgraphs • 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 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>)
RDF triples (cont.) • Resources can use any URI • http://www.mysite.com • http://www.example.org/file.html#home • http://www.example.org/form?a=b&c=d • RDF triples form a directed, labelledgraph (the best way to think about them!)
A simple RDF example (in Turtle) http://…isbn/2020386682 @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:original dc:title http://…isbn/000651409X Le palais des miroirs
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>
= Same RDF example (in RDF/XML) http://…isbn/2020386682 <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:original dc:title http://…isbn/000651409X Le palais des miroirs
= Same RDF example (in RDFa) http://…isbn/2020386682 <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">Glass Palace</span>”</p> . RDFa is a mechanism to allow embedding RDF meta-data within a HTML page dc:title my:original http://…isbn/000651409X Le palais des miroirs
URIs play a fundamental role • URIs made the merge possible • URIs ground RDF semantics • information can be retrieved using existing tools • this makes the “Semantic Web”, well… “Semantic Web”
RDF principles • Every node is a URI or a literal • Every edge is a URI i.e. ground all data without exception
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.
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/)
Title Author/creator Subject/keywords Description Publisher Other Contributor Date Resource type Format Resource Identifier Source Language Relation Coverage Rights management Dublin Core Elements http://dublincore.org/documents/dces/
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 RDF Elements http://www.w3.org/1999/02/22-rdf-syntax-ns#
For new concepts • Create your own namespace
“Internal” nodes • 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»? London a:city a:publisher http://…isbn/000651409X a:p_name Harper Collins
One solution: create an extra URI • The resource will be “visible” on the Web • care should be taken to define unique URI-s <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>
Or Internal identifier (“blank nodes”) <rdf:Descriptionrdf:about="http://…/isbn/000651409X"> <a:publisherrdf:nodeID="A234"/> </rdf:Description> <rdf:Descriptionrdf:nodeID="A234"> <a:p_name>HarpersCollins</a:p_name> <a:city>HarpersCollins</a:city> </rdf:Description> <http://…/isbn/2020386682> a:publisher_:A234. _:A234a:p_name "HarpersCollins". • Internal = these resources are not visible outside London a:city a:publisher http://…isbn/000651409X a:p_name Harper Collins
More on blank nodes • 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…”
Closer look – An example • Task – to build a knowledge base for an online camera shop using RDF
Closer look – An example • Task – to build a knowledge base for an online camera shop using RDF @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_bydbpedia:Nikon. :Nikon_D300 :model "D300". :Nikon_D300 :weight "0.6_kg".
Closer look – An example • Blank node – to add reviewer “John Smith” @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_bydbpedia: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”.
Closer look – An example • Co-reference – Buyer and reviewer are the same @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_bydbpedia: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.
Closer look – An example • Use separate ids – for buyer and reviewer • Public info vs Private info ### 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_bydbpedia: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”.
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”.
Converting Turtle to RDF/XML • 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 rdfconversion • Notation3 is very similar to Turtle format though not identicalUse http://www-module.cs.york.ac.uk/arin/camera.rdf.turtle - right click on the link, then select Save linked file as cwm --n3 camera.rdf.turtle--rdf > camera.rdf.rdf
Visualising RDF graph • Use RDF to dot converter from CPAN (Perl Repository): RDF-Trine-Exporter-GraphViz • Comes with command-line tool: rdfdot(you’ve got it) • Use Graphvizvisualiser to view the graph rdfdot -ttlcamera.rdf.turtle> camera.rdf.dot
Visualising RDF graph • Use Graphvizvisualiser to view the graph
Turtle shortcuts • Use of semicolon; • The following two are equivalent: :Nikon_D300 rdf:type :DSLR. :Nikon_D300 :manufactured_bydbpedia:Nikon. :Nikon_D300 :model "D300". :Nikon_D300 :weight "0.6_kg". :Nikon_D300 :reviewed_by :Reviewer_1. :Nikon_D300 rdf:type :DSLR; :manufactured_bydbpedia:Nikon; :model "D300”; :weight "0.6_kg”; :reviewed_by :Reviewer_1.
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