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:
- input: [y], output: [a, b]
- input: [a], output: [c]
- input: [b], output: [d]
- 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
.