如何解决gds.alpha.shortestPath.stream 中的 NodeProperties
Neo4j 数据图科学库有一个最短路径算法 (https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/shortest-path/)。以下序列是适用于我的项目的示例算法:
MATCH (start:Loc {name: 'A'}),(end:Loc {name: 'F'})
CALL gds.alpha.shortestPath.stream({
nodeProjection: 'Loc',relationshipProjection: {
ROAD: {
type: 'ROAD',properties: 'cost',orientation: 'UNDIRECTED'
}
},startNode: start,endNode: end,relationshipWeightProperty: 'cost'
})
YIELD nodeId,cost
RETURN gds.util.asNode(nodeId).name AS name,cost
问题是在找到最短路径之前必须过滤图。每个节点都有一个名为 currentWeather 的属性,并且每个带有 currentWeather = "good" 的节点都是最短路径的有效节点。
是否可以使用例如nodeProperties 过滤currentWeather = "good"? 如果这不起作用,您将如何为 currentWeather = "good" 的节点创建子图或过滤器?
非常感谢
解决方法
您需要使用密码投影来过滤子图。
MATCH (start:Loc {name: 'A'}),(end:Loc {name: 'F'})
CALL gds.alpha.shortestPath.stream({
nodeQuery: 'Match (l:Loc) Where l.currentWeather =
"Good" return id(l) as id',relationshipQuery: 'match (l:Loc)-[r:ROAD]-(t:Loc) return id(l) as source,id(t) as target,r.cost as cost',startNode: start,endNode: end,relationshipWeightProperty: 'cost'
})
YIELD nodeId,cost
RETURN gds.util.asNode(nodeId).name AS name,cost
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。