Cypher如何仅对特定类型的节点施加最大跳数? [英] How can Cypher Impose a Maximum Number of Hops Only Counting a Specific Type of Node?

查看:62
本文介绍了Cypher如何仅对特定类型的节点施加最大跳数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Neo4J中,可以使用Cypher根据两个节点之间的最大跳数来过滤结果,如下所示:

I know that in Neo4J, Cypher can be used to filter results based on a maximum number of hops between two nodes, like this:

MATCH (a:Word)-[relationships*..3]-(b:Word)
RETURN a, relationships, b
LIMIT 5

这将返回节点(a和b),它们都是Word类型的,并且彼此之间总共有4个跃点(通过所有节点类型和所有关系类型).

This will return nodes (a and b) that are both of type Word, and that are with 4 total hops of each other (through all node types, and all relationship types).

我想知道是否可以使Cypher在上例中计数到最多3个跃点时仅计算特定类型的节点.

I'm wondering whether Cypher can be made to only count specific types of nodes when it's counting to that maximum of 3 hops in the above example.

例如,在此节点链中:

(a:Word)--->(b:定义)--->(c:Word)--->(d:定义)--->(e:定义)--->(f:Word)--->(g:定义)--->(h:Word)

(a:Word) ---> (b:Definition) ---> (c:Word) ---> (d:Definition) ---> (e:Definition) ---> (f:Word) ---> (g:Definition) ---> (h:Word)

节点 a h 之间总共有 7个跃点.但是,它们之间只有 3个字跳.

There are 7 total hops between nodes a and h. However, there are only 3 Word hops between them.

Cypher是否可以通过这种方式施加最大跳数?

Is it possible for Cypher to impose a maximum number of hops in this way?

推荐答案

您可以使用过滤器以计算标签个节点.例如:

You can use a filter to count label of nodes. For example:

MATCH path = (a:Word)-[relationships*..10]-(b:Word)
WHERE SIZE( FILTER(n IN NODES(path) WHERE 'Word' IN LABELS(n)) ) > 3
RETURN a, relationships, b
LIMIT 5

这篇关于Cypher如何仅对特定类型的节点施加最大跳数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆