如何将 Neo4j 图形算法与 Neo4jClient 一起使用

How to use the neo4j graph algorithms with Neo4jClient

我想为 neo4j 使用 closeness centrality graph algorithm with Neo4jClient .Net 客户端。

在 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 是我的 class 节点,它们之间有 SEES 关系。

我得到的异常是:

SyntaxException: Unknown procedure output: `node` (line 2, column 7 (offset: 
55))
"YIELD node,centrality"
        ^

此查询的正确 C# 语法是什么?

简单的解决方案 - 将 'node' 更改为 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;

这 return 是一个 IEnumerable,其中每个元素都是匿名类型,具有 nodeId 及其中心性分数的两个属性。 Int32 = nodeId.As<Int32>()Double = centrality.As<Double>() 看起来应该更简洁。

documentation for closeness centrality 将 'node' 作为 return 类型的名称,但它似乎应该是 nodeId。

这些密码到 C# 翻译的有用资源是 Neo4jClient github 页面上的 cypher examples page

你是对的这个查询 returns 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;