Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 检查neo4j数据库中是否存在关系,该关系是否不起作用_Python_Neo4j_Py2neo - Fatal编程技术网

Python 检查neo4j数据库中是否存在关系,该关系是否不起作用

Python 检查neo4j数据库中是否存在关系,该关系是否不起作用,python,neo4j,py2neo,Python,Neo4j,Py2neo,当我使用如下所示的事务创建两个节点及其关系时,我能够使用graph.match()检查关系是否存在 from py2neo import Graph, Node, Relationship, NodeSelector g = Graph('http://localhost:7474/db/data', user='uname', password='pass') tx = g.begin() a = Node("Person", name="Alice") tx.create(a) b =

当我使用如下所示的事务创建两个节点及其关系时,我能够使用graph.match()检查关系是否存在

from py2neo import Graph, Node, Relationship, NodeSelector
g = Graph('http://localhost:7474/db/data', user='uname', password='pass')

tx = g.begin()

a = Node("Person", name="Alice")
tx.create(a)

b = Node("Person", name="Bob")
tx.create(b)

ab = Relationship(a, "KNOWS", b)
tx.create(ab)

tx.commit()

relations = g.match(start_node=a, rel_type="KNOWS", end_node=b)
list(relations) // this returns [(alice)-[:KNOWS]->(bob)]
后来,我尝试将start_节点和end_节点传递给graph.match()函数,如下所示,但它不起作用,而是返回了错误:关系匹配端点的节点必须绑定

d = Node("Person", name="Alice")
e = Node("Person", name="Bob")
relations = g.match(start_node=d, rel_type="KNOWS", end_node=e)
list(relations) // this returns error " Nodes for relationship match end points must be bound "

获取Alice和Bob之间的现有关系的上述代码有什么问题

d = Node("Person", name="Alice")
e = Node("Person", name="Bob")
relations = g.match(start_node=d, rel_type="KNOWS", end_node=e)
list(relations) // this returns error " Nodes for relationship match end points must be bound "
节点用于创建新节点,如注释中提到的@InverseFalcon。它并没有指向服务器中的实际节点。在创建节点(我问题中的第一组代码)时检查关系是有效的,因为创建节点后,节点类返回节点对象

以下代码适用于我的项目

d = g.run("MATCH (a:Person) WHERE a.name={b} RETURN a", b="Alice")
list_d = list(d)
start_node = list_d[0]['a']
e = g.run("MATCH (a:Person) WHERE a.name={b} RETURN a", b="Bob")
list_e = list(e)
end_node = list_e[0]['a']
relations = g.match(start_node=start_node, rel_type="KNOWS", end_node=end_node)

Node()
不是用于创建节点吗?我不确定你的代码是否与图中现有的节点匹配。在你提出问题后,我开始思考,并尝试了一些有效的方法。谢谢