2017-06-18 71 views
1

我想實現以下,但我不能完全弄清楚如何做到這一點。節點組只連接到一個子圖內的一種節點

我有節點類型:A,:S1, :S2:t和:k

我想找到連接到一個:A節點,並且從不連接(兩個,當然),以:S:S1節點:t節點的夫妻,但我想這樣做的子圖,其中: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}) 

的關係?

回答

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 
相關問題