1
votes

create a relationship between nodes with the property input and output where the output value of a node becomes input value to another node. for example i have 4 nodes, each node has property:

  1. input: [y], output: [a, b]
  2. input: [a], output: [c]
  3. input: [b], output: [d]
  4. input: [c, d] output: [x]

this is my cypher code :

MATCH (n:node), (m:node)
WITH n.output as output, m.input as input
FOREACH (output in n |
       FOREACH (input in m |
               MATCH n, m
               WHERE output = input
               MERGE (n)-[:NEXT_TO]->(m)
       )
)

the output of the cypher code above should be the relation NEXT_TO from node 1 to nodes 2 and 3, relation NEXT_TO from node 2 to node 4 and relation NEXT_TO from node 3 to node 4.

1

1 Answers

1
votes

Perhaps something like this?

MATCH (n:node)
UNWIND n.output as output
MATCH (m:node) WHERE output IN m.input
MERGE (n)-[:NEXT_TO]->(m)