python - py2neo 在现有节点之间建立新的边

标签 python neo4j cypher py2neo edges

假设我想将新边合并到两个相邻节点之间的图中(以便在操作之后,可以说相关边加倍)。

我有 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/

相关文章:

python - 生成特定 id 值的 json 输出时出错

python Pandas : Using apply() to subtract a value from an array

neo4j - Cypher-QueryDSL : 'My "Q"classes cannot be resolved' compile error (e. g。 Q人)

Neo4j 加载 CSV 错误 : unknown protocol: c

python - 如何从python获取密码查询的执行时间?

python - Spyne、TLS 和服务器到客户端的请求

python - 我可以用 sum() 加入列表吗?

java - Neo4j 无法在 Centos 上启动

indexing - Neo4j 数据库索引

neo4j - cypher 中的嵌套 has_many 关系