Skip to content

Instantly share code, notes, and snippets.

@davidfauth
Created December 1, 2020 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfauth/bbd2aa1abcdb56fb3414358f4ac3aeb8 to your computer and use it in GitHub Desktop.
Save davidfauth/bbd2aa1abcdb56fb3414358f4ac3aeb8 to your computer and use it in GitHub Desktop.
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' }
},
{
HAS_EMAIL: {
type: 'HAS_EMAIL',
orientation: 'NATURAL'
},
HAS_PHONE: {
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