我想将closeness centrality图算法与用于Neo4j的.Net客户端Neo4jClient一起使用。
在Cypher中使用紧密度中心点的查询是:
CALL algo.closeness.stream('Node', 'LINK')
YIELD nodeId, centrality
RETURN algo.getNodeById(nodeId).id AS node, centrality
ORDER BY centrality DESC
LIMIT 20;
我尝试翻译成C#:
var clcsCent =
_graphClient.Cypher.Call("algo.closeness.stream('SitePoint', 'SEES')")
.Yield("node,centrality")
.Return((node,centrality)=>new {
Int32 = node.As<Int32>(),
Double = centrality.As<Double>()
})
.Results;
SitePoint
是我的类,用于它们之间具有SEES
关系的节点。
我得到的例外是:
SyntaxException: Unknown procedure output: `node` (line 2, column 7 (offset:
55))
"YIELD node,centrality"
^
此查询的正确C#语法是什么?
答案 0 :(得分:0)
简单的解决方案-更改nodeId的“节点”:
var clcsCent =
_graphClient.Cypher.Call("algo.closeness.stream('SitePoint', 'SEES')")
.Yield("nodeId,centrality")
.Return((nodeId,centrality)=>new {
Int32 = nodeId.As<Int32>(),
Double = centrality.As<Double>()
})
.Results;
这将返回一个IEnumerable,其中每个元素是一个匿名类型,它具有nodeId及其中心得分的两个属性。
Int32 = nodeId.As<Int32>()
和Double = centrality.As<Double>()
看起来都应该更简洁。
documentation for closeness centrality将'node'用作返回类型的名称,但似乎应该是nodeId。
Neo4jClient github页面上的cypher examples page是将这些密码转换为C#的有用资源
答案 1 :(得分:0)
您是对的,该查询返回nodeId
而不是node
。
如果您想要节点,那么您的Cypher查询应该是这样
(我不知道如何在C#中翻译它,我想您可以翻译它以获取节点):
CALL algo.closeness.stream('SitePoint', 'SEES')
YIELD nodeId, centrality
RETURN algo.getNodeById(nodeId) AS node, centrality
ORDER BY centrality DESC
LIMIT 20;