【问题标题】:neo4j cypher: find all paths with end-nodes that do not have a certain outgoing relationship?neo4j cypher:找到所有没有特定传出关系的端节点的路径?
【发布时间】:2013-07-04 14:20:44
【问题描述】:

我想使用 cypher 得到以下结果: “查找从节点 A 开始的所有路径,仅遵循属性“百分比”1 大于 50 且路径结尾是属性“类型”= 1 且路径结尾具有没有之前指定的进一步关系 (percentage>50 ...)"

1:出于性能原因,我正在考虑创建一个单独的关系类型“MY_RELATIONSHIP_50”)

到目前为止,我的 Cypher 工作正常:
start A = node(...)
match path = (A)-[rels:MY_RELATIONSHIP*]->(B)
where all(rel in rels where rel.percentage! > 50) and B.type = 1
return path

但我找不到表达“the end of path has no further relationships as specified before (percentage>50 ...)”的方法

我尝试使用“and not B-->C”扩展 where 子句,但我没有找到如何使用 percentage > 50 进行限定。

有没有办法做到这一点?

非常感谢您 =)

【问题讨论】:

    标签: neo4j cypher


    【解决方案1】:

    你在寻找最长的路径吗?

    所以要么按长度降序排序,然后取前 n 个。

    否则类似:

    start A = node(...)
    match path = (A)-[rels:MY_RELATIONSHIP*]->(B)
    where all(rel in rels where rel.percentage! > 50) and B.type = 1
    AND NONE(r in extract(p in (B-[:MY_RELATIONSHIP]->()) : head(rels(p)) WHERE r.percentage > 50)
    return path
    

    【讨论】:

    • @Michael:'... : head(rels..' 部分中的 : (冒号) 是什么?我找不到有关在列表理解中使用冒号的任何信息。还是您的意思是 |(管道)?
    猜你喜欢
    • 2014-10-29
    • 2016-03-12
    • 1970-01-01
    • 2023-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多