Created
December 1, 2020 14:02
-
-
Save davidfauth/bbd2aa1abcdb56fb3414358f4ac3aeb8 to your computer and use it in GitHub Desktop.
Neo4j WCC Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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