Given A, How to get F, E, B, C and their relations.
First I want get all the child nodes b via (a)-[:SubEvent]->(b) then spread the path by childs of childs with [:Causal|Result|SubEvent] of child. if exists child of child then spread NextEvent of child of child
I have a cypher like this:
match (e:A)-[:SubEvent|mo_ta]->(e1)-[r1:NextEvent*0..1]-()
match path=(e1)-[r2:(Causal|Result|SubEvent)*0..1]->(var1)-[r3:NextEvent*0..1]-(var2)
return nodes(path), r1 + r2 + r3
but it doesn't work: if e1 doesn't have r2 then e1 equal var1 then it still gets the NextEvent of e1 which is D which is not correct.
Match p=(a)-[*..3]-(d)
return p
This will return all the node shown in your image. Changing path length to 2 shows a, b, c, d, e nodes
If you do not want to see node d, then use
Match p=(a)-[*..3]-(d) where not labels(d) in [["d"]]
match (:Event {id:"A"})-[r1:SubEvent]->(subEvent)
optional match (subEvent)-[r2:Causal|Result|SubEvent]->(child:Event)
optional match (child)-[r3:NextEvent]-(e)
return *
note that "if exists child of child" is implicit: if the first optional match does not return anything, the second is ignored