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.

Graph and RDF databases

2,548 views

Published on

This presentation is an introduction to the Graph and RDF databases.

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

Graph and RDF databases

  1. 1. Graph and RDF Databases Context : Course of Advanced Databases Prepared by : Nassim BAHRI February 19th, 2015
  2. 2. Table of contents I. Introduction :Overview of BIG DATA & NOSQL II. Graph Databases III. RDF Databases IV. Application example V. Scientific article VI. Conclusion and Q&A
  3. 3. Introduction 3 Not Only SQL Storing data in memory Distributed databases
  4. 4. Introduction : Data Model 4 Documents Databases (Voldemort, Riak) Big Table Column (Hbase, cassandra, Hypertable) Key-Value (MongoDB) Graph Databases (Neo4J)
  5. 5. Introduction : Data Model 5 Data complexity Datasize Key-Value Stores Column Family Document Databases Graph Databases 90% of use cases This is what we are interested Source : Neo Technology webinar
  6. 6. Graph Databases What is Graph Database? A graph database is a databases whose specific purpose is the storage of graph-oriented data structures.  Is simply an object oriented database based on Graph theory. 6
  7. 7. Graph Databases Representation • Nodes • Relationships between nodes • Properties on both 7 2 3 1 Name : John Age : 43 Name : Google Type : Ford Color : blue Work in Since : 2013
  8. 8. Graph Databases The power of Graph Databases Performance Flexibility Agility 8
  9. 9. Graph VS Relational Databases Relational Database Modeling ID Name 1 Larry Page 2 Sergey Brin 3 Larry Elisson N … ID Name 1 Google 2 Oracle … … N … PersonID CompanyID Since 1 1 1998 2 1 2001 3 2 2010 Person Company WorksIn SELECT Person.Name FROM Person,Company,WorksIn WHERE Company.Name='Google' AND WorksIn.CompanyID=Company.ID AND WorksIn.PersonId=Person.ID; Google's employees? Lookup Lookup Lookup 9
  10. 10. Graph VS Relational Databases Graph Database Modeling Name : Larry Page Name : Google Name : Sergey Brin Name : Oracle Name : Larry Elisson Person 1 Person 2 Company 1 Company 2 Person 3 WorksIN Since : 2001 Since : 2010 Since : 1998 Lookup 10
  11. 11. Graph Databases Graph storage and graph processing 1. The underlying storage • Some databases use native graph storage, • The other databases use relational database, an object-oriented database,… 2. The processing engine • The nodes are physically connected to each other in database, • index-free adjacency 11
  12. 12. Graph Databases Graph Database Management System 12Source [1]
  13. 13. Graph Databases : Example Visual Modeling 13 Name : John Age : 27 FRIEND_OF Name : Sally Age : 32 Title : Graph Databases Authors : Ian Robinson, Jim Webber Since : 01/09/2013 Since : 01/09/2013 On : 02/09/2013 Rating : 4 On : 02/03/2013 Rating : 5 FRIEND_OF
  14. 14. Graph Databases : Example Create a simple dataset // Create Sally CREATE (sally:Person { name: 'Sally', age: 32 }) // Create John CREATE (john:Person { name: 'John', age: 27 }) // Create Graph Databases book CREATE (gdb:Book { title: 'Graph Databases', authors: ['Ian Robinson', 'Jim Webber'] }) // Connect Sally and John as friends CREATE (sally)-[:FRIEND_OF { since: 1357718400 }]->(john) // Connect Sally to Graph Databases book CREATE (sally)-[:HAS_READ { rating: 4, on: 1360396800 }]->(gdb) // Connect John to Graph Databases book CREATE (john)-[:HAS_READ { rating: 5, on: 1359878400 }]->(gdb) 14
  15. 15. Graph Databases : Example 15
  16. 16. Graph Databases : Example Simple selection from node: Query 1 : How old are Sally? MATCH (sally:Person { name: 'Sally' }) RETURN sally.age as sally_age 16
  17. 17. Graph Databases : Example Simple selection from node: Query 2 : Who are the authors of Graph Databases? MATCH (gdb:Book { title: 'Graph Databases' }) RETURN gdb.authors as authors 17
  18. 18. Graph Databases : Example Selection using relationship: Query 3 : Who are sally's friends? MATCH (sally:Person { name: 'Sally' }) MATCH (sally)-[r:FRIEND_OF]-(person) RETURN person.name as sally_friend 18
  19. 19. Graph Databases : Example Selection using relationship and group function: Query 4 : What is the average rating of Graph Databases? MATCH (gdb:Book { title: 'Graph Databases' }) MATCH (gdb)<-[r:HAS_READ]-() RETURN avg(r.rating) as average_rating 19
  20. 20. Graph Databases : Example Using order and limit in query: Query 5 : Who Read Graph Databases First, Sally or John? MATCH (people:Person) WHERE people.name = 'John' OR people.name = 'Sally' MATCH (people)-[r:HAS_READ]->(gdb:Book { title: 'Graph Databases' }) RETURN people.name as first_reader ORDER BY r.on LIMIT 1 20
  21. 21. Graph Databases : Example Visual Modeling 21 Name : John Age : 27 FRIEND_OF Name : Sally Age : 32 Name : Alain Age : 19 Since : 01/09/2013 Since : 01/09/2013 FRIEND_OF Since : 01/11/2014
  22. 22. Graph Databases : Example Completing our schema // Create Alain CREATE (alain:Person { name: 'Alain', age: 19 }) // Connect Sally and Alain as friends MATCH (alain:Person { name: 'Alain' }) MATCH (sally:Person { name: 'Sally' }) CREATE (sally)-[:FRIEND_OF { since: 1358818400 }]->(alain) 22 Alain Sally John GDB book
  23. 23. Graph Databases : Example Node / relationship navigation: Query 6 : Which is shared between Alain and John Friend? MATCH (alain:Person { name: 'Alain' }) MATCH (john:Person { name: 'John' }) MATCH (alain)-[:FRIEND_OF]-(person)-[:FRIEND_OF]-(john) RETURN person.name as friend 23
  24. 24. Graph Databases : Example Update node’s properties: Query 7 : Change Alain name to Larry MATCH (n { name: 'Alain' }) SET n.name = 'Larry' Query 8 : Remove property MATCH (n { name: 'Larry' }) SET n.name = NULL Query 9 : Add property MATCH (n { name: 'John' }) SET n += { hungry: TRUE , position: 'Entrepreneur' } 24
  25. 25. RDF Databases The principle of the web 25 HTTP Request HTTP Response URL : http://website.com Communication protocol : HTTP Representation language : HTML
  26. 26. RDF Databases Changing status 26 URL URI IRI Uniform Resource Locator Uniform Resource Identifier International Resource Identifier http://website.com http://animals.com#lion http://‫.الحيوانات‬tn#lion
  27. 27. RDF Databases W3C Standards 27 Identification Representation Query Reasoning
  28. 28. RDF Databases RDF Resource Description Framework 28 means : pages, person, animals Idea,… : attributes, characteristics, Relationship,… : Model, language and syntax to build description
  29. 29. RDF Databases Data model & syntax Description : (Subject, Predicate, object) “example : doc.html is created by John and belongs to the music theme” 29 Doc.html is created by John Doc.html belongs to music theme
  30. 30. RDF Databases Data model & syntax (Subject, Predicate, object) (Vertex, edge, Vertex) 30 John Doc.html Music Author Theme
  31. 31. RDF Databases Labeled graph with URI and literals 31 http://www.website.com/john#me http://www.website.com/doc.html Music http://www.website.com/schema#author http://www.website.com/schema#theme
  32. 32. RDF Databases RDF Syntaxes XML, Turtle, TriG, JSON-LD,… Turtle syntax @prefix rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#> @prefix site : <http://www.website.com/schema#> <http://www.website.com/doc.html> site:author <http://www.website.com/john#me>; site:theme "Music". 32
  33. 33. RDF Databases SPARQL Protocol And RDF Query Language • Syntax similar to SQL SELECT data, FROM data source WHERE { conditions } 33
  34. 34. RDF Databases SPARQL Protocol And RDF Query Language ?x rdf:type ex:Person Get all person SELECT ?subject ?property ?value WHERE { ?subject ?property ?value } Get the full Graph database SELECT ?x WHERE { ?x rdf:type ex:Person . ?x :name ?name . } Get all person who have a name 34
  35. 35. RDF Databases SPARQL Protocol And RDF Query Language Declaring prefixes PREFIX esen : <http://esen.tn#> SELECT ?student WHERE { ?student esen:registeredAt ?x. } 35
  36. 36. RDF Databases SPARQL Protocol And RDF Query Language Optional pattern PREFIX foaf : <http://xmlns.com/foaf/0.1> SELECT ?person ?name WHERE { ?person foaf:homepage <http://john.info> . OPTIONAL { ?person foaf:name ?name .} } name : unbound 36
  37. 37. RDF Databases SPARQL Protocol And RDF Query Language Union PREFIX foaf : <http://xmlns.com/foaf/0.1> SELECT ?name WHERE { ?person foaf:name ?name . { {?person foaf:homepage <http://john.info> .} UNION {?person foaf:homepage <http://paul.info> .} } } 37
  38. 38. RDF Databases SPARQL Protocol And RDF Query Language Minus PREFIX ex : <http://website.com#> SELECT ?person WHERE { { ?person rdf:type ?type } MINUS { ?person rdf:type ex:student } } 38
  39. 39. RDF Databases Use case : rich snippets Google 39 <div xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Person"> My name is <span property="v:name"> Pierre Dumoulin</span>. My personal homepage: <a href="http://www.example.com" rel="v:url" > www.homepage.com</a>I’m living is <span rel="v:address" typeof="v:address"> <span property="v:street-address">12 street name</span> <span property="v:locality">city name</span> ,<span property="v:region">XY</span> <span property="v:postal-code">12345</span>. <span> </div>
  40. 40. Application example (RDF) Data storage # Default graph (stored at http://example.org/foaf/aliceFoaf) @prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name "Alice" . . _:b foaf:mbox <mailto:bob@work.example> . . _:a foaf:mbox <mailto:alice@work.example> . Query PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name FROM <http://example.org/foaf/aliceFoaf> WHERE { ?x foaf:name ?name } 40 Name Alice Result
  41. 41. Application example (Neo4J) Question : Who is older, Sally or John? 41 Name : John Age : 27 FRIEND_OF Name : Sally Age : 32 Name : Alain Age : 19 Since : 01/09/2013 Since : 01/09/2013 FRIEND_OF Since : 01/11/2014
  42. 42. Application example (Neo4J) Who is older, Sally or John? MATCH (people:Person) WHERE people.name = 'John' OR people.name = 'Sally' RETURN people.name as oldest ORDER BY people.age DESC LIMIT 1 42
  43. 43. Scientific article Title : Querying RDF Data from a Graph Database Perspective Book title : The Semantic Web: Research and Applications Pages : 346-360 Online ISBN : 978-3-540-31547-6 Series Volume : 3532 Publisher : Springer Berlin Heidelberg Copyright : 2005 Authors : Renzo Angles Claudio Gutierrez 43
  44. 44. Scientific article MODEL LEVEL DATA COMPLEXITY CONNECTIVITY TYPE OF DATA Network physical simple high homogeneous Relational logical simple low homogeneous Semantic user simple/medium high homogeneous Object-O logical/physical complex Medium heterogeneous XML logical medium medium heterogeneous RDF logical medium high heterogeneous 44 Table 1 : Summary of comparison among different database models
  45. 45. Scientific article PROPERTY G G+ GraphLog Gram GraphDB Lorel F-G Adjacent nodes +/- √ √ √ +/- √ +/- Adjacent edges +/- √ √ √ +/- √ +/- Degree of a node X √ √ x ? X x Path √ √ √ √ √ √ √ Fixed-length Path √ √ √ √ √ √ √ Distance between two nodes X √ √ X ? x x Diameter x √ √ X ? x X 45 Table 2 : Support of some graph database query languages for the example graph properties
  46. 46. Scientific article PROPERTY RQL SeRQL RDQL Triple N3 Versa RxPath Adjacent nodes +/- +/- +/- +/- +/- +/- X Adjacent edges +/- +/- +/- +/- X x X Degree of a node +/- x x x x x X Path x x x x X x +/- Fixed-length Path +/- +/- +/- +/- +/- X +/- Distance between two nodes x x x x x x X Diameter x x x x x x x 46 Table 3 : Support of some current RDF query languages for some example graph properties
  47. 47. Conclusion • Using Graph database for storing data in graph form or in hierarchical tree structure. • Graph database : Performance, Agility, Flexibility • The shortest path 47
  48. 48. Bibliography [1] Ian Robinson, Jim Webber, and Emil Eifrem.«Graph Databases».O’REILLY, 2013. [2] Serge Miranda, Fabien Gandon. «Des Bases de Données à Big Data». Course at Nice Sophia university, MOOC, 2015. [3] Michel Domenjoud. «Bases de données graphes : un tour d’horizon». Available on <http://blog.octo.com/bases-de-donnees-graphes-un-tour-dhorizon> (consulted 18/02/2015). [4] Neo4J community. «Cypher Query Language». Available on <http://neo4j.com/developer/data-modeling/> (consulted 18/02/2015). [5] Frank Manola, Eric Miller, Brian McBride. «RDF 1.1 Primer». Available on <http://www.w3.org/TR/2014/NOTE-rdf11-primer-20140225/> (consulted 18/02/2015). [6] Eric Prud'hommeaux, Andy Seaborne. «SPARQL Query Language for RDF». Available on <http://www.w3.org/TR/rdf-sparql-query/> (consulted 18/02/2015). [7] Neo4J community. «Introduction to graph databases webinar». Available on <http://www.neo4j.org/learn/videos_webinar> (consulted 18/02/2015). 48
  49. 49. 49 Thanks for your attention

×