简体   繁体   English

在Neo4j中连接相同节点的关系

[英]Relationship that connect the same node in Neo4j

I will try to be very succinct with my problem. 我会尽量简洁地表达我的问题。 I have the node Person that I loaded using a .csv file and I have another .csv file to be loaded - person_speaks_language_0.csv 我有使用.csv文件加载的节点Person,还有另一个要加载的.csv文件-person_speaks_language_0.csv

(got this header: idPerson|languagePSL ) (获得此标头:idPerson | languagePSL)

How can I relate this? 我该如何关联? How can I create this relationship? 如何建立这种关系?

Grabbing another example, that is very similar to the previous one, and that I can't solve. 抓住另一个例子,它与前面的例子非常相似,我无法解决。 I have the Comment node loaded in Neo4j an I need to load another .csv file, that file is - comment_replyOf_comment_0.csv 我在Neo4j中加载了Comment节点,我需要加载另一个.csv文件,该文件是-comment_replyOf_comment_0.csv

(got his header: idComment|idComment) (获得标题:idComment | idComment)

How can I load this file? 如何加载此文件? How can I connect a relation that goes "in and out" from the same node - that connects the same node? 如何连接从同一节点“进出”的关系-连接同一节点?

For the first example. 对于第一个示例。 there is 2 options. 有2个选项。

If you want Language to be a separate node, try this cypher: 如果您希望语言成为单独的节点,请尝试以下密码:

LOAD CSV FROM 'person_speaks_language_0.csv' AS line
MATCH (p:Person) 
WHERE p.id=line[0]
MERGE (p)-[r:Speaks]->(l:Language { name: line[1])})
RETURN p, l, r

Or, probably, better option 或者,也许是更好的选择

LOAD CSV FROM 'person_speaks_language_0.csv' AS line
MERGE (p:Person { id:line[0] })-[r:Speaks]->(l:Language { name: line[1]) })
RETURN p, l, r

If you want Language to be a property, try this: 如果您希望语言成为属性,请尝试以下操作:

LOAD CSV FROM 'person_speaks_language_0.csv' AS line
MERGE (p { id:line[0], language:line[1] })
RETURN p

The RETURN statement is optional and you don't want to include it for a big csv files (although it could be useful for debug). RETURN语句是可选的,并且您不希望将其包含在大型csv文件中(尽管它对于调试很有用)。

For the second example, try this: 对于第二个示例,请尝试以下操作:

LOAD CSV FROM 'comment_replyOf_comment_0.csv' AS line
MERGE (c1:Comment { id:line[0] })-[r:Commented]->(c2:Comment { id:line[1]) })
RETURN c1, r, c2

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

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