简体   繁体   English

用Neo4j Cypher查找给定长度以下的路径,但排除那些将其特定属性设置为特定值的节点的路径

[英]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.

相关问题 Cypher (Neo4j) 匹配具有特定长度和值的所有路径 - Cypher (Neo4j) Match all paths with specific length and value 查找没有特定关系的节点(Cypher / neo4j) - Finding nodes that do not have specific relationship (Cypher/neo4j) 在Cypher Neo4j中查找并计算从一个不超过特定长度的节点开始的所有可能路径 - Find and count all possible paths starting from one node not exceeding specific length in Cypher Neo4j 查找具有特定长度的路径以及具有特定度数neo4j的节点 - find paths with specific length combined with nodes with specific degree neo4j Cypher -Neo4j在可变长度路径中设置节点属性值 - Cypher -Neo4j Set the node attribute value in Variable length paths Neo4J Cypher排除连接到特定节点的节点 - Neo4J Cypher Exclude nodes that connect to a specific node Neo4j Cypher 排除缺少特定关系的节点 - Neo4j Cypher exclude nodes where a specific relationship is missing 具有特定标签的Neo4j / Cypher / Traversing节点 - Neo4j / Cypher / Traversing nodes having a specific label 在 Neo4j 中如何返回特定节点或与密码的关系? - In neo4j how to return specific nodes or relationship with cypher? 从Neo4j Cypher allShortestPaths()中排除包含给定节点或给定关系的路径 - Excluding paths from Neo4j Cypher allShortestPaths() that contain a given node, or given relationship
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM