py2neo公司图形.合并()的行为与Cypher MERGE不同?

2024-04-25 19:36:35 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,对于空数据库,MERGE (N1:A {name:"A"})-[:r]->(N2:B {name:"B"})将创建两个节点N1和{},它们之间有一个边缘{}。但是,下面的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合并行为?在


Tags: 代码namefrom数据库node节点merge边缘
2条回答

在Py2neo中,^{}通过标签和(可选)属性匹配或创建一个节点,您希望在其中合并整个模式(节点、关系、其他节点)。在

CypherMERGE语句使用的模式似乎在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)

结果是: Nodes A and B related after a merge

相关问题 更多 >