我想导入一些句子,用文字分割内容。对于我分割句子并使用FOREACH和CASE检查数组的大小,并根据运行不同类型的语句
以下查询是我正在使用的缩减版本,但我得到的错误是相同的
WITH SPLIT("my house", " ") AS SWords
WITH SIZE(SWords) as msize, SWords
FOREACH(myize IN CASE WHEN msize = 1 THEN
[
MERGE (w1:Word{name: SWords[0]})
]
ELSE
[
MERGE (w2:Word{name: SWords[1]})
]
END
)
返回该错误:
Invalid input ')': expected whitespace or a relationship pattern (line 5, column 44 (offset: 176))
" MERGE (w1:Word{name: SWords[0]})"
^
MERGE (w1:Word)
,我会收到关于FOREACH的右括号的错误代码:
WITH SPLIT("my house", " ") AS SWords
WITH SIZE(SWords) as msize, SWords
FOREACH(myize IN CASE WHEN msize = 1 THEN
[
MERGE (w1:Word)
]
ELSE
[
MERGE (w2:Word)
]
END
)
错误:
Invalid input ')': expected whitespace, comment, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR or '|' (line 12, column 9 (offset: 332))
" )"
^
欢迎任何帮助! 感谢
答案 0 :(得分:0)
解决方案(如this question中所述)是使用两个FOREACH,每个条件一个:
NSNotFound
这将是第二个FOREACH和节点&#34; house&#34;将被添加到db
无论如何,我不明白为什么我使用的代码没有用,最后CASE-WHEN-ELSE语句没有按预期工作
答案 1 :(得分:0)
在Cypher中,集合([...]
)必须包含值,而不是Cypher读/写语句(如MERGE
)。
此外,您只需要一个FOREACH
子句即可获得正确的结果:
WITH SPLIT("My house", " ") AS SWords
WITH SIZE(SWords) as msize, SWords
FOREACH(name IN
CASE
WHEN msize = 1 THEN [SWords[0]]
WHEN msize > 1 THEN [SWords[1]]
ELSE []
END |
MERGE (:Word{name: name})
);