简体   繁体   English

如何显示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:
--------------------

I have a CSV file containing a list of nodes where each line denotes a relationship of node at line[0] with every other list of nodes line[2],line[2],line[3].....line[4500] in that line 我有一个CSV文件,其中包含节点列表,其中每行表示第[0]行的节点与其他所有节点列表的关系line [2],line [2],line [3] ..... line [ 4500]

Ex. 防爆。 Sample Input File: 样本输入文件:

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)

Please note (line 1),(line 2) etc. is not present in actual CSV file. 请注意,实际的CSV文件中没有(第1行),(第2行)等。 Here I've named them just for sake of explanation. 在这里,我仅出于解释目的命名它们。

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....

what i am trying to do is I want to show a graph in Neo4j depicting the suggested friend relationship among each nodes. 我想做的是要在Neo4j中显示一个图表,描述每个节点之间建议的朋友关系。

what I cannot figure out is how to iterate the whole csv file as well as capture the relationship among each nodes on each line of csv file. 我无法弄清的是如何迭代整个csv文件以及如何捕获csv文件每一行上每个节点之间的关系。

Please Note:[I have attached the expected hand drawn output of a sample input file.] 请注意:[我已附上了示例输入文件的预期手绘输出。]

Link to Comma separated value file containing the friends 链接到包含朋友的逗号分隔值文件

Link to Image 链接到图片

First, save your CSV file into Neo4j import directory (take a look in Neo4j files location docs ). 首先,将CSV文件保存到Neo4j导入目录中(在Neo4j文件位置docs中查看)。 After, use Neo4j LOAD CSV statement to import your data. 之后,使用Neo4j LOAD CSV语句导入数据。 The script I used to reproduce your desired output is as follow: 我用来重现所需输出的脚本如下:

// 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)

The output considering your sample CSV file will be: 考虑您的示例CSV文件的输出将是:

产量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM