I have the following graph
MERGE (a:Node{id:"A"})
MERGE (b:Node{id:"B"})
MERGE (c:Node{id:"C"})
MERGE (d:Node{id:"D"})
MERGE (e:Node{id:"E"})
MERGE (a)-[:LINK]->(b)
MERGE (b)-[:LINK]->(c)
MERGE (d)-[:LINK]->(c)
MERGE (e)-[:LINK]->(d);
which is a directed version of the graph in Closeness Centrality - Neo4j Graph Data Science
If I want undirected, unweighted version of closeness centrality, I use
CALL algo.closeness.stream(
'MATCH (n:Node) RETURN id(n) AS id',
"MATCH (n)-[:LINK]-(m:Node) RETURN id(n) AS source, id(m) AS target",
{graph: "cypher"})
YIELD nodeId, centrality
RETURN algo.asNode(nodeId).id AS node, centrality
which is indeed correct - the directionality is taken care in the cypher projection, but not with the option "direction: "BOTH" - if the option is available.
On the other hand, if I need directed, unweighted option, using cypher projection or not, using
CALL algo.closeness.stream(
'MATCH (n:Node) RETURN id(n) AS id',
"MATCH (n)-[:LINK]->(m:Node) RETURN id(n) AS source, id(m) AS target",
{graph: "cypher", direction: "OUTGOING"})
YIELD nodeId, centrality
RETURN algo.asNode(nodeId).id AS node, centrality
ORDER BY centrality DESC
LIMIT 20;
returns
node | centrality |
---|---|
"B" | 1.0 |
"D" | 1.0 |
"C" | 0.0 |
"E" | 0.0 |
"A" | 0.0 |
which needs some explanation from the algorithms team. They are not reflective of "directed paths" either. Using any variation of the code, dropping "direction:" parameter in the above code - all return the same answer.