Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
Loading in …5
×

# Jarrar: RDF - Graph Data Model

913 views

Published on

This presentation is about:
- Relational vs. Tree vs. Graph data models
- Why XML is not enough
- RDF
- Mapping between R.DB and RDF

Published in: Education
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

### Jarrar: RDF - Graph Data Model

1. 1. Mustafa Jarrar Lecture Notes, Web Data Management (MCOM7348) University of Birzeit, Palestine 1st Semester, 2013 RDF Graph Data Model Dr. Mustafa Jarrar University of Birzeit mjarrar@birzeit.edu www.jarrar.info Jarrar © 2013 1
2. 2. Watch this lecture and download the slides from http://jarrar-courses.blogspot.com/2013/11/web-data-management.html Jarrar © 2013 2
3. 3. Outline • Relational vs. Tree vs. Graph data models • Why XML is not enough • RDF • Mapping between R.DB and RDF Keyword: Graph Data Models, Try Data Models, Relational Data Models, RDF, Directed Labeled Graph, XML Semantics, Mapping XML to RDF, Mapping RDB to RDF Jarrar © 2013 3
4. 4. Reading RDF Primer (http://www.w3.org/TR/rdf-syntax-grammar/ ) Please have a look only to: Chapter 2 Making Statements About Resources Chapter 3 An XML Syntax for RDF: RDF/XML Chapter 3 Defining RDF Vocabularies: RDF Schema Jarrar © 2013 4
5. 5. Relational vs Tree vs Graph Data model Relational Data models • Data is represented in tuples, groups into relations • Relational databases Tree data models • Parent / child relationships • Directed Acyclic Graphs • XML is a tree data model Graph Data Models • A nodes is a data element and links are relations between these elements. • Directed Labeled Graphs • RDF is a graph data model  Tree are special case of graphs Jarrar © 2013 5
6. 6. What is XML • Provides a common syntax for marking up documents. • Easy to exchange between computers (web) • Data model: an XML Document is an ordered labeled tree (/collection of trees). • W3C standard since 1997. bookinfo <bookInfo> <title>Orientalism</title> <author> <persName> <title>Prof.</title> <foreName>Edward</foreName> <surName>Said</surName> <roleName>University Professor <placeName>Columbia University </placeName> </roleName> </persName> </author> </bookInfo> title author persName title foreName surName roleName placeName Jarrar © 2013 6
7. 7. XML Example <address> <name>Universsity of Birzeit</name> <street>Almarj 435</street> <town>Birzeit</town> </address> Jarrar © 2013 7
8. 8. Address Example: XML to XML XML Markup 1: <address> <name>University of Birzeit</name> <street>Almarj 435</street> <town>Birzeit</town> </address> XML stylesheets to transform between XML representations XML Markup 2: <address> <name>University of Birzeit</name> <place> <street>Almarj 435</street> <town>Birzeit</town> </place> </address> Jarrar © 2013 8
9. 9. Why XML is Not Enough? • It provides syntax, but not semantics, which is important when exchanging/representing data over the Web. <aaaa> <bbbb>Universsity of Birzeit</bbbb> <cccc>Almarj 435</cccc> <dddd>Birzeit</dddd> </aaaa> • Not primitive. Same data can be represented in many ways, which is a problem when exchanging/representing data over the Web. <address> <name>University of Birzeit</name> <street>Almarj 435</street> <town>Birzeit</town> </address> <address name=“University of Birzeit”> <street>Almarj 435</street> <town>Birzeit</town> </address> Jarrar © 2013 9
10. 10. What is RDF? • W3C standard since 1999 • RDF stands for Resource Description Framework. • For describing resources on the web. • Written in XML. It is not a language but a framework • You see it as a way of writing XML  making it meaningful and more primitive. • You may see it independent, RDF data might never occur in XML form Jarrar © 2013 10
11. 11. Makes use of URIs • In order to refer to and identify things on the web (i.e., web resource) RDF uses a URI (Uniform Resource Identifier). •  URIs are like Global Primary Key. • Unlike URLs, URIs are not limited to identifying things that have a network location. • A URI reference (URIref) is a URI, together with an optional fragment identifier at the end. http://www.example.org/index.html#section2 Jarrar © 2013 11
12. 12. RDF Important Concepts • Data is represented in RDF as a directed labeled graph. • An RDF graph is a set of triples, of the form <Subject, Predicate, Object> http://www.amazon.com/Orientalism-Edward-W-Said/dp/039474067Xc 11\$ :Author Edward Said Orientalism Each Subject and each Predicate must be a URI; that is, it has to be a unique identifier, not a literal. An Object can be either a URI or a literal. Jarrar © 2013 12
13. 13. Example http://www.amazon.com/Orientalism-Edward-W-Said/dp/039474067Xc 11\$ :Author Edward Said Orientalism <?xml version="1.0"?> <rdf:RDF xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns# xmlns:a="http://www.example.com" xmlns:w="http://en.wikipedia.org/wiki/"> <rdf:Description rdf:about="http://www.amazon.com/Orientalism-Edward-W-Said/dp/039474067X"> <a:Title>Orientalism</a:Title> <a:Price>11\$</a:Price> <a:Author>Edward_Said</a:Author> </rdf:Description> </rdf:RDF> Jarrar © 2013 13
14. 14. Example a:Author http://en.wikipedia.org/wiki/Edward_Said 25/9/2003 11\$ Orientalism 1/11/1935 a:BirthCity http://www.amazon.com/Orientalism-Edward-W-Said/dp/039474067Xc Edward Saïd <?xml version="1.0"?> <rdf:RDF xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns# Jerusalem xmlns:a="http://www.example.com/" xmlns:w="http://en.wikipedia.org/wiki/"> <rdf:Description rdf:about="http://www.amazon.com/Orientalism-Edward-W-Said/dp/039474067X"> <a:Title>Orientalism</a:Title> <a:Price>11\$</a:Price> <a:Author> <rdf:Description rdf:about="w:Edward_Said"> <a:BirthCity>Jerusalem</a:BirthCity> <a:BornAt>1/11/1935</a:BornAt> <a:DiedA>25/9/2003</a:DiedA> </rdf:Description> </a:Author> </rdf:Description> </rdf:RDF> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> Jarrar © 2013 14
15. 15. Example :Author 25/9/2003 http://en.wikipedia.org/wiki/Edward_Said :BirthCity http://www.amazon.com/Orientalism-Edward-W-Said/dp/039474067Xc <?xml version="1.0"?> Orientalism Edward Saïd <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 11\$ 1/11/1935 xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:a="http://www.example.com#" xmlns:w="http://en.wikipedia.org/wiki/"> http://en.wikipedia.org/wiki/Jerusalem <rdf:Description rdf:about="http://www.amazon.com/Orientalism-Edward-W-Said/dp/039474067X"> <a:Title>Orientalism</a:Title> <a:Price>11\$</a:Price> <a:Author> <rdf:Description rdf:about="w:Edward_Said"> <a:BornAt>1/11/1935</a:BornAt> <a:DiedA>25/9/2003</a:DiedA> 760800 Palestine <a:BirthCity> <rdf:Description rdf:about="http://en.wikipedia.org/wiki/Jerusalem"> <a:Population>760800</a:Population> <a:CapitalOf>Palestine</a:CapitalOf> </rdf:Description> </a:BirthCity> </rdf:Description> </a:Author> </rdf:Description> </rdf:RDF> Jarrar © 2013 15
16. 16. Another Example Jarrar © 2013 16
17. 17. Directed Labelled Graph Representation Jarrar © 2013 17
18. 18. Simple Example <?xml version="1.0"?> <RDF> <Description about="http://www.w3schools.com/default.asp"> <author>Jan Egil Refsnes</author> <created>November 1, 1999</created> <modified>February 1, 2004</modified> </Description> </RDF> Jarrar © 2013 18
19. 19. Example Explained • In the example: – the URI "http://www.w3schools.com/-default.asp" is used to identify a web page, – the property "author" describes the author of the page, – the property value is "Jan Egil Refsnes". – The property "created" tells when the page was created, and the property "modified" when it was last modified. Jarrar © 2013 19
20. 20. Subject, Predicate & Object • RDF terminology also use the words subject, predicate and object. • The resource http://www.w3schools.com/default.asp is the subject • The property "author" is the predicate • The value "Jan Egil Refsnes" is the object Jarrar © 2013 20
21. 21. Example 2 <rdf:RDF> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax ns#" xmlns:cd="http://www.recshop.fake/cd"> <rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"> <cd:artist>Bob Dylan</cd:artist> <cd:country>USA</cd:country> <cd:company>Columbia</cd:company> <cd:price>10.90</cd:price> <cd:year>1985</cd:year> </rdf:Description> ............ Jarrar © 2013 21
22. 22. Example 2 (cont) <rdf:Description rdf:about="http://www.recshop.fake/cd/Hide your heart"> <cd:artist>Bonnie Tyler</cd:artist> <cd:country>UK</cd:country> <cd:company>CBS Records</cd:company> <cd:price>9.90</cd:price> <cd:year>1988</cd:year> </rdf:Description> </rdf:RDF> Jarrar © 2013 22
23. 23. Details of the Example • The first line in the XML file is the XML declaration, telling the version of XML. • The rdf:RDF element indicates that the content is RDF. • The xmlns:rdf namespace, specifies that tags with the rdf: prefix are from the namespace defined by "http://www.w3.org/1999/02/22-rdf-syntax-ns#". • The xmlns:cd namespace, specifies that tags with the cd: prefix are from the namespace defined by "http://www.recshop.fake/cd". • The rdf:Description element contains the description of a resource identified by the rdf:about attribute. • The cd:artist element describes a property of the resource, and so does cd:country, etc. Jarrar © 2013 23
24. 24. Table Representation (List of Triples) Subject Predicate Object http://www.recshop.fake/cd/Empire Burlesque http://www.recshop.fake/cdartist "Bob Dylan" http://www.recshop.fake/cd/Empire Burlesque http://www.recshop.fake/cdcount ry "USA” http://www.recshop.fake/cd/Empire Burlesque http://www.recshop.fake/cdcomp any "Columbia” http://www.recshop.fake/cd/Empire Burlesque http://www.recshop.fake/cdprice "10.90” http://www.recshop.fake/cd/Empire Burlesque http://www.recshop.fake/cdyear "1985” Jarrar © 2013 24
25. 25. Main RDF Properties and Attributes Main RDF Properties • rdf:subject The subject of the resource in an RDF Statement • rdf:predicate The predicate of the resource in an RDF Statement • rdf:object The object of the resource in an RDF Statement • rdf:type The resource is an instance of a class Main RDF Attributes • rdf:RDF The root of an RDF document • rdf:about Defines the resource being described • rdf:Description Container for the description of a resource • rdf:resource Defines a resource to identify a property • rdf:datatype Defines the data type of an element Jarrar © 2013 25
26. 26. RDF Validator • Check the correctness of an RDF document: http://www.w3.org/RDF/Validator/ • Result shows the subject, predicate and object of each element of the document and a graph of the model. Jarrar © 2013 26
27. 27. Mapping XML into RDF (Example) <Article ID=B2 Year=“2005”> <Author href=“#A1”/> <Author ID=A1> <Author ID=A2> <Name>Tom</Name> <Name>Bob</Name> <Affiliation ID=UoM> <Affiliation ID=UoC> <Name>University of Malta</Name> <Name>University of Cyprus</Name> <Country ID=mt> <Country ID=cy> <Name> Malta</Name> <Name> Cyprus</Name> <Capital>Valletta</Capital> <Capital>Nicosia</Capital> </Country> </Country> </Affiliation> </Affiliation> <Author> <Author> </Article> </Article> XML <XML> ID=B1 Year=“2000”> <Article 2000 B1 Author “Malta” Affiliation UoM County mt “Valletta” “Tom” Root “Bob” Article RDF “University of Malta” Employs A1 <Article ID=B3 Year=“2007”> <Author ID=A3> <email>ps@uoc</email> <Affiliation href=“#UoC”/> <Author> </Article> <Article ID=B4 Year=“2008”> <Publisher ID=ACM/> </Article> </XML> B2 A2 Affiliation Employs B3 2008 ACM “Cyprus” cy “University of Cyprus” A3 2007 County “Nicosia” 2005 B4 UoC p3@uoc Jarrar © 2013 27
28. 28. Mapping Database into RDF (Example) RDF Article ID Year B1 Data Web 2007 B2 Author Tile Semantic Web 2005 Article Person Person B1 A1 ID Name Affiliation B1 A2 A1 Tom Lara UoM B2 A2 A2 Bob Hacker UoC Country Affiliation ID Name ID Country mt Malta UoM mt cy Cyprus UoC cy S :B1 :B1 :B1 :B2 :B2 :B2 :B1 :B1 :B2 :A1 :A1 :A1 :A2 :A2 :A2 :UoM :UoM :mt :mt :UoC :UoC :cy :cy Jarrar © 2013 P rdf:Type :Title :Year rdf:Type :Title :Year :Author :Author :Author rdf:Type :Name :Affiliation :Type :Name :Affiliation :Type :Country :Type :Name :Type :Country :Type :Name O :Article “Data Web” 2007 :Article “Semantic Web” 2005 :A1 :A2 :A1 :Person “Tom Lara” :UoM :Person “Bob Hacker” :UoC :University :mt :Country “Malta” :University :cy :Country “Cyprus” 28
29. 29. Practice Session Write all information in your Passport into formats: 1. in RDF/XML format, 2. as SPO table. Jarrar © 2013 29
30. 30. Practice Session ( Solution Example) <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mz="http://www.example.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema-datatypes"> <rdf:Description rdf:about="http://mohammad.example.com/"> <mz:id rdf:datatype="xsd:integer">111111111</mz:id> <mz:firstname>Mohammad</mz:firstname> <mz:firstname xml:lang="ar"> </mz:firstname> <mz:familyname>ZeinEddin</mz:familyname> <mz:wife rdf:resource="http://tamara.example.com/" /> </rdf:Description> <rdf:Description rdf:about="http://tamara.example.com/"> <mz:id rdf:datatype="xsd:integer">2222222222</mz:id> <mz:firstname>Tamara</mz:firstname> <mz:familyname>Adam</mz:familyname> </rdf:Description> </rdf:RDF> Jarrar © 2013 30
31. 31. Practice Session ( Solution Example) Jarrar © 2013 31
32. 32. Practice Session ( Solution Example) Jarrar © 2013 32