【问题标题】:Finding Paths with Neo4j Cypher Below a Given Length, but Excluding Those with an Nodes with a Specific Property set to a Specific Value使用 Neo4j Cypher 查找路径低于给定长度,但排除具有特定属性的节点设置为特定值的路径
【发布时间】:2014-11-18 17:52:43
【问题描述】:

我无法创建适当的 Cypher 查询。我想返回主题节点一定距离内的所有边和节点的子图。这可以通过以下方式轻松完成:

START (topic: attribute)-[rel: describedBy*0..4]-(node: attribute
WHERE id(topic) IN [37, 38] 
RETURN rel;

问题是我想删除路径中的任何节点(末端节点除外)具有属性“key”且值为“enrichment”或“classification”的路径。

我尝试使用以下方法删除路径:

MATCH path=(topic: attribute)-[rel: describedBy|influences*0..4]-(intermediate: attribute)-[rel: describedBy|influences*0..4]-(node: attribute)
WHERE id(topic) IN [37,38] AND NOT intermediate in [x IN nodes(path) WHERE x.key IN ['enrichment', 'classification'] | x] and length(path) < 5
RETURN rel;

我已经尝试在路径中的每个潜在距离进行过滤:

MATCH (topic: attribute)-[rel:describedBy|influences]-(node: attribute)
WHERE id(topic) IN [37,38]
RETURN rel as rels
UNION
MATCH path=(topic: attribute)-[rel: describedBy|influences*1]-(intermediate: attribute)-[rel: describedBy|influences*1..3]-(node: attribute)
WHERE id(topic) IN [37,38] AND NOT intermediate.key in ['enrichment', 'classification'] and length(path) < 5
RETURN rel as rels
UNION
MATCH path=(topic: attribute)-[rel: describedBy|influences*2]-(intermediate: attribute)-[rel: describedBy|influences*1..2]-(node: attribute)
WHERE id(topic) IN [37,38] AND NOT intermediate.key in ['enrichment', 'classification'] and length(path) < 5
RETURN rel as rels
UNION
MATCH path=(topic: attribute)-[rel: describedBy|influences*3]-(intermediate: attribute)-[rel: describedBy|influences*1..1]-(node: attribute)
WHERE id(topic) IN [37,38] AND NOT intermediate.key in ['enrichment', 'classification'] and length(path) < 5
RETURN rel as rels;

我希望第 2 场比赛能够停止 (37)-[rel]-(32)-[rel*0..3]-() 的路径,但是其中 32 具有 'key':'enrichment'它没有。

有没有人对我如何制定查询以在到达具有特定键值对的节点时停止跟随路径有任何建议?

感谢您的帮助。

【问题讨论】:

  • 顺便说一句,如果可能的话,我还想将 node.key IN [value list] match 替换为某种类型的 degree(node)

标签: neo4j cypher


【解决方案1】:

我认为这是我想要的:

MATCH path=(topic: attribute)-[rel:describedBy|influences]-(node: attribute)
WHERE id(topic) IN [128204]
RETURN DISTINCT extract(r IN rels(path) | r)
UNION
MATCH path=(topic: attribute)-[rel1: describedBy|influences]-(intermediate: attribute)-[rel2: describedBy|influences]-(node: attribute)
WHERE id(topic) IN [128204] AND NOT intermediate.key in ['enrichment', 'classification'] and length(path) < 5
RETURN DISTINCT extract(r IN rels(path) | r)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2011-07-04
    • 1970-01-01
    相关资源
    最近更新 更多