Neo4j:加入neo4j图中的现有节点

时间:2016-03-07 06:12:04

标签: neo4j cypher py2neo

问题陈述: 添加两个输入节点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

我已经解释了上面的问题。我怎样才能实现它。

1 个答案:

答案 0 :(得分:3)

这将涵盖所有四点,附加点为:

如果n1和n2不存在,则创建n1和n2并与edge [:rel]连接。

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@android:color/transparent"> <!-- ripple color -->

    <item android:drawable="your color"/> <!-- normal color -->

</ripple>
相关问题