I need to split a field in different values and store each value in a different node. For each created node I want to store the position. Example:
Sentence Words
My car is red My;car;is;red
Using:
FOREACH (w IN SPLIT(line.TWords, ";") |
MERGE (wd:Word {word: w})
I can split the field and store the different words, but I'd like to store the position on the relationship.
My car is red -[HAS_WORD {position:1}]-> My
My car is red -[HAS_WORD {position:2}]-> car
My car is red -[HAS_WORD {position:3}]-> is
My car is red -[HAS_WORD {position:4}]-> red
How can I get this?
SOLUTION
USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM 'file:///output_2016-05-06_0203_Neo4jImport.csv' AS line FIELDTERMINATOR "\t"
MERGE (s:Segment{text: line.Source})
MERGE (ta:Segment{text: line.Target})
WITH SPLIT(line.SWords, ";") AS SWords, line, s, ta
UNWIND RANGE(0, SIZE(SWords)-1) as i
MERGE (s)-[r:HAS_WORD {position:i+1}]->(w:Word {word: SWords[i]})
WITH SPLIT(line.TWords, ";") AS TWords, line, ta
UNWIND RANGE(0, SIZE(TWords)-1) as i
MERGE (ta)-[r:HAS_WORD {position:i+1}]->(w:Word {word: TWords[i]})
Be sure that the fist WITH
has the variable references necessary in second WITH: WITH SPLIT(line.SWords, ";") AS SWords, line, s, ta