cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a unique component id per network

1113
Node Clone

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 !

2 REPLIES 2

Bennu
Graph Fellow

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

1113
Node Clone

Hi,

Sorry for the late feedback and thank you very much for your answer !

All the best !