[英]Finding Paths with Neo4j Cypher Below a Given Length, but Excluding Those with an Nodes with a Specific Property set to a Specific Value
I am having trouble creating an appropriate Cypher query. 我在创建适当的Cypher查询时遇到问题。 I would like to return the sub-graph of all edges & nodes within a certain distance of a topic node. 我想返回主题节点一定距离内所有边缘和节点的子图。 This could easily be done with something like: 这可以很容易地通过以下方式完成:
START (topic: attribute)-[rel: describedBy*0..4]-(node: attribute
WHERE id(topic) IN [37, 38]
RETURN rel;
The problem is I want to remove paths where any of the nodes in the path (other than the end node) have the property "key" with either the value "enrichment" or "classification". 问题是我要删除路径中任何节点(终端节点除外)具有值为“ enrichment”或“ classification”的属性“ key”的路径。
I've tried removing paths using: 我尝试使用以下方式删除路径:
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;
I've tried filtering at each potential distance in the path: 我试过过滤路径中每个可能的距离:
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;
I was hoping the 2nd match would stop paths that go (37)-[rel]-(32)-[rel*0..3]-(), where 32 has 'key':'enrichment', however it does not. 我希望第二场比赛能够阻止走(37)-[rel]-(32)-[rel * 0..3]-()的路径,其中32具有'key':'enrichment',但是它没有。
Does anyone have any suggestions how I could formulate a query to stop following a path when it reaches a node with a specific key:value pair? 有人对我如何提出查询以在到达具有特定key:value对的节点时停止遵循路径的方法有任何建议吗?
Thank you for the help. 感谢您的帮助。
I think this does what I want: 我认为这符合我的要求:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.