Python py2neo在现有节点之间建立新边
假设我想将新的边合并到两个相邻节点之间的图中(这样,在操作之后,可以说有问题的边加倍) 我有Python py2neo在现有节点之间建立新边,python,neo4j,cypher,py2neo,edges,Python,Neo4j,Cypher,Py2neo,Edges,假设我想将新的边合并到两个相邻节点之间的图中(这样,在操作之后,可以说有问题的边加倍) 我有graph.cypher.execute()返回的以下记录: 现在我想把边(A,B)和(B,C)加倍。为此,我编写了以下代码: for record in graph.cypher.execute(<some query>): for rel in record[0]: self.graph.cypher.execute("MERGE "+str(self.gr
graph.cypher.execute()
返回的以下记录:
现在我想把边(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)))
用于graph.cypher.execute()中的记录:
对于记录[0]中的rel:
self.graph.cypher.execute(“MERGE”+str(self.graph.node(rel.start\u node.ref))+“-[:new]->”+str(self.graph.node(rel.end\u 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\u节点,“new”,r.end\u节点))做到了
需要py2neo导入rel中的
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)))