繁体   English   中英

py2neo graph.merge()与Cypher MERGE的行为有何不同?

[英]py2neo graph.merge() behaves differently from Cypher MERGE?

因此,对于空数据库MERGE (N1:A {name:"A"})-[:r]->(N2:B {name:"B"})将创建两个节点N1N2 ,其边缘为r他们。 但是下面的python代码没有这样做......但为什么呢? 不应该吗?

from py2neo import Graph, authenticate, rel, Node

graph = Graph()

# set up authentication parameters
authenticate("localhost:7474", <user>, <password>)

# clear the data base
graph.delete_all()

graph.merge(rel(Node("A" , name="A"), "r", Node("B" , name="B")))

运行该脚本会导致数据库仍为空。 为什么这样,如何在不使用graph.cypher.execute("MERGE ...")情况下从py2neo获取Cypher合并行为?

在Py2neo中, graph.merge通过label和(可选)属性匹配或创建单个节点,您希望在整个模式(节点,关系,其他节点)上进行MERGE。

您在Cypher MERGE语句中使用的模式似乎在Cypher之外的Py2neo中不受支持。

这是一个关于如何合并两个节点的关系的示例。

from py2neo import Graph, authenticate, Relationship, Node

server = "localhost:7474"

# set up authentication parameters
authenticate(server, <user>, <password>)

graph = Graph("{0}/db/data".format(server))

# merge nodes and relationship
node1 = Node("A", name="A")
node2 = Node("B", name="B")
node1_vs_node2 = Relationship(node1, "r", node2)
graph.merge(node1_vs_node2)

结果是: 合并后的节点A和B相关

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM