本文介绍了如何在CSV中指定关系类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSV文件,其数据如下:

I have a CSV file with data like:

ID,Name,Role,Project
1,James,Owner,TST
2,Ed,Assistant,TST
3,Jack,Manager,TST

,并希望创建在其中指定与项目的关系的人员.我试图这样做:

and want to create people whose relationships to the project are therein specified. I attempted to do it like this:

load csv from 'file:/../x.csv' as line
match (p:Project {code: line[3]})
create (n:Individual {name: line[1]})-[r:line[2]]->(p);

但它用以下命令拒绝:

,因为在关系创建中似乎无法取消引用line.如果我对其进行硬编码:

as it can't seem to dereference line in the relationship creation. if I hard-code that it works:

load csv from 'file:/../x.csv' as line
match (p:Project {code: line[3]})
create (n:Individual {name: line[1]})-[r:WORKSFOR]->(p);

那我怎么做参考呢?

推荐答案

现在您不能,因为这是结构信息.

Right now you can't as this is structural information.

为此可以使用 neo4j导入工具.

或者像您手动指定的那样,或者使用以下解决方法:

Or specify it manually as you did, or use this workaround:

load csv with headers from 'file:/../x.csv' as line
match (p:Project {code: line.Project})
create (n:Individual {name: lineName})
foreach (x in case line.Role when "Owner" then [1] else [] end |
  create (n)-[r:Owner]->(p)
)
foreach (x in case line.Role when "Assistant" then [1] else [] end |
  create (n)-[Assistant]->(p)
)
foreach (x in case line.Role when "Manager" then [1] else [] end |
  create (n)-[r:Manager]->(p)
)

这篇关于如何在CSV中指定关系类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 19:35
查看更多