Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Neo4j WCC Example
// Data was randomly generated data
// Create the Graph
CALL gds.graph.create(
'wcc-graph', {
Customer: { label: 'Customer' },
Email: { label: 'Email' },
Phone: { label: 'Phone' }
type: 'HAS_EMAIL',
orientation: 'NATURAL'
type: 'HAS_PHONE',
orientation: 'NATURAL'
YIELD graphName, nodeCount, relationshipCount;
// Estimate Stats
CALL gds.wcc.stats('wcc-graph')
YIELD componentCount;
// Run wcc and store results in memory
CALL gds.wcc.mutate('wcc-graph', { mutateProperty: 'componentId' })
YIELD nodePropertiesWritten, componentCount;
// Write in-memory property to graph
CALL gds.wcc.write('wcc-graph', { writeProperty: 'componentId' })
YIELD nodePropertiesWritten, componentCount;
// Create Index
CREATE INDEX componentID FOR (n:Customer) ON (n.componentId);
// Examine communities
match (n:Customer) return n.componentId, count(n) as numComponents
order by numComponents desc limit 20;
// Display a community
match (n:Customer) where n.componentId=216
with n
match path= (n)-[:HAS_EMAIL|HAS_PHONE]->()
return path;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment