I would like to create a graph model that captures the following sequential patterns and return unique paths between specific nodes:
Sequential Patterns
| Pattern ID | Sequential Pattern |
|---|---|
| 1 | A8-->A9 |
| 2 | A8-->S8-->A9 |
| 3 | A8-->A9-->S9 |
| 4 | A8-->S6-->S8 |
| 5 | S8-->A8-->A9 |
| 6 | A8-->S8-->S9 |
Edges of Graph Model
| Edge ID | From Node | To Node | Type |
|---|---|---|---|
| 1 | A8 | A9 | -Transition-> |
| 2 | A8 | S8 | -Transition-> |
| 3 | S8 | A9 | -Transition-> |
| 4 | A9 | S9 | -Transition-> |
| 5 | A8 | S6 | -Transition-> |
| 6 | S6 | S8 | -Transition-> |
| 7 | S8 | A8 | -Transition-> |
| 8 | S8 | S9 | -Transition-> |
The desired output of unique paths starting at A8 and ending at A9:
| Path ID | Unique Path |
|---|---|
| 1 | A8-->A9 |
| 2 | A8-->S8-->A9 |
I have tried the following:
MATCH (a: node{name:'A8'})
MATCH (b:node{name:'A9'})
CALL apoc.algo.allSimplePaths(a,b,'Transition>',3)
YIELD path
RETURN reduce(s="",n in nodes(path) | s+(CASE WHEN s="" THEN "" ELSE "-->" END) +n.name) as string
I get the following output:
| string |
|---|
A8-->A9 |
A8-->S8-->A9 |
A8-->S6-->S8-->A9 * |
A8-->S9-->A9 * |
A8-->S8-->S9-->A9 * |
A8-->S6-->S9--A9 * |
Any suggestions on how I can produce an output that excludes the last 4 paths (marked with *)?