繁体   English   中英

当节点之间没有直接关系时,向Neo4j中的csvfile中的关系添加属性

[英]Add a property to a relation from a csvfile in Neo4j when there is no direct relation between nodes

我有这3个节点(User,Tweet,Token),例如:

:User with this property {userID}
:Token with this property {word}
:Tweet with this properties {tweetID, userID, tweetTxt}

目前的关系如下:

(:Tweet)<-[:MADE]-(:User) (:Token)<-[:CONTAINS {tweet_score}]-(:Tweet)

现在考虑以下csv文件:

userToken.csv
_________________________________________
token,userID,score
that_danielle,15990804,0.111140564157
foodies,15990804,0.159946268074
soft-launched,15990804,0.132826927255
email,60730027,0.0561669544423
email,60730027,0.105124263028
email,60730027,0.0453705868273
email,60730027,0.0967876752689
email,32785000,0.101566813224
you,60730027,0.0835723672219

我需要向“ CONTAINS”关系中添加一个名为“ user_score”的新属性,并且应从userToken.csv文件中检索此分数。 在下面的代码中,我尝试执行以下操作:匹配“ p”以包含用户拥有的所有:Token节点(不确定是否确实有效!),然后使用这些“ p”从csv添加“ user_score”文件与“ CONTAINS”的关系:

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:///..../userToken.csv" AS csvrow
MATCH p=(u:User)-[*2]->(tok:Token)
with p
where u.userID = toInt(csvrow.userID)
FOREACH (n IN nodes(p)| SET n.user_score = toFloat(csvrow.score) )

这是我的节点和关系的样子!!!

这将返回错误:

"csvrow not defined (line 6, column 52 (offset: 258))
"FOREACH (n IN nodes(p)| SET n.user_score = toFloat(csvrow.score) )""

你能帮我解决吗?

PS:不确定我的问题的标题:/

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:///..../userToken.csv" AS csvrow
MATCH p=(u:User)-[*2]->(tok:Token)
with p
where u.userID = toInt(csvrow.userID)
FOREACH (n IN nodes(p)| SET n.user_score = toFloat(csvrow.score) )

之后,在WITH没有传递的所有内容都不可用,因此,由于您没有传递csvrow ,因此不再绑定到查询的其余部分。

但是,您绝对不需要在这里使用。 其次,您在此处的查询会将分数添加到路径中的所有节点,因此在用户节点,tweet和令牌上也是如此。

当您想将其放在CONTAINS关系上时,可以这样进行:

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:///..../userToken.csv" AS csvrow
MATCH (u:User)
where u.userID = toInt(csvrow.userID)
MATCH (u)-[:MADE]->(tweet)-[r:CONTAINS]->(token)
SET r.user_score = csvrow.score

但是,此查询还将在用户节点上添加一个user_score

注释后编辑(假设令牌节点上的属性键为name

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:///..../userToken.csv" AS csvrow
MATCH (u:User)
where u.userID = toInt(csvrow.userID)
MATCH (u)-[:MADE]->(tweet)-[r:CONTAINS]->(token)
WHERE token.name = csvrow.token
SET r.user_score = csvrow.score

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM