简体   繁体   English

如何在Neo4j中找到具有多个节点和多个关系的最短路径

[英]How to find the shortest path with multiple nodes and multiple relationships in Neo4j

I am not an expert in Cypher but I'm in a project where I have several nodes with the following properties: 我不是Cypher的专家,但是我在一个项目中有多个具有以下属性的节点:

['COGAB11', 'COGAB7', 'COGAB30', 'COGAB32', 'COGAB94', 'COGAB70',
'COGAB01', 'COGAB04', 'COGAB91', 'COG1AB77', 'COGAB46', 'COGAB40',
'COGAB31', 'COGAB14']

and between them there are several relationships: 它们之间存在几种关系:

[rel:coexpression|cooccurence|database|experimental|
fusion|neighborhood|score|textmining]

which also have a property like score which is a numerical integer value of 0-1000 and I would like to find the shortest path between all these nodes and get the relationships with a score greater than and equal to 500 between them. 它也具有诸如score的属性,该属性是0-1000的数值整数,我想找到所有这些节点之间的最短路径,并获得它们之间的分数大于等于500的关系。 Therefore, I would like to return the graph with these relationships and path. 因此,我想返回具有这些关系和路径的图。 However, I have only found a query of the shortest path but between two nodes and not between multiple nodes and multiple relationships. 但是,我只找到了最短路径的查询,但是查询的是两个节点之间,而不是多个节点和多个关系之间。 Additionally, I'm not sure if I should use APOC for this. 另外,我不确定是否应该为此使用APOC。

MATCH (start:Loc{name:'A'}), (end:Loc{name:'F'})
CALL algo.shortestPath.stream(start, end, 'cost')
YIELD nodeId, cost
RETURN algo.asNode(nodeId).name AS name, cost

If you mean that you want each relationship to have a score >= 500, then this should return the shortest path: 如果您想让每个关系的score大于等于500,则应返回最短路径:

MATCH (start:Loc {name: 'A'}), (end:Loc {name: 'F'}),
  p = SHORTESTPATH((start)-[:coexpression|cooccurence|database|experimental|fusion|neighborhood|score|textmining]-(end))
WHERE ALL(r IN RELATIONSHIPS(p) WHERE r.score >= 500)
RETURN p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM