如何在neo4j中显示关系

How to show the relationship in neo4j

I've attached the sample input comma separated value file and a hand drawn image showing my expected output down below.

Problem Description:
--------------------

我有一个包含节点列表的 CSV 文件,其中每一行表示第 [0] 行的节点与每个其他节点列表第 [2]、第 [2]、第 [3] 行的关系。 ...行[4500]在那行

例如。示例输入文件:

0,1,2,3 (line 1)  
1,2 (line 2)    
2,4 (line 3)  
3,7,19 (line 4)  
10,4,5,11 (line 5)

请注意(第 1 行)、(第 2 行)等在实际 CSV 文件中不存在。在这里我给它们命名只是为了解释。

for line 1 (Let 'line') node at 
line[0] i.e. "0" has a directed "friends" relationship with 
nodes at line[2] i.e "1" 
nodes at line[4], i,e."2"
nodes at line[6], i,e."3"

similarly again for line 2 (Let 'line') node at 
line[0] i.e. "1" has a directed "friends" relationship with 
nodes at line[2] i.e "2" 

similarly again for line 3(Let 'line')  node at 
line[0] i.e. "2" has a directed "friends" relationship with 
nodes at line[2] i.e "4" 


similarly again for line 4(Let 'line')  node at 
line[0] i.e. "3" has a directed "friends" relationship with 
nodes at line[2] i.e "7" 
nodes at line[4], i,e."19"

and so on....

我想做的是在 Neo4j 中显示一个图表,描述每个节点之间建议的朋友关系。

我想不通的是如何迭代整个 csv 文件以及捕获 csv[=29] 的每一行上每个节点之间的关系=] 文件.

请注意:[我附上了示例输入文件的预期手绘输出。]

Link to Comma separated value file containing the friends

Link to Image

首先,将您的 CSV 文件保存到 Neo4j 导入目录(查看 Neo4j files location docs). After, use Neo4j LOAD CSV 语句以导入您的数据。我用来重现您想要的输出的脚本如下:

// Load the csv file
load csv from "file:///friends.csv" as line
// calculate the indexes from the second column to the last
with line, range(1, size(line) - 1) as indexes
// merge (create or assign) the node from first column (0,1,2,3,10)
merge(a:Node{id:line[0]})
// pass 'a', 'indexes' and 'line' to the next context
with a, indexes, line
// unwind the indexes into single index per row
unwind indexes as index
// merge (create or assign) the node from other columns
merge(b:Node{id:line[index]})
// merge the relationship between a and b
merge(a)-[:FRIEND_OF]->(b)

考虑到您的示例 CSV 文件的输出将是: