如何解决由gds.alpha.kShortestPaths.stream
我使用Neo4j 4.0.2运行gds.alpha.kShortestPaths.stream
。该算法产生一条路径。
该路径具有以NEXT
关系连接的节点。我需要在图中找到连接路径中节点的实际关系。我根据知道的路径长度提出了一个混乱的查询:
...
YIELD path
with nodes(path) as nodes with nodes[0] as n0,nodes[1] as n1,nodes[2] as n2,nodes[3] as n3
match (n0)-[r1]-(n1)
match (n1)-[r2]-(n2)
match (n2)-[r3]-(n3)
return n0,n1,n2,n3,r1,r2,r3
显然,该解决方案是不够的,我在此处发布此解决方案的唯一原因是为了说明我对任何长度的路径都需要执行的操作。
谢谢
解决方法
您可以通过以下方式以编程方式执行此操作:
YIELD index,path
WITH index,nodes(path) as nodes
WITH index,nodes,size(nodes) as number_of_nodes
UNWIND range(0,number_of_nodes - 2) as start
WITH index,nodes[start] as start_node,nodes[start + 1] as end_node
MATCH (start_node)-[r:NEXT]->(end_node)
RETURN index,start_node,r,end_node
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。