[英]Neo4j Cypher Query: Finding all nodes, that are connected to a node, that has more than 3 other relationships
I have a problem with my Cypher query.我的 Cypher 查询有问题。 I have some nodes called
:SENTENCE
and some other called :WORD
.我有一些名为
:SENTENCE
节点,还有一些名为:WORD
节点。 :SENTENCE
nodes have relationships :CONTAINS
to :WORD
nodes. :SENTENCE
节点具有:CONTAINS
到:WORD
节点的关系。
I want to find :SENTENCE
nodes, that are connected to :WORD
nodes, that are used from more than 3 other :SENTENCE
nodes.我想找到连接到
:WORD
节点的:SENTENCE
节点,这些节点被 3 个以上的其他:SENTENCE
节点使用。 All :WORD
nodes have to comply this criterion.所有
:WORD
节点都必须遵守此标准。
I tried something like this:我试过这样的事情:
MATCH p=(s1:SENTENCE)-[:CONTAINS]-(w:WORD)-[:CONTAINS]-(s2:SENTENCE)
WITH s1,w, COUNT(s2) as num
WHERE num > 3
RETURN s1
LIMIT 25
But the result contains :SENTENCE
nodes, where one and not all :WORD
nodes have a degree of minimum 3.但结果包含
:SENTENCE
节点,其中一个而不是所有:WORD
节点的度数最小为 3。
Some other try:其他一些尝试:
MATCH p=(s1:SENTENCE)-[:CONTAINS]-(w:WORD)-[:CONTAINS]-(s2:SENTENCE)
WHERE SIZE((:SENTENCE)-[:CONTAINS]-(w:WORD)) > 3
RETURN s1
LIMIT 25
But this does not hold for any :WORD
nodes that is contained in an Sentence.但这不适用于包含在 Sentence 中的任何
:WORD
节点。 It only holds for 1.它仅适用于 1。
So my question is: How can I make a query that the condition hold for all nodes and not only for one.所以我的问题是:如何查询条件适用于所有节点而不仅仅是一个节点。
This kind of requirement usually requires collecting nodes and using the all()
function to ensure some predicate holds true for all elements of the collection:这种要求通常需要收集节点并使用
all()
函数来确保某些谓词适用于集合的所有元素:
MATCH (s1:SENTENCE)-[:CONTAINS]-(w:WORD)
WITH s1, collect(w) as words
WHERE all(word in words WHERE size((word)-[:CONTAINS]-()) > 3)
RETURN s1
LIMIT 25
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.