Neo4j's connected component algorithm

For example, there are A, B, C, D, E, F, G, H, I, J, K, L, M, N 14 nodes. A, B, C, D, F, L have a common attribute value x is defined as x community. C, D, E, G, L have a common attribute value y is defined as y community. F, H, I, M have a common attribute value z is defined as z community. H, I, J, K, M, N have a common attribute value w is defined as w community. According to neo4j's connected component algorithm, these 14 nodes are considered as a community. I expect to divide the community according to another standard. I hope to use the number of overlapping nodes as the community division standard. If the "overlapping number is 3" is used as the standard for community division, then A, B, C, D, E, F, G, L are a community, and F, H, I, J, K, M, N As a community.Thank you very much!

I thought of a solution, but there are still some confusion:

  1. Save the node id of each community in a list:match(m:property)<--(n:nodes)
    with m.community,collect(n.id) as list
  2. Use apoc.coll.intersection (first, second) to calculate the intersection of the lists in pairs. If the number of elements in the intersection is> 3, then merge: apoc.coll.union (first, second)
  3. Use apoc.periodic.commit () until the number of elements in the intersection <3.

Code show as below:
CALL apoc.periodic.commit("match(m:property)<--(n:nodes)
with m.community,collect(n.id) as list
where size(apoc.coll.intersection(first,second))>2 LIMIT {limit}
with first,second
apoc.coll.union(first, second)
return size(apoc.coll.intersection(first,second))>2",
{limit:5}
)

What to replace the 'first' and 'second'?Please give me some advice.Thank you very much!