0
votes

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;

SitePointis 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?

2
What have you tried so far?belwood
The Cypher query doesn't change with C# or any other programming language. Just find how to connect neo4j using C#Rajendra Kadam
@Raj - my question should have been clearer - I am using Neo4jClient a .Net client for neo4j. And belwood - also adding my initial attempt to translate the query. Editing the question to include this information.rolyH

2 Answers

0
votes

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

0
votes

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;