Neo4j将节点与关系合并

时间:2015-07-05 22:38:51

标签: neo4j cypher

我有一个问题,我如何合并文档(Doc1,Doc2和Doc3)的节点,以获得漂亮的3个开始模式。

for index, row in import_ds.iterrows():
     ind = ind+1
     graph.cypher.execute("MERGE (Document:Document"+str(fnum)+" {Document:\"Doc"+str(fnum)+"\"})")
     graph.cypher.execute("MERGE (Type:Type {Type:\""+str(row['type'])+"\"})<-[:HAS_TYPE]-(Word:Word {Word:\""+str(row['token_low'])+"\"})-[:IS_IN]->(Document:Document"+str(fnum)+" {Document:\"Doc"+str(fnum)+"\"})")

(WordType)<-[:HAS_TYPE]-(Word)-[:IS_IN]->(Document) http://www.yottalabs.co.uk/ss.png
[code output - Neo4j browser][1]

1 个答案:

答案 0 :(得分:0)

  1. 你应该使用参数,而不是字符串替换
  2. merge尝试查找整个路径,如果不是,则创建整个路径
  3. 通常先将节点合并到rels:

    MERGE (type:Type {Type: {type}})
    MERGE (word:Word {Word:{token_low}})
    MERGE (document:Document {Document:{doc}})
    MERGE (type)<-[:HAS_TYPE]-(word)
    MERGE (word)-[:IS_IN]->(document)
    

    合并文档节点

    上的数据
    MERGE (document:Document {Document:{doc}})
    SET document.foo = {new_data}.foo, document.bar = {param_bar}