简体   繁体   English

密码学-Neo4j

[英]FOREACH in cypher - neo4j

I am very new to CYPHER QUERY LANGUAGE AND i am working on relationships between nodes. 我对CYPHER QUERY语言非常陌生 ,我正在研究节点之间的关系。 I have a CSV file of table containing multiple columns and 1000 rows. 我有一个包含多列和1000行的表格的CSV文件。 Template of my table is : 我的表格模板是:

cdrType    ANUMBER    BNUMBER    DUARTION    
2          123        456        10 
2          890        456        5 
2          123        666        2 
2          123        709        7 
2          345        789        20 

I have used these commands to create nodes and property keys. 我已经使用这些命令来创建节点和属性键。

LOAD CSV WITH HEADERS FROM "file:///2.csv" AS ROW
CREATE (:ANUMBER {aNumber:ROW.aNumber} ),
CREATE (:BNUMBER {bNumber:ROW.bNumber} )

Now I need to create relation between all rows in the table and I think FOREACH loop is best in my case. 现在,我需要在表中的所有行之间创建关系,并且我认为FOREACH循环最适合我。 I created this query but it gives me an error. 我创建了此查询,但它给了我一个错误。 Query is : 查询是:

MATCH (a:ANUMBER),(b:BNUMBER)
FOREACH(i in RANGE(0, length(ANUMBER)) | 
    CREATE UNIQUE (ANUMBER[i])-[s:CALLED]->(BNUMBER[i]))

and the error is : 错误是:

Invalid input '[': expected an identifier character, whitespace, NodeLabel, a property map, ')' or a relationship pattern (line 3, column 29 (offset: 100)) " CREATE UNIQUE (a:ANUMBER[i])-[s:CALLED]->(b:BNUMBER[i]))" 无效的输入'[':预期为标识符字符,空格,NodeLabel,属性映射'')或关系模式(第3行,第29列(偏移量:100))“创建唯一(a:ANUMBER [i])- [s:CALLED]->(b:BNUMBER [i]))”

I need relation for every row. 我需要每一行的关系。 like in my case. 就我而言 123 - called -> 456 , 890 - called -> 456. So I need visual representation of this calling data that which number called which one. 123-称为-> 456,890-称为->456。因此,我需要可视化表示此调用数据,即哪个号码调用了哪个号码。 For this I need to create relation between all rows. 为此,我需要在所有行之间创建关系。

any one have idea how to solve this ? 有人知道如何解决这个问题吗?

What about : 关于什么 :

LOAD CSV WITH HEADERS FROM "file:///2.csv" AS ROW
CREATE (a:ANUMBER {aNumber:ROW.aNumber} )
CREATE (b:BNUMBER {bNumber:ROW.bNumber} )
MERGE (a)-[:CALLED]->(b);

It's not more complex than that imo 没有比这更复杂的imo

Hope this helps ! 希望这可以帮助 !

Regards, Tom 问候,汤姆

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

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