8.3 Graph solutions

Course subject(s) 8. Alternatives Neo4J

Introduction on Neo4j, a very specialised tool used to store and analyse graphs. Keep in mind, you should not run to your spreadsheet immediately, it is not always the best solution.

Sorry but there don't seem to be any downloads..

Subtitles (captions) in other languages than provided can be viewed at YouTube. Select your language in the CC-button of YouTube.

Commands used

Creating the movies:

LOAD CSV WITH HEADERS FROM

“file:/path/to/file/file.csv”

as row

CREATE (m:movie {name:row.movie})

A simple match command for the graph:

MATCH(n) return n

Creating the actors:

LOAD CSV WITH HEADERS FROM

“file:/path/to/file/file.csv”

as row

CREATE (a:actor {fullname:row.fullname})

Creating the links between movies and actors:

LOAD CSV WITH HEADERS FROM

“file:/path/to/file/file.csv”

as row

MATCH (a:actor {fullname:row.fullname})

MATCH (m:movie {name:row.movie})

CREATE (a-[:acted]->m)

Looking for a path of 2 hops from Bacon to another actor:

MATCH (b:actor {fullname:”Kevin Bacon”})-[*2]-(a:actor)

RETURN a.fullname

Looking for all unique actors with a path of 4 hops from Bacon:

MATCH (b:actor {fullname:”Kevin Bacon”})-[*4]-(a:actor)

RETURN distinct a.fullname

Looking for the shortestpath from Bacon to other actors (“0..” is added to include Kevin Bacon in the list):

MATCH p=shortestpath(

((b:actor {fullname:”Kevin Bacon”})-[*0..]-(a:actor))

)

RETURN a.fullname, length(p)

Looking for the shortestpath from Bacon to other actors and outputting the Bacon Number (“0..” is added to include Kevin Bacon in the list):

MATCH p=shortestpath(

((b:actor {fullname:”Kevin Bacon”})-[*0..]-(a:actor))

)

RETURN a.fullname, 1+length(p)/2

Creative Commons License
Data Analysis: Take it to the Max by TU Delft OpenCourseWare is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://ocw.tudelft.nl/courses/data-analysis-take-it-to-the-max/.
Back to top