Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-09-2019 09:07 AM
Hello all,
I'm trying to modify a code by Michael Hunger. What I want is to add a sentence number to each word.
{text} is a list of words.
S is initialized by 1 and it will be used to update the sentence number.
If the current WORDS[i] is a dot (full stop), then increment S.
My code as follows:
WITH {text} AS WORDS, 1 AS S
UNWIND range(0, size(WORDS)-2) AS i
WITH WORDS, i, (CASE WHEN WORDS[i] CONTAINS "." THEN S+1 ELSE S END ) AS S
MERGE (w1:Word {name: WORDS[i]})
ON CREATE SET w1.count = 1, w1.position = [i+1], w1.sentence = [S]
ON MATCH SET w1.count = w1.count + 1, w1.position = w1.position + [i+1], w1.sentence = w1.sentence + [S]
MERGE (w2:Word {name: WORDS[i+1]})
ON CREATE SET w2.count = 1
ON MATCH SET w2.count = w2.count + (case when i = size(WORDS)-2 then 1 else 0 end)
MERGE (w1)-[r:NEXT]->(w2)
ON CREATE SET r.count = 1
ON MATCH SET r.count = r.count+1
The problem is:
Anyone can help?!
Thank you.
All the sessions of the conference are now available online