1

我想给顶点增加权重。

我在 r-studio 中迈出了第一步。以下代码给出了一个带有权重的数据框:

query = "
MATCH (p)-[:REFERS_TO]->(q)<-[:REFERS_TO]-(r)
WHERE (ID(p) < ID(q))
RETURN q.name, COUNT(q) AS Weight
ORDER BY Weight DESC
"
newvalue = cypher(graph, query)

如何将权重作为标签添加到顶点?以下对我不起作用,因为它将权重添加到节点而不是顶点:

query = "
MATCH (p)-[:REFERS_TO]->(q)<-[:REFERS_TO]-(r)
WITH q.name, COUNT(q) AS Weight
SET q.weight = Weight
"
cypher(graph, query)

谢谢!

4

1 回答 1

1

I think what you're trying to do is to add the weight to the edge (or relationship) rather than to the node (or vertex).

In order to add the weight as a property of the edge, you need to bind it to a variable, and then you can set the property as before:

query = "
MATCH (p)-[r1:REFERS_TO]->(q)<-[r2:REFERS_TO]-(r)
WITH q.name, COUNT(q) AS Weight
SET r1.weight = Weight, r2.weight = Weight
"
cypher(graph, query)

Note I can't tell which of the relationships you want the weight on, so in this example I'm doing both. The only thing here is I'm binding those two relationships to r1 and r2. Relationships can have properties just like nodes, so the rest is straightforward.

于 2015-03-29T00:04:18.890 回答