1

This question is related to that one.

I explain my little usecase to better understand my problem :

I have this kind of graph (doc)-[contain]-(sentence)-[with]-(word)

Nodes (word) can have semantic relations between them (word)-[rel]-(word)

I want to return (doc) with a number of [rel] > 10

This query can do that :

MATCH (doc:document)-[contain]-(sentence)-[with]-(ng1:word)-[rel:relations]-(ng2:word)
WITH doc, count(rel) as nbRels, collect(rel) as rels
WHERE nbRels > 10 RETURN doc, nbRels, rels

But I don't know what (word) are concerned by each [rel] found.

Is it possible to do know and to return that?

Thanks,

Community
  • 1
  • 1
JC R
  • 314
  • 2
  • 10

1 Answers1

1

Untested, but you should be able to unwind your rels collection and pull out the start and end nodes. Something like:

MATCH (doc:document)-[contain]-(sentence)-[with]-(ng1:word)-[rel:relations]-(ng2:word)
WITH doc, count(rel) as nbRels, collect(rel) as rels
WHERE nbRels > 10
WITH doc, UNWIND(rels) as rel,
RETURN doc, STARTNODE(rel), ENDNODE(rel)

But you might just want to collect something different in the first place:

MATCH (doc:document)-[contain]-(sentence)-[with]-(ng1:word)-[rel:relations]-(ng2:word)
WITH doc, ng1, collect(ng2) as rels
WHERE LENGTH(rels) > 10 
RETURN doc, ng1, rels
JohnMark13
  • 3,709
  • 1
  • 15
  • 26
  • 2
    Hello, Thank you a lot! Your answer helps me a lot. Here is the query with correct syntax (if you want to edit your answer) `MATCH (doc:document {docid:5881})-[contain]-(sentence)-[with]-(ng1:word)-[rel:relations]-(ng2:word) WITH doc, count(rel) as nbRels, collect(rel) as rels WHERE nbRels > 10 WITH doc, rels UNWIND rels AS rel RETURN doc, STARTNODE(rel), ENDNODE(rel)` Thank you again, – JC R Nov 20 '14 at 15:34