py2neo graph.merge() 的行为与 Cypher MERGE 不同?
py2neo graph.merge() behaves differently from Cypher MERGE?
因此,对于空数据库 MERGE (N1:A {name:"A"})-[:r]->(N2:B {name:"B"})
将创建两个节点 N1
和 N2
,它们之间有一条边 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
通过标签和(可选)属性 匹配或创建单个节点,您希望在整个模式(节点、关系、其他节点)上合并。
您用于 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)
结果是:
因此,对于空数据库 MERGE (N1:A {name:"A"})-[:r]->(N2:B {name:"B"})
将创建两个节点 N1
和 N2
,它们之间有一条边 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
通过标签和(可选)属性 匹配或创建单个节点,您希望在整个模式(节点、关系、其他节点)上合并。
您用于 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)
结果是: