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.
Gen AI in Business - Global Trends Report 2024.pdf
Introduction to Graph Database
1. Introduction to
Graph Database
!
Eric C.Y. LEE
eric@nus.edu.sg
eric@eric.lv
National University of Singapore
February, 2014
2. Outline
•
Relational Database v.s. Graph Database
•
Design the Database in Graph Architecture
•
Basic Usage of Neo4j
•
Cypher Query Language
•
Business application
!2
3. 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
4. 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
5. Modelling a K-pop Database
All materials for database construction,
we can find in these wikipedia pages.
!5
6. 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
7. 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?
8. 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?
10. 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
27. 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
28. 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
30. 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
31. [: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