quelopes
quelopes

Reputation: 121

Add path in network

I've this expression:

MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE) 
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr

So, I would like ADD MORE the follow pattern, like this sentence:

(c:CLUSTER)-[:has]-(v:ORTH) where v.Term are equal in all CLUSTER

Any suggestions? Thanks!

Upvotes: 0

Views: 41

Answers (2)

JohnMark13
JohnMark13

Reputation: 3739

To filter the results by an additional parameter:

MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE) 
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH{term:"Your Value"})
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr

If you literally want all the values for v.term to be the same (but you do not know what that value is ahead of time) then it's a bit more involved and I think that you will have to use the WHERE ALL collection predicate to compare the term property in a collection of ORTH nodes.

MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE) 
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH)
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info, COLLECT(v) as orths
ORDER BY score DESC
WHERE ALL(orth IN TAIL(orths) WHERE (orth.term = HEAD(orths).term))
AND score >= 4
RETURN h.sym, score, info, h.chr

If that is what you want it may be faster to break the HEAD and TAIL collection modifiers into a separate WITH and apply the length filter first:

MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE) 
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH)
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info, COLLECT(v) as orths
WHERE score >= 4
WITH h, score, info, TAIL(orths) as orhttail, HEAD(orths) as orthhead
WHERE ALL(orth IN orthtail WHERE (orth.term = orthead.term))
RETURN h.sym, score, info, h.chr

Upvotes: 1

Stewart
Stewart

Reputation: 18302

This is an untested suggestion.

MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE) 
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH)
WITH v, h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
WHERE v.Term are equal in all CLUSTER
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr

Alternatively:

MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)  // Find 'c', we don't need 'g' after this
WITH c
MATCH (v:ORTH)-[:has]-(c:CLUSTER)<-[:Belong]-(h:GNE) // From 'c', find the datums of interest
WITH v, h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
WHERE v.Term are equal in all CLUSTER
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr

Upvotes: 0

Related Questions