问题陈述:添加两个输入节点 n1 和 n2,边缘定向 n1-[:rel]->n2
1. if n1-[:rel]->n2 exists ignore
2. if n1 and n2 exists but not with [:rel]
create a new relationship edge between the existing nodes
3. if n1 doesnt exist
create n1 and join n1 and existing n2 with edge [:rel]
4. if n2 doesnt exist
create n2 and join n2 and existing n1 with edge [:rel]
查询:
INSERT_QUERY = ''' FOREACH(t IN {term_mod_pair_list}|
MERGE(tt:target_Word {type:'target_term',word:t[0]['word'],pos:t[0]['tag']})-
[:MODIFIER]->(mod:mod_Word {type:'a-mod',word:t[1]['word'],pos:t[0]['tag']}) ) '''
我发现合并正在创建重复的节点,在一些发现之后,我看到合并与确切的模式匹配。所以如果n1-[:rel]->n2
存在,新添加的关系n1-[:rel]->n3
将创建另一个新节点 N1
我已经在上面解释了我的问题。 我怎样才能实现它。
这将涵盖所有四点,并附加以下几点:
如果 n1 和 n2不存在,请创建 n1 和 n2 并使用边 [:rel] 连接。
MERGE (n1:Label {unique_prop: "unique_value"})
MERGE (n2:Label {unique_prop: "unique_value"})
MERGE (n1)-[:rel]->(n2);