Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active August 21, 2019 16:36
Show Gist options
  • Save vladbatushkov/dd3157a01bb5368c01fe2fde73cf771f to your computer and use it in GitHub Desktop.
Save vladbatushkov/dd3157a01bb5368c01fe2fde73cf771f to your computer and use it in GitHub Desktop.
Community Detection in city
CALL algo.scc(
'MATCH (p:Person)-[:FROM]->(:City { name: "Bangkok" }) RETURN id(p) as id',
'MATCH (p1:Person)-[:OUT]->(:Call)<-[:IN]-(p2:Person) RETURN id(p1) as source, id(p2) as target',
{ write: true, writeProperty: 'communityId', graph:'cypher' })
YIELD communityCount
MATCH (p:Person)-[:FROM]->(:City { name: "Bangkok" })
WITH p.name as name, p.communityId as communityId
RETURN communityId, count(name) as total
ORDER BY total DESC
// show community ring
MATCH (p:Person { communityId: 17 })-[:OUT]->(c:Call)
RETURN p, c
// apply to all cities
MATCH (c:City)
UNWIND c.name as cityName
CALL algo.scc(
'MATCH (p:Person)-[:FROM]->(:City { name: "' + cityName + '" }) RETURN id(p) as id',
'MATCH (p1:Person)-[:OUT]->(:Call)<-[:IN]-(p2:Person) RETURN id(p1) as source, id(p2) as target',
{ write: true, writeProperty: 'communityId', graph:'cypher' })
YIELD communityCount
MATCH (p:Person)-[:FROM]->(:City { name: cityName })
WITH cityName, p.name as name, p.communityId as communityId
RETURN cityName, communityId, count(name) as total
ORDER BY total DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment