节点耦合仅连接到子图中的一种类型的节点

时间:2017-06-18 16:48:27

标签: neo4j cypher

我正在努力实现以下目标,但我无法弄清楚如何做到这一点。

我的节点类型为:A:S1:S2:t和:k

我希望找到连接到:t节点并且永远不会连接(当然都是):A:S个节点的:S1个节点的对,但我希望在子:A:S:S1节点连接到另一个节点(:k{t:1})的子图中执行此操作。

如果没有子图需要它很简单,例如:

match p=(n:t)-[]-(:A)-[]-(m:t) 
WHERE NOT (n)-[]-(:S)-[]-(m) 
and NOT (n)-[]-(:S1)-[]-(m)
WITH n,m,count(p) as test
where test >4
return n.token,m.token,test ORDER BY test DESC

但我如何加入

(:A)--(:k{t:1})

(:S)--(:k{t:1}),(:S1)--(:k{t:1})

的关系?

1 个答案:

答案 0 :(得分:0)

首先简单地MATCH子图和它之后MATCH所需的n个节点如何?

这样:

// First MATCH (:A)--(:k{t:1}), (:S)--(:k{t:1}), (:S1)--(:k{t:1})
// Store the matched nodes in a, k, s and s1 variables
MATCH (a:A)--(k:k{t:1}),
(s:S)--(k),
(s1:S1)--(k)

// Using a, k, s and s1 match couple of n...
// connected with a
MATCH p = (n:t)--(a)--(m:t)
// not connected with s 
WHERE NOT (n)--(s)--(m)
// and not connected with s1
AND NOT (n)--(s1)--(m)
WITH n, m, count(p) as count
WHERE count > 4
RETURN n.token, m.token, count
ORDER BY count
相关问题