Weakly Connected Components
Introduction
The Weakly Connected Components (WCC) algorithm identifies connected components within a directed graph, disregarding edge direction.
Output
The algorithm outputs the following fields:
Field Name | Description |
---|---|
id | The ID of the vertex (node) |
componentId | A generated integer ID representing the component of the vertex |
Using Cypher
Query Example
CALL algo.wcc({
labels: ['User'],
relationshipTypes: ['LINK'],
seedProperty: 'name',
threshold: 1.0,
maxIterations: 30,
minComponentSize: 5
}) YIELD id, componentId
RETURN id, componentId
Parameters
Name | Description | Required |
---|---|---|
labels | Specifies the node labels to include in the algorithm | Yes |
relationshipTypes | Specifies the relationship types to include | Yes |
relationshipWeightProperty | Defines the property name for edge weights | No |
seedProperty | The node property used as the seed for the component ID | No |
threshold | Minimum edge weight value for it to be included in the algorithm | No |
minComponentSize | Minimum size of the components to be returned | No |
Exporting Query Results
For large datasets, export the results to object storage:
EXPORT TO 's3://my_bucket/target_dir'
PROPERTIES {
catalog: 'puppygraph_catalog_name'
}
CALL algo.wcc({
labels: ['User'],
relationshipTypes: ['LINK'],
relationshipWeightProperty: 'weight',
threshold: 1.0
}) YIELD id, componentId
RETURN id, componentId
Using Gremlin
Query Example
graph.compute().program(
WeakConnectedComponentProgram.build()
.maxIteration(20)
.vertices("User")
.edges("LINK")
.edgeProperties("amount")
.setParam("weight", "amount", "threshold", 10.0)
.create()
).submit().get().toList()
Parameters
Method | Description |
---|---|
maxIteration(int n) | Sets the maximum iteration count, default is 30 |
vertices(String... names) | Specifies the vertex labels to include |
edges(String... names) | Specifies the edge labels to include |
edgeProperties(String... names) | Defines the property name for edge weights |
setParams(Object... args) | Adds additional parameters using alternating keys and values |
Additional Parameters
Key | Description | Default Value |
---|---|---|
weight | Specifies the edge weight property or a constant value as weight | 1.0 |
threshold | Minimum edge weight value for it to be included in the algorithm | 0.0 |
seedProperty | The vertex property used as the component ID seed | "id" |
minComponentSize | Minimum size of the components to be returned | 0 |
Exporting Query Results
For large datasets, use the save()
method to export the results.
graph.compute().program(
WeakConnectedComponentProgram.build()
.maxIteration(20)
.vertices("User")
.edges("LINK")
.edgeProperties("amount")
.setParam("weight", "amount", "threshold", 10.0)
.create()
).submit().get().save([
"exportTo": "s3://my_bucket/target_dir",
"catalog": "puppygraph_catalog_name"
])