【发布时间】:2020-08-27 14:11:14
【问题描述】:
我有一个单词列表,我想在 Neo4j 中用作种子标签。
这些标签每天都会更新,所以我想自动化我的 Cypher 请求。
这是我今天的清单:
列表:list_of_labels = ['crise sanitaire', 'face crise', 'confinement avril', 'crise coronavirus', 'virus guerre']
我在 Cypher 请求中使用变量尝试了这个:
def create_seed_property(tx, i): j = 0 while j < len(list_of_labels): tx.run(" MATCH (n:ARTICLE {label: $i}) SET n.seed_label = $j RETURN n ") j +=1
接下来我这样做了:
for i in list_of_labels: session.read_transaction(create_seed_property(i))
我不知道我错在哪里。
[附录]
我想为'crise sanitaire' 添加seed_label = 0,为'face crise' 添加seed_label = 1 等。我想为list_of_labels 列表中的每个字符串添加seed_label 属性。但是列表每天都会更新,这就是我尝试将其自动化的原因。
【问题讨论】:
-
你的代码有很多问题。首先,您的
run()调用没有传递任何参数,所以这可能是最直接的问题。但是,为了获得更好的效率,您可能甚至不应该首先在循环中执行此操作。此外,即使您的逻辑确实有效,您最终也会向每个ARTICLE的seed_label写入 5 次,即使最终的属性值始终为 4。您到底想做什么? -
我想为'crise sanitaire'添加seed_label = 0,为'face crise'添加seed_label = 1等。我想为list_of_labels列表中的每个字符串添加seed_label属性。但是列表每天都会更新,这就是我尝试将其自动化的原因。
-
我已将该信息作为
ADDENDUM添加到您的问题中。对于需要澄清的问题等,您将来也应该这样做。 -
谢谢@cybersam