簡體   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