Neo 4 J
Neo 4 J
net/publication/348098103
CITATIONS READS
0 2,640
1 author:
Bibhuti Regmi
Asian Institute of Technology
2 PUBLICATIONS 1 CITATION
SEE PROFILE
All content following this page was uploaded by Bibhuti Regmi on 01 January 2021.
Presented by:
Bibhuti Regmi
What is graph database?
A graph database is
essentially a collection of
nodes and edges.
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.
Cypher – A Next-Generation Query Language
● Cypher was based on
the power of SQL, but
optimized specifically for
graphs.
● The syntax is concise
and straightforward,
allowing users to easily
write all the normal
CRUD operations in a
simple and maintainable
way.
Nodes: Cypher uses ASCII-Art to represent patterns. We surround nodes
with parentheses which look like circles (p:Person).
Relationships: Relationships are basically an arrow --> between two nodes.
Additional information can be placed in square brackets inside of the arrow.
Data Storage No support for connected data at the Fast transaction in connected data
database level.
Data Modeling Data model not suitable for Flexible, "whiteboard-friendly" data model
enterprise architectures as wide allows for fine-grained control of data
columns and document stores do architecture
not offer control at the design level.
Query Performance No graph processing capability for Native graph processing ensures zero
data relationships latency and real-time performance
Query Language No query constructs exist to express Cypher: native graph query language
data relationships.
Sample demo: Creating a music database that
contains band names and their albums.
Step 1. Create a node: Strapping Young Lad
The first band will be called Strapping Young Lad. So we will create an Artist node and
call it Strapping Young Lad.
Artist: is label
Node: has property name, value of property: Strapping Young Lad
a: variable name, useful if we need to refer to it later in the statement
1.1. Create and Display node
The CREATE statement creates the node but it doesn't display the node.
To display the node, you need to follow it up with a RETURN statement.
Let's create another node. This time it will be the name of an album. But this time we'll
follow it up with a RETURN statement.
● MATCH statement : find the two nodes to create the relationship between
● There could be many nodes with an Artist or Album label so we narrow it down to
just those nodes we're interested in. In this case we use “Name”
● Relationship is created using CREATE. The relationship is established by using an
ASCII-code pattern, with an arrow indicating the direction of the relationship:
(a)-[r:RELEASED]->(b).
● We give the relationship a variable name of r and give the relationship a type of
RELEASED (as in "this band released this album"). The relationship's type is
analogous to a node's label.
Retrieve a node
MATCH (p:Person {Name: "Devin Townsend"})
RETURN p
is equivalent to
If we wanted to find out which artist released the album called Heavy as a Really Heavy
Thing, we could use the following query:
MATCH (a:Artist)-[:RELEASED]->(b:Album)
WHERE b.Name = "Heavy as a Really Heavy Thing"
RETURN a
It matches all artists that released an album that had a name of Heavy as a Really Heavy
Thing
Update
MATCH (n)
WHERE n.name = "Killers"
SET n.price = "$20"
Delete
Delete a node
MATCH (a:Album {Name: "Killers"}) DELETE a
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.
Displaying stalls visited by nepali people and have
given good rating
Query:
Match (cus:Customer)-[:Reviewed]->(s:Stall),
(s)-[:HasMenu]-(m:Menu),
(cus)-[:gaveReview]->(n:Review)
where cus.nationality='Nepali'
and
(n.taste+n.affordability+n.availability+n.behaviour+n.hygiene)/5
>3
return s,m,count(cus)as customernumber
order by customernumber desc
Displaying stalls visited by nepali people and have given good rating
RDBMS NEO4J
select s.stall_name, m.description from Match
stall s (cus:Customer)-[:Reviewed]->(s:Stall),
Inner join review r (s)-[:HasMenu]-(m:Menu),
On s.st_id = r.stall_id (cus)-[:gaveReview]->(n:Review)
Inner join Givesreview gr with
On r.r_id=g.r_id s,m,cus,(n.taste+n.affordability+n.avail
Inner join customer c ability+n.behaviour+n.hygiene)/5 as
On gr.c_id = c.c_id reviewfinal
Inner join menu m where cus.nationality='Nepali'
on s.stall_id=m.stall_id and reviewfinal>3
Where return s,m,count(cus)as
(r.taste+r.affordability+r.availability+r. customernumber
.behaviour+r.hygiene)/5)>3 order by customernumber desc
And c.nationality=’Nepalese’)
Thank you