neo4j:受节点和rel属性约束的最短路径

编程入门 行业动态 更新时间:2024-10-11 13:23:02
本文介绍了neo4j:受节点和rel属性约束的最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

从教程开始:

MATCH p=shortestPath( (keanu:Person)-[:KNOWS*]-(kevin:Person) ) WHERE keanu.name="Keanu Reeves" and kevin.name = "Kevin Bacon" RETURN length(p)

想象一下,每个人"节点都有一个年龄属性和一个职业.每个KNOWS边都有一个length of acquaintance属性.

Imagine each Person node has an age property and an occupation. Every KNOWS edge has a length of acquaintance property.

什么Cypher查询将返回最短路径,例如,

What Cypher query would return a shortest path with, for instance,

age > 40 years not (occupation = ACTOR) lengthOfAcquaintance > 10 years

在分子生物学相互作用数据中,我们希望进行更复杂的查询-可能是密码处理得很好的那种查询,但又使我难以理解.例如:

In molecular biology interaction data, we wish to make yet more complex queries - probably of the sort which cypher handles well, but just how eludes me. For example:

找到受体分子A和转录因子B之间的最短路径,其中大多数边缘来自小规模实验,大多数基因被标记为激酶,并且边缘的证据(权重)为greater than 0.5

Find the shortest paths between receptor molecule A and transcription factor B, where most edges are from small-scale experiments, most of the genes are annotated as kinase, and evidence (weight) for the edges is greater than 0.5

这些查询可能在许多设置中出现.谁能指出我的阅读和例子,这将有助于我理解其完成方式?也许可以提供培根数"查询的适度扩展,以容纳一个节点和一个边缘属性?

These queries probably come up in lots of settings. Can anyone point me towards readings and examples which will help me understand how this is done? And maybe provide a modest extension of the "Bacon Number" query which accommodates one node and one edge property?

谢谢!

  • Paul
推荐答案

我认为您正在寻找的是所有谓词.

I think that what you are looking for is the ALL predicate.

以下是一些使用它的示例:

Here are a couple of examples using it :

ShortestPath,路径中的所有参与者都应具有age > 40:

ShortestPath where all actors in the paths should have an age > 40 :

MATCH p=shortestPath( (keanu:Person)-[:KNOWS*]-(kevin:Person) ) WHERE keanu.name = "Keanu Reeves" AND kevin.name = "Kevin Bacon" AND ALL(x IN nodes(p) WHERE x.age > 40) RETURN p

ShortestPath,其中所有边缘都应具有lengthOfAcquaintance > 10

ShortestPath where all edges should have a lengthOfAcquaintance > 10

MATCH p=shortestPath( (keanu:Person)-[:KNOWS*]-(kevin:Person) ) WHERE keanu.name = "Keanu Reeves" AND kevin.name = "Kevin Bacon" AND ALL(x in rels(p) WHERE x.lengthOfAcquaintance > 100 RETURN p

您当然可以将两者结合在一起:

Of course you can combine the both :

MATCH p=shortestPath( (keanu:Person)-[:KNOWS*]-(kevin:Person) ) WHERE keanu.name = "Keanu Reeves" AND kevin.name = "Kevin Bacon" AND ALL(x in rels(p) WHERE x.lengthOfAcquaintance > 10) AND ALL(x in nodes(p) WHERE x.age > 40) RETURN p

更多推荐

neo4j:受节点和rel属性约束的最短路径

本文发布于:2023-11-29 11:39:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   最短   路径   属性   neo4j

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!