通过匹配现有ID加载CSV文件并添加属性关系

时间:2019-05-01 12:34:28

标签: neo4j

我有一个图,其中包含标记为疾病的节点,它们具有唯一的id(cui)和关系Has_child,Has_descendant作为属性。我想加载CSV文件并通过匹配ID在关系上添加一些属性。

USING PERIODIC COMMIT 
LOAD CSV WITH HEADERS FROM 'file:///Descendant_distance.csv' AS line 
FIELDTERMINATOR '\t'
MERGE (d:Disease{id: line.CUI_SRC})
(n:Disease{id: line.CUI_DST})
 (d)-[r:HAS_CHILD|HAS_DESCENDANT]->(n)
 on match set 
    r.distance = line.DISTANCE,
    r.SAB = line.SAB;

我尝试了这个,对我来说,它应该可以工作,但是我有一个错误

    (Neo.ClientError.Statement.SyntaxError: Invalid input '(': expected whitespace, comment, a relationship pattern, ON, FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, ';' or end of input (line 5, column 1 (offset: 150))  "(n:Disease{id: line.CUI_DST})"

我希望最后我将在关系中添加2个属性,而不会影响/修改其余数据。 谁能帮我解决这个问题?

1 个答案:

答案 0 :(得分:1)

节点已经创建,因此您可以执行“匹配,设置”命令。

USING PERIODIC COMMIT  
LOAD CSV WITH HEADERS FROM 'file:///Descendant_distance.csv' AS line 
FIELDTERMINATOR '\t'
MATCH (d:Disease{id: line.CUI_SRC}), 
(n:Disease{id: line.CUI_DST}), 
(d)-[r:HAS_CHILD|HAS_DESCENDANT]->(n)
SET r.distance = line.DISTANCE,
    r.SAB = line.SAB;