计算中介 - 中心性和显示百分比

时间:2017-05-25 11:56:04

标签: neo4j cypher percentage network-analysis

我在Neo4j图表上做了一些分析,并且知道我遇到了另一个问题。 我的工作查询如下:

MATCH p=allShortestPaths((source:Person)-[:KNOWS*]-(target:Person)) 
WHERE id(source) < id(target) and length(p) > 1 
UNWIND nodes(p)[1..-1] AS n 
RETURN n.id AS id, n.firstname AS firstname, n.lastname AS lastname, count(*) as betweenness 
ORDER BY betweenness DESC

这可以按预期工作,并给我一个这样的列表:

result betweenness

到目前为止,这么好。但是现在我想要一个额外的列,其中显示基于所有最短路径的百分比值。 我曾尝试简单地添加100.0 * SUM(betweenness) / count(p) AS percent,但这会导致错误变量betweenness未定义(第4行,第119栏(偏移:267))

如果有人知道如何处理,请告诉我;)

提前谢谢,干杯!

1 个答案:

答案 0 :(得分:0)

使用WITH

  • 使用WITH传递p以及下一个上下文的其他属性。
  • betweenness计算percent并返回全部。

试一试:

MATCH p=allShortestPaths((source:Person)-[:KNOWS*]-(target:Person)) 
WHERE id(source) < id(target) and length(p) > 1 
UNWIND nodes(p)[1..-1] AS n 
WITH p, n.id AS id, n.firstname AS firstname, n.lastname AS lastname, count(*) as betweenness
RETURN id, firstname, lastname, betweenness, 100.0 * SUM(betweenness) / count(p) AS percent
ORDER BY betweenness DESC