假设我想将新边合并到两个相邻节点之间的图中(以便在操作之后,可以说相关边加倍)。
我有 graph.cypher.execute(<some query>)
返回的以下记录:
| p
---+----------------------------
1 | (:A)-[:r]->(:B)-[:r]->(:C)
现在我想将边缘 (A,B) 和 (B,C) 加倍。为此我写了这段代码:
for record in graph.cypher.execute(<some query>):
for rel in record[0]:
self.graph.cypher.execute("MERGE "+str(self.graph.node(rel.start_node.ref))+"-[:new]->"+str(self.graph.node(rel.end_node.ref)))
但是,我没有得到现有节点之间的新边,而是得到了总共 4 个新节点的两个新关系,因为显然 NEO4J 不解释 str(self.graph.node(rel.start_node.ref))
和str(self.graph.node(rel.end_node.ref))
引用图中的现有节点。我该如何解决这个问题?
最佳答案
self.graph.create(rel(r.start_node, "new", r.end_node))
做到了。
需要from py2neo import rel
关于python - py2neo 在现有节点之间建立新的边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36057791/