2. Neo4j
● Neo4j is an open-source, NoSQL, native graph database that provides an
ACID-compliant transactional backend for your applications.
● referred to as a native graph database because it efficiently implements the
property graph model down to the storage level.
● It is highly scalable and schema-free.
● It's world most popular graph database management system.
● Neo4j is implemented in Java language and it can be accessed by other
language using Cypher Query Language (CQL) through a transactional HTTP
endpoint.
● The database uses pointers to navigate and traverse the graph.
3. Use cases
● Fraud detection and analytics
● Network and database infrastructure monitoring
● Recommendation engines
● Social networks
● Knowledge graph
● Identity and access management
● Privacy and risk compliance
● Master data management
Over 300 commercial customers and over 750 startups use Neo4j.
Flagship customers include eBay, Walmart, Cisco, Citibank, ING, UBS, HP,
Microsoft, IBM, Thomson Reuters, Amadeus Travel, Caterpillar, Volvo and many
more.
5. Sample queries: Cafeteria Rating
Step 1. Create a node: Stall
● CREATE (a:Stall {Name: "Western food", description: "Get varieties of western food
here", location: "SU Snack Bar"})
return a
Similarly create nodes:
● Menu
● Review
● Customer
6. Step 2: Creating relationship between nodes
Creating relation between Customer and stall
Match(c:Customer),(b:Stall)
where c.name="Bibhuti Regmi" and b.Name="Nepalese food"
Create (c)-[r:Reviewed]->(b)
Return r
7. Retrieve a node
MATCH (c:Customer {name: "Bibhuti Regmi"})
RETURN p
is equivalent to
SELECT * FROM Customer
WHERE name = "Bibhuti Regmi";
8. Update
MATCH (n)
WHERE n.name = "Bibhuti Regmi"
SET n.age = "16"
MATCH (n:Customer)
{Name: "Bibhuti Regmi"})
Delete n
Delete
9. Functionality
➢ A platform to view cafeteria’s
○ Stall ratings and comments on each stall.
○ Menu
➢ Build a platform to share their rating with other
customers and also with the stall owners through which
they can know their pros and cons.
➢ Get recommendation on which stall to eat
10. Analysis Queries in NEO4j
1. Check all the ratings provided by a particular customer
MATCH (c:Customer)-[:Reviewed]->(s:Stall),
(c)-[:gaveReview]->(r:Review)
WHERE c.name='George Miller'
RETURN c,r,s
2. Displaying nationality of customers who provided rating to a particular stall
Match (cus:Customer)-[:Reviewed]->(s:Stall)
where s.Name="Nepalese food"
Return cus.nationality,count(*)
Fig: Ratings provided by George
Output of query 2
11. continued..
3. View Avg Rating of stall based on categories and average rating of each category
MATCH (s:Stall)-[:HasReview]->(n:Review)
RETURN s,avg(n.taste) as avgtaste, avg(n.behaviour) as avgbehaviour,avg(n.affordability) as avgaffordability,
avg(n.availability)as avgavialability,avg(n.hygiene) as
avghygiene,avg((n.taste+n.affordability+n.availability+n.behaviour+n.hygiene)/5) as reviewfinal
12. ● View the ratings for different stalls in cafeteria or snack bar.
● Know the rating which other customers have given based on the categories such as
taste or hygiene and so on.
● Share experiences in the form of comments or ratings
Implemented Using RDBMS
Additional Implementation using Neo4j
● Get recommendation on which stall to eat(Based on nationality and rating)
13. Use case: Recommendation system
Neo4j is used in recommendation system. So as an extension of our project
cafeteria rating, I added a new functionality that would suit this data model:-
recommending stalls to user based on nationality and rating of the stall.
For simplicity purpose I have just implemented nationality as a recommendation
parameter.
Eg: If a student is Nepali, then the stalls visited by nepali people and have given
good rating will be recommended. A portion of this is implemented.
14. Fig: Table involved in project using RDBMS Fig: Neo4j equivalent
RDBMS Neo4j
15. RDBMS
select s.stall_name, m.description from
stall s
Inner join review r
On s.st_id = r.stall_id
Inner join Givesreview gr
On r.r_id=g.r_id
Inner join customer c
On gr.c_id = c.c_id
Inner join menu m
on s.stall_id=m.stall_id
Where
(r.taste+r.affordability+r.availability+r.
.behaviour+r.hygiene)/5)>3
And c.nationality=’Nepalese’)
NEO4J
MATCH (cus:Customer)-[:Reviewed]->(s:Stall),
(s)-[:HasMenu]-(m:Menu),
(cus)-[:gaveReview]->(n:Review)
WITH s, m, cus,
(n.taste+n.affordability+n.availability+n.behaviour+n.hygiene)/5
as reviewfinal
WHERE cus.nationality='Nepali'
and reviewfinal>3
RETURN s,m,count(cus) as customernumber
ORDER BY customernumber desc
Displaying stalls visited by nepali people and have given good rating
16. Displaying stalls visited by nepali people and have
given good rating
Match (cus:Customer)-[:Reviewed]->(s:Stall),
(s)-[:HasMenu]-(m:Menu),
(cus)-[:gaveReview]->(n:Review)
With s, m, cus,
(n.taste+n.affordability+n.availability+n.behaviour
+n.hygiene)/5 as reviewfinal
where cus.nationality='Nepali'
and reviewfinal>3
Return s,m,count(cus) as customernumber
order by customernumber desc Fig: Output of the Query