问题描述
如何执行 shortestPath()
和 allShortestPaths()
在py2neo中?
How do I perform the functions of shortestPath()
and allShortestPaths()
in py2neo?
在Cypher中,我将执行以下操作:
In Cypher, I'd execute something like:
START beginning=node(4), end=node(452)
MATCH p = shortestPath(beginning-[*..500]-end)
RETURN p
我已经尝试过我认为是等效的方法(如下),但这是行不通的(这些关系在cypher中有效,并且node_ *对象确实是正确的节点
I've tried what I thought was the equivalent (below), but this doesn't work (these relationships work in cypher, and the node_* objects are indeed the correct nodes
>>> rels = list(graph_db.match(start_node=node_4, end_node=node_452))
>>> rels
[]
推荐答案
我不想窃取jjaderberg的评论,但是这里是如何使用py2neo运行Cypher查询的方法.据我所知,没有实现图形算法.
I don't want to steal jjaderberg's comment but here is how you could run your Cypher query with py2neo. As far as I know graph algorithms are not implemented.
query_string = "START beginning=node(4), end=node(452)
MATCH p = shortestPath(beginning-[*..500]-end)
RETURN p"
result = neo4j.CypherQuery(graph_db, query_string).execute()
for r in result:
print type(r) # r is a py2neo.util.Record object
print type(r.p) # p is a py2neo.neo4j.Path object
然后,您可以按照以下说明从路径中获得所需的内容: http://book .py2neo.org/en/latest/paths/
You can then get what you need from your path as described here: http://book.py2neo.org/en/latest/paths/
这篇关于py2neo中的密码查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!