Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active August 18, 2019 14:34
Show Gist options
  • Save vladbatushkov/23c4b8d7212979871c6a07f9e05a809a to your computer and use it in GitHub Desktop.
Save vladbatushkov/23c4b8d7212979871c6a07f9e05a809a to your computer and use it in GitHub Desktop.
Apply Degree Centrality vs calculate it Manualy
// algorithm
CALL algo.degree.stream("City", "CONNECT_WITH", { direction: "both", weightProperty: "calls" }) YIELD nodeId, score
RETURN algo.asNode(nodeId).name AS name, score
ORDER BY score DESC
// manual calculation
MATCH (c:City)-[cw:CONNECT_WITH]-(:City)
RETURN c.name as name, SUM(cw.calls) as score
ORDER BY score DESC
// projection
CALL algo.degree(
'MATCH (c:City) RETURN id(c) as id',
'MATCH (c1:City)<-[:FROM]-(:Person)-[OUT]->(:Call)<-[]-(:Person)-[:FROM]->(c2:City) WHERE id(c1) <> id(c2) RETURN id(c1) as source, id(c2) as target',
{ graph:'cypher', write: true, writeProperty: "degree" }
)
// compare
MATCH (c:City)-[cw:CONNECT_WITH]-(:City)
WITH c.name as name, c.population as population, c.calls as internal, SUM(cw.calls) as external
RETURN name, population, internal + external as total
ORDER BY population DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment