Adding a unique component id per network

Dear all,

Thanks to the brillliant request bellow, I'm able to add an ID to each nodes related to the network size where he belongs :

CALL gds.wcc.stream({
nodeProjection: "Entity",
relationshipProjection: "IRW"
})
YIELD nodeId, componentId
WITH componentId, collect(gds.util.asNode(nodeId).EntityID) AS libraries
WITH size(libraries) AS size, libraries
WITH size, apoc.coll.flatten(collect(libraries)) AS nodes_list
CALL apoc.periodic.iterate('
MATCH (n)
WHERE n.EntityID IN $nodes_list
RETURN n
', '
SET n.community_id = $community_id
', {batchSize:1000, params:{nodes_list:nodes_list, community_id:size}}) YIELD batch, operations
RETURN 1

In this case 2 nodes from 2 differnents networks could have the same id.

I would like to keed this ID related to the network size but I would also like to another ID related to the network components (Each network will have a unique ID)
So for each nodes, I will know the network size he belongs and the networks ID he belongs too.

What should I add in this request or should I run another request that will add this ID ?

Thanks in advance !

Hi @1113 !

You already have an ID that works as network ID... The communityId.
So:

CALL gds.wcc.stream({
nodeProjection: "Entity",
relationshipProjection: "IRW"
})
YIELD nodeId, componentId
WITH componentId, collect(nodeId) AS libraries
WITH componentId, size(libraries) AS size, libraries
UNWIND libraries as nodeId
MATCH (n)
WHERE id(n) = nodeId
SET n.community_id = componentId,
n.community_size = size

Bennu