cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Get "parallel" subgraph into ordered list

cmdr
Node Link

Hi,

say that i am modelling a production line consisting of several steps. The line has 2 "entry points" (stepA and stepD) and one "end" (stepG), and the subgraphs starting from the two entry points "merge" at one point(stepC) in the line - like this:

(stepA)-->(stepB)-->(stepC)-->(stepF)-->(stepG)
(stepD)-->(stepE)------|

What i would like to achieve is to have this flattened into a list looking like this:
stepA,stepB,stepD,stepE,stepC,stepF,stepG

So: the upper path from start to the merging point (but excluding it), the lower path from start to the merging point (but including it) and the rest of the path.

Can we achieve something like this with Cypher? If yes - would it also work for more that two starting points and evtl. several different merging points?

Thank you!

4 REPLIES 4

asperlinga
Graph Buddy

Dear Markus,

I understand only this:

Can you give us a pratical example of the results you want?

In the meantime you can look here:
https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#query-syntax-case

ciao

Alessio

cmdr
Node Link

Hi Alessio,

the image you posted is what i was trying to depict with my "ascii art"

The output that i would like to receive is a list: [stepA,stepB,stepD,stepE,stepC,stepF,stepG].
stepA and stepB would come first, cause they are the first brach from the beginning to the merge point, them stepD and stepE cause they are the second brach (e.g. derived simply from the name who is first and second) amd then everything after the merge point.

Cheers

asperlinga
Graph Buddy

Hi Markus,

I think you can use "OPTIONAL MATCH" as in the example below, looks like an outer join in SQL.
Sorry, I can't try it on a DB.

1
MATCH (A:stepA)
OPTIONAL MATCH (A)-->(B:stepB)-->(C:StepC)-->(F:stepF)-->(G:stepG)
RETURN A.code as stepA, B.code as stepB, C.code as stepC, G.code as stepG
LIMIT 5

2
MATCH (D:stepD)
OPTIONAL MATCH (D)-->(E:stepE)-->(C:StepC)-->(F:stepF)-->(G:stepG)
RETURN D.code as stepD, E.code as stepE, C.code as stepC, G.code as stepG
LIMIT 5

I write LIMIT 5 because we have no filter on stepA and I presume exist a property "code"
You can filter Ex: MATCH (A:stepA{code:"0001"})

You can export the two list in Excel as csv file with the same structure if you write:

in 1
RETURN A.code as stepA, B.code as stepB," " as stepD," " as stepE, C.code as stepC, G.code as stepG

in 2
RETURN " " as stepA," " as stepB, D.code as stepD, E.code as stepE, C.code as stepC, G.code as stepG

You can also test the UNION clause (https://neo4j.com/docs/cypher-manual/4.1/clauses/union/) for have only one list.

ciao

Alessio

cmdr
Node Link

Hi Alessio,

thank you for your suggestion. I don´t think that it solves my problem, cause this seems to only work when i completely specify the output "path" in the query? What i wanted was to have a query that essentially does something like "Take these startNodes (A & D), follow them to the end node (G) and combine all the parallel paths on the merging Nodes"

Or maybe i just don`t understand?

Anyway, in the meantime i came to the idea to just manually introduce a new relationship type that depicts the desired outcome and query the one or the other relationship type depending on desired POV.

Thank you
Markus