Introduction to Graph Database

67 %
33 %
Information about Introduction to Graph Database
Technology

Published on February 18, 2014

Author: leezhenyu

Source: slideshare.net

Description

Introduction to Graph database, using K-pop as a database modelling case. From the idea of graph database, Neo4j installation, modelling, Cypher to business application.

Introduction to 
 Graph Database ! Eric C.Y. LEE
 eric@nus.edu.sg
 eric@eric.lv
 National University of Singapore February, 2014

Outline • Relational Database v.s. Graph Database • Design the Database in Graph Architecture • Basic Usage of Neo4j • Cypher Query Language • Business application !2

Relational Database • Based on table schema. • Field -> Record -> Table -> Database • Query by SQL syntax. • Open source and commercial products available. • MySQL, Oracle, PostgreSQL, MS-SQL Server. • LAMP: Linux+Apache+MySQL+PHP !3

Graph Database • Schema-less, based on graph theory. • Only two types of data inside the graph database. • Node and relationship (edge) . • One of the NoSQL database management systems, query by several query languages, depend on database products. • Widely use in social network system and large scale website architecture. !4 Figure Credit: Wikipedia

Modelling a K-pop Database All materials for database construction, 
 we can find in these wikipedia pages. !5

The information I want to provide. • Team member profiles • • Group, Name, Birth Place,Birth Year, Birth Month Released albums • Title, Released Year, Number of Sales !6

K-Pop Profiles in Table View Group SNSD SNSD SNSD SNSD SNSD SNSD SNSD SNSD SNSD KARA KARA KARA KARA Name Taeyeon Jessica Sunny Tiffany Hyoyeon Yuri Sooyoung Yoona Seohyun Gyuri Seungyeon Hara Jiyoung Birth Place Korea U.S.A. U.S.A. U.S.A. Korea Korea Korea Korea Korea Korea Korea Korea Korea !7 Birth Year 1989 1989 1989 1989 1989 1989 1990 1990 1991 1988 1988 1991 1994 Birth Month March April May August September December February May June May July January January Any finding?

K-Pop Albums in Table View Group Title Released Year Number of sales SNSD Girls’ Generation 2007 284994 SNSD Oh 2010 406662 SNSD The Boys 2011 449616 SNSD I GOT A BOY 2013 293302 KARA BLOOMING 2007 50000 KARA REVOLUTION 2009 80000 KARA STEP 2011 100662 KARA FULL BLOOM 2013 46199 !8 Any finding?

Group SNSD SNSD SNSD SNSD SNSD SNSD SNSD SNSD SNSD KARA KARA KARA KARA SNSD KARA Name Taeyeon Jessica Sunny Tiffany Hyoyeon Yuri Sooyoung Yoona Seohyun Gyuri Seungyeon Hara Jiyoung Birth Place Korea U.S.A. U.S.A. U.S.A. Korea Korea Korea Korea Korea Korea Korea Korea Korea U.S.A Korea !9 Birth Year 1989 1989 1989 1989 1989 1989 1990 1990 1991 1988 1988 1991 1994 1988 1989 1990 1991 1994 Birth Month March April May August September December February May June May July January January January February March April September May December June July August

Group Title Released Year Number of sales SNSD Girls’ Generation 2007 284994 SNSD Oh 2010 406662 SNSD The Boys 2011 449616 SNSD I GOT A BOY 2013 293302 KARA BLOOMING 2007 50000 KARA REVOLUTION 2009 80000 KARA STEP 2011 100662 KARA FULL BLOOM 2013 46199 2007 2009 2010 2011 2013 SNSD KARA !10

Graph Modelling !11

Neo4j 1. Download latest version 2.0.1 from www.neo4j.org 2. Cross-platform, Java 1.7 is required. 3. Extract the compressed package, execute main program. 4. Web console: http://localhost:7474 2 1 3 !12 4

Default Web Console Query Statement Input Query Result Area

Web Admin Interface • URL localhost:7474/webadmin/ !14

Allow Remote Connection • Modify configuration file. 
 (/neo4j-root/conf/neo4j-server.properties) • Uncomment #org.neo4j.server.webserver.address=0.0.0.0 !15

Cypher • Basic statement: MATCH, CREATE, WHERE, RETURN • Inspired by “ASCII Art”.
 
 MATCH (singer)-[:BIRTH_PLACE]->(country) 
 RETURN singer, country; singer BIRTH PLACE country (singer)-[:BIRTH_PLACE]->(country) !16

Cypher of Example • Create the Nodes • Singer
 CREATE (n:Singer {name:”Taeyeon”})
 CREATE (n:Singer {name:”Jessica”})
 CREATE (n:Singer {name:”Sunny”})
 CREATE (n:Singer {name:”Tiffany”})
 CREATE (n:Singer {name:”Hyoyeon”})
 CREATE (n:Singer {name:”Yuri”})
 CREATE (n:Singer {name:”Sooyoung”})
 CREATE (n:Singer {name:”Yoona”})
 CREATE (n:Singer {name:”Seohyun”})
 CREATE (n:Singer {name:”Gyuri”})
 CREATE (n:Singer {name:”Seungyeon”})
 CREATE (n:Singer {name:”Hara”})
 CREATE (n:Singer {name:”Jiyoung”})
 !17 • Group
 CREATE (n:Group {name:”SNSD”})
 CREATE (n:Group {name:”KARA”}) • Year
 CREATE (n:Year {year:”1988”})
 CREATE (n:Year {year:”1989”})
 CREATE (n:Year {year:”1990”})
 CREATE (n:Year {year:”1991”})
 CREATE (n:Year {year:”1994”})
 CREATE (n:Year {year:”2007”})
 CREATE (n:Year {year:”2009”})
 CREATE (n:Year {year:”2010”})
 CREATE (n:Year {year:”2011”})
 CREATE (n:Year {year:”2013”})

Cypher of Example • Create the Nodes • Album
 • CREATE (n:Album {name:”Girl’s Generation”, sales: “284994”})
 CREATE (n:Album {name:”Oh”, sales:”406662”})
 CREATE (n:Album {name:”The boys”, sales:”449616”})
 CREATE (n:Album {name:”I got a boy”, sales:”293302”})
 CREATE (n:Album {name:”Blooming”,sales:”50000”})
 CREATE (n:Album {name:”Revolution”,sales:”80000”})
 CREATE (n:Album {name:”STEP”,sales:”100662”})
 CREATE (n:Album {name:”Full Bloom”,sales:”46199”})
 
 !18 Country
 CREATE (n:Country {name:”U.S.A.”})
 CREATE (n:Country {name:”Korea”}) • Month
 CREATE (n:Month {month:”January”})
 CREATE (n:Month {month:”February”})
 CREATE (n:Month {month:”March”})
 CREATE (n:Month {month:”April”})
 CREATE (n:Month {month:”May”})
 CREATE (n:Month {month:”June”})
 CREATE (n:Month {month:”July”})
 CREATE (n:Month {month:”August”})
 CREATE (n:Month {month:”September”})
 CREATE (n:Month {month:”December”})

Cypher of Example • Create Relationships • Group and Members [:HAS_MEMBER]
 MATCH (snsd:Group{name:”SNSD”}), (taeyeon:Singer{name:”Taeyeon”}), (jessica:Singer{name:”Jessica”}),(sunny:Singer{name:”Sunny”}), (tiffany:Singer{name:”Tiffany”}),(hyoyeon:Singer{name:”Hyoyeon”}), (yuri:Singer{name:”Yuri”}),(sooyoung:Singer{name:”Sooyoung”}), (yoona:Singer{name:”Yoona”}),(seohyun:Singer{name:”Seohyun”})
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(taeyeon)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(jessica)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(tiffany)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(sunny)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(hyoyeon)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(yuri)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(sooyoung)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(yoona)
 CREATE UNIQUE (snsd)-[:HAS_MEMBER]->(seohyun) !19

Cypher of Example • Create Relationships • Group and Members [:HAS_MEMBER]
 MATCH (kara:Group{name:”KARA”}), (gyuri:Singer{name:”Gyuri”}), (seungyeon:Singer{name:”Seungyeon”}), (hara:Singer{name:”Hara”}), (jiyoung:Singer{name:”Jiyoung”})
 CREATE UNIQUE (kara)-[:HAS_MEMBER]->(gyuri)
 CREATE UNIQUE (kara)-[:HAS_MEMBER]->(seungyeon)
 CREATE UNIQUE (kara)-[:HAS_MEMBER]->(hara)
 CREATE UNIQUE (kara)-[:HAS_MEMBER]->(jiyoung)
 !20

Cypher of Example • Create Relationships Albums and Released Year [:RELEASED_YEAR]
 MATCH (y2007:Year{year:”2007”}), 
 (y2009:Year{year:”2009”}),(y2010:Year{year:”2010”}),(y2011:Year{year:”2011”}), (y2012:Year{year:”2012”}),(y2013:Year{year:”2013”}),
 (album1:Album{name:”Girl’s Generation”}),
 (album2:Album{name:”Oh”}),
 (album3:Album{name:”The boys”}),
 (album4:Album{name:”I got a boy”}),
 (album5:Album{name:”Blooming”}),
 (album6:Album{name:”Revolution”}),
 (album7:Album{name:”STEP”}),
 (album8:Album{name:”Full Bloom”})
 CREATE UNIQUE (album1)-[:RELEASED_YEAR]->(y2007)
 CREATE UNIQUE (album2)-[:RELEASED_YEAR]->(y2010)
 CREATE UNIQUE (album3)-[:RELEASED_YEAR]->(y2011)
 CREATE UNIQUE (album4)-[:RELEASED_YEAR]->(y2013)
 CREATE UNIQUE (album5)-[:RELEASED_YEAR]->(y2007)
 CREATE UNIQUE (album6)-[:RELEASED_YEAR]->(y2009)
 CREATE UNIQUE (album7)-[:RELEASED_YEAR]->(y2011)
 CREATE UNIQUE (album8)-[:RELEASED_YEAR]->(y2013)
 • 
 !21

Cypher of Example • Create Relationships • Group and Albums [:HAS_ALBUM]
 MATCH (kara:Group{name:”KARA”}), 
 (snsd:Group{name:”SNSD”}),
 (album1:Album{name:”Girl’s Generation”}),
 (album2:Album{name:”Oh”}),
 (album3:Album{name:”The boys”}),
 (album4:Album{name:”I got a boy”}),
 (album5:Album{name:”Blooming”}),
 (album6:Album{name:”Revolution”}),
 (album7:Album{name:”STEP”}),
 (album8:Album{name:”Full Bloom”})
 CREATE UNIQUE (snsd)-[:HAS_ALBUM]->(album1)
 CREATE UNIQUE (snsd)-[:HAS_ALBUM]->(album2)
 CREATE UNIQUE (snsd)-[:HAS_ALBUM]->(album3)
 CREATE UNIQUE (snsd)-[:HAS_ALBUM]->(album4)
 CREATE UNIQUE (kara)-[:HAS_ALBUM]->(album5)
 CREATE UNIQUE (kara)-[:HAS_ALBUM]->(album6)
 CREATE UNIQUE (kara)-[:HAS_ALBUM]->(album7)
 CREATE UNIQUE (kara)-[:HAS_ALBUM]->(album8)
 !22

Cypher of Example • Create Relationships Singer and Country [:BIRTH_PLACE]
 MATCH (korea:Country{name:”Korea”}), 
 (gyuri:Singer{name:”Gyuri”}),
 (seungyeon:Singer{name:”Seungyeon”}),
 (hara:Singer{name:”Hara”}),
 (jiyoung:Singer{name:”Jiyoung”}),(taeyeon:Singer{name:”Taeyeon”}), (hyoyeon:Singer{name:”Hyoyeon”}),(yuri:Singer{name:”Yuri”}),(sooyoung:Singer{name:”Sooyoung”}), (yoona:Singer{name:”Yoona”}),(seohyun:Singer{name:”Seohyun”})
 • 
 CREATE UNIQUE (gyuri)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (seungyeon)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (hara)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (jiyoung)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (taeyeon)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (hyoyeon)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (yuri)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (sooyoung)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (yoona)-[:BIRTH_PLACE]->(korea)
 CREATE UNIQUE (seohyun)-[:BIRTH_PLACE]->(korea) !23

Cypher of Example • Create Relationships Singer and Country [:BIRTH_PLACE]
 MATCH (usa:Country{name:”USA”}), 
 (jessica:Singer{name:”Jessica”}),
 (tiffany:Singer{name:”Tiffany”}),
 (sunny:Singer{name:”Sunny”})
 • 
 CREATE UNIQUE (jessica)-[:BIRTH_PLACE]->(usa)
 CREATE UNIQUE (tiffany)-[:BIRTH_PLACE]->(usa)
 CREATE UNIQUE (sunny)-[:BIRTH_PLACE]->(usa)
 !24

Cypher of Example • Create Relationships Singer and Birth Year [:BIRTH_YEAR]
 MATCH (y1988:Year{Year:”1988”}),(y1989:Year{Year:”1989”}),(y1990:Year{Year:”1990”}), (y1991:Year{Year:”1991”}), (y1994:Year{Year:”1994”}),
 (gyuri:Singer{name:”Gyuri”}),(seungyeon:Singer{name:”Seungyeon”}),(taeyeon:Singer{name:”Taeyeon”}), (jessica:Singer{name:”Jessica”}),(sunny:Singer{name:”Sunny”}),(tiffany:Singer{name:”Tiffany”}), (yuri:Singer{name:”Yuri”}),(hyoyeon:Singer{name:”Hyoyeon”}),(sooyoung:Singer{name:”Sooyoung”}), (yoona:Singer{name:”Yoona”}),(seohyun:Singer{name:”Seohyun”}),(hara:Singer{name:”Hara”}), (jiyoung:Singer{name:”Jiyoung”})
 • 
 
 CREATE UNIQUE (gyuri)-[:BIRTH_YEAR]->(y1988)
 CREATE UNIQUE (seungyeon)-[:BIRTH_YEAR]->(y1988)
 CREATE UNIQUE (taeyeon)-[:BIRTH_YEAR]->(y1989)
 CREATE UNIQUE (jessica)-[:BIRTH_YEAR]->(y1989)
 CREATE UNIQUE (sunny)-[:BIRTH_YEAR]->(y1989)
 CREATE UNIQUE (tiffany)-[:BIRTH_YEAR]->(y1989)
 CREATE UNIQUE (hyoyeon)-[:BIRTH_YEAR]->(y1989)
 CREATE UNIQUE (yuri)-[:BIRTH_YEAR]->(y1989)
 CREATE UNIQUE (sooyoung)-[:BIRTH_YEAR]->(y1990)
 CREATE UNIQUE (yoona)-[:BIRTH_YEAR]->(y1990)
 CREATE UNIQUE (seohyun)-[:BIRTH_YEAR]->(y1991)
 CREATE UNIQUE (hara)-[:BIRTH_YEAR]->(y1991)
 CREATE UNIQUE (jiyoung)-[:BIRTH_YEAR]->(y1994)
 !25

Cypher of Example • Create Relationships Singer and Birth Month [:BIRTH_MONTH]
 MATCH (jan:Month{Month:”January”}),(feb:Month{Month:”February”}),(mar:Month{Month:”March”}), (apr:Month{Month:”April”}), (may:Month{Month:”May”}),(jun:Month{Month:”June”}),(jul:Month{Month:”July”}), (aug:Month{Month:”August”}),(sep:Month{Month:”September”}),(dec:Month{Month:”December”}),
 (gyuri:Singer{name:”Gyuri”}),(seungyeon:Singer{name:”Seungyeon”}),(taeyeon:Singer{name:”Taeyeon”}), (jessica:Singer{name:”Jessica”}),(sunny:Singer{name:”Sunny”}),(tiffany:Singer{name:”Tiffany”}), (yuri:Singer{name:”Yuri”}),(hyoyeon:Singer{name:”Hyoyeon”}),(sooyoung:Singer{name:”Sooyoung”}), (yoona:Singer{name:”Yoona”}),(seohyun:Singer{name:”Seohyun”}),(hara:Singer{name:”Hara”}), (jiyoung:Singer{name:”Jiyoung”})
 • 
 
 CREATE UNIQUE (hara)-[:BIRTH_MONTH]->(jan)
 CREATE UNIQUE (jiyoung)-[:BIRTH_MONTH]->(jan)
 CREATE UNIQUE (sooyoung)-[:BIRTH_MONTH]->(feb)
 CREATE UNIQUE (taeyeon)-[:BIRTH_MONTH]->(mar)
 CREATE UNIQUE (jessica)-[:BIRTH_MONTH]->(apr)
 CREATE UNIQUE (sunny)-[:BIRTH_MONTH]->(may)
 CREATE UNIQUE (yoona)-[:BIRTH_MONTH]->(may)
 CREATE UNIQUE (gyuri)-[:BIRTH_MONTH]->(may)
 CREATE UNIQUE (seohyun)-[:BIRTH_MONTH]->(jun)
 CREATE UNIQUE (seungyeon)-[:BIRTH_MONTH]->(jul)
 CREATE UNIQUE (tiffany)-[:BIRTH_MONTH]->(aug)
 CREATE UNIQUE (hyoyeon)-[:BIRTH_MONTH]->(sep)
 CREATE UNIQUE (yuri)-[:BIRTH_MONTH]->(dec) !26

Query Cases Who is the member of Girl’s Generation(SNSD)?
 • 
 MATCH (snsd{name:”SNSD”})-[:HAS_MEMBER]->(member)
 RETURN member; Who is the youngest member of KARA?
 • 
 MATCH (kara{name:”KARA”})-[:HAS_MEMBER]->(member), (member)-[:BIRTH_YEAR]->(year)
 RETURN member, ORDER BY (year.year) LIMIT 1 ; !27

Query Cases Who is not born in Korea? Who and where.
 • 
 MATCH (singer)-[:BIRTH_PLACE]->(country) 
 WHERE NOT country.name="Korea" 
 RETURN singer, country; Which album is the top selling of SNSD? Show the album name and number.
 • 
 MATCH (Group{name:”SNSD”})-[:HAS_ALBUM]->(albums)
 WITH albums ORDER BY albums.sales DESC
 RETURN albums LIMIT 1; !28

Business Application GENDER_IS Customer:A Male BOUGHT_ALBUM Customer:B GENDER_IS BOUGHT_ALBUM Integrate a subset graph of customer 
 purchase history to the existed K-pop database. !29

Potential Orders? Customer:B bought SNSD and KARA’s album, we can promote albums of T-ARA to him?
 • 
 Both SNSD and KARA are female K-pop groups, T-ARA is female K-pop group too. Give Customer:A price discount, push him buy the album “I GOT A BOY”.
 • 
 SNSD has 4 albums. According to the graph, Customer:A bought the 3 albums from us. He didn’t buy “I GOT A BOY”. Ask male customer buy female K-pop groups’ album is much easier.
 • 
 The database shows most of female K-pop group album buyers are male. !30

[:HAS_STUDENT] Person
 Name:”TAN TIN WEE”
 Occupation: “Professor” [:HAS_MODULE] Person
 Name:”Eric Lee”
 Occupation: “Student” [:HAS_TA] [:HAS_TA] [:SAY] Person
 Name:”Christine Eng”
 Occupation: “Student” [:HAS_STUDENT] Module
 ID:”LSM3241”
 Name:”Bioinformatics and Biocomputing” [:HAS_TA] Person
 Name:”Hu Yongli”
 Occupation: “Student” Sentence
 Sentence:”Thank you!” !31

Add a comment

Related presentations

Related pages

What is a Graph Database? A Property Graph Model Intro

Learn the basics of a graph database in general – and Neo4j in particular – in this introduction for database developers of all levels and backgrounds.
Read more

An introduction to graph databases | Information Age

Every type of database is a metaphor for the arrangement of information. The earliest mainframe databases arranged their contents in a simple, tree-like ...
Read more

Introduction to Graph Databases and Neo4j | Pluralsight

This course introduces the audience to graph databases and the Neo4j graph database product.
Read more

PHP and Neo4j: Introduction to Graph Databases - SitePoint

Learn about Graph Databases like Neo4j and prepare for the continuation of this series - a real world example of PHP+Neo4j use.
Read more

Introduction to Graph Databases | Data Exposed | Channel 9

What does this mean? Subscriptions allow us send you email notifications when new content is added. You need to be signed in to Channel 9 to use ...
Read more

Introduction to Graph Databases - YouTube

Neo Technology CEO Emil Eifrem provides a fast paced introduction to NOSQL, graph databases, and Neo4j, the world's leading graph database.
Read more

Introduction To Graph Databases | LearnComputer

Have you heard about Graph Databases? They are a new way of storing data that helps to show relationships between things or people instead of the traditional
Read more

Graph Databases, published by O'Reilly Media

Graph Databases, the definitive book on graph databases, written by Ian Robinson, Jim Webber and Emil Eifrem, and published by O'Reilly Media.
Read more