edges - Neo4j. Create graph from two tables -


i have 2 csv files nodes , edges.

nodes:  big, adjective arm, noun face, noun, best, adjective  edges: big, face best, friend face, arm 

i want create graph relationships edges , add nodes group: noun , adjective.

i use command create relationships:

load csv 'file:copperfield_edges.csv' line merge (g:g {word1 : line[0]}) line, g merge (j:j {word2 : line[1]}) g,j merge (g)-[:from_to]->(j); 

but in case each word appears 2 times. how can unique relationships of words , add noun , adjective group?

i want http://joxi.ru/1a5qx6mh6lz1ae

you're assignen g label nodes in first column , j label in second column. since have 1 identifier (e.g. big, face) every word, use 1 label all, e.g. word try following:

load csv 'file:copperfield_edges.csv' line  merge (g:word {word : line[0]})  merge (j:word {word : line[1]})  merge (g)-[:from_to]->(j); 

based on nodes csv file, can assign additional label indicating if word adjective or noun:

load csv 'file:nodes.csv' line merge (w:word {word: line[0]}) foreach (n in (case when line[1] = "adjective" [1] else [] end) |   set w :adjective  ) foreach (n in (case when line[1] = "nound" [1] else [] end) |   set w :noun  ) 

since cannot set labels dynamically, i've had use foreach trick documented @ http://www.markhneedham.com/blog/2014/06/17/neo4j-load-csv-handling-conditionals/

if graph more handful of nodes consider using creating index before running load csv:

create index on :word(word) 

Comments