如何在Neo4jClient中使用neo4j图算法

问题描述 投票:0回答:2

我想使用closeness centrality图算法与Neo4jClient .Net客户端neo4j。

在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;

SitePointis我的类节点,它们之间有SEES关系。

我得到的例外是:

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

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

c# neo4j cypher graph-algorithm neo4jclient
2个回答
0
投票

简单的解决方案 - 更改nodeId的'node':

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。

这些cypher到C#转换的有用资源是Neo4jClient github页面上的cypher examples page


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;
© www.soinside.com 2019 - 2024. All rights reserved.