I would like to use the closeness centrality graph algorithm with Neo4jClient a .Net client for neo4j.
The query to use closeness centrality in Cypher is:
CALL algo.closeness.stream('Node', 'LINK')
YIELD nodeId, centrality
RETURN algo.getNodeById(nodeId).id AS node, centrality
ORDER BY centrality DESC
LIMIT 20;
My attempt at a translation to 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
is my class for nodes which have SEES
relationships between them.
The exception I get is:
SyntaxException: Unknown procedure output: `node` (line 2, column 7 (offset:
55))
"YIELD node,centrality"
^
What is the correct C# syntax for this query?
Simple solution - change 'node' for 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;
This returns an IEnumerable where each element is an anonymous type with two properties for the nodeId and its centrality score. Both Int32 = nodeId.As<Int32>()
and Double = centrality.As<Double>()
look like they should be more concise.
The documentation for closeness centrality gives 'node' as the name of the return type but it seems like it should be nodeId.
A useful resource for these cypher to C# translations is the cypher examples page on the Neo4jClient github pages
You are right this query returns nodeId
instead of a node
.
If you want node then your Cypher query should be like this
(I don't know how to translate this in C#, I think you can translate this to get the nodes):
CALL algo.closeness.stream('SitePoint', 'SEES')
YIELD nodeId, centrality
RETURN algo.getNodeById(nodeId) AS node, centrality
ORDER BY centrality DESC
LIMIT 20;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.