Parameters in apoc.periodic.commit

Some nodes are divided into different communities according to a certain attribute value. Now we need to merge according to the number of overlapping nodes (> 2) of the initial community, and re-divide the community.

My code is as follows:

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

How should the bold parameters be expressed?Please give me some advice.Thank you very much!

Hi @ruanlovelin,

Could you please explain the model and requirement.

For example, people go shopping in supermarkets. Some people go to supermarket A to shop, these people are a group A. Another group of people go to supermarket B for shopping, these people are another group B. And so on, we will have many groups. Now we want to regroup the people: if there are at least 3 people in group A and group B, we merge group A and group B into a new group A (or B). This cycle continues until there is no more than 2 weights between groups.
Thank you very much!

It can be understood as a variant of the "Union-Find "。

I look forward to your help and suggestions。Thank you very much!

Hi @ruanlovelin,

**Inserted below data **
'''
Group,Member
A,1
A,2
A,3
A,4
B,3
B,4
B,5
B,6
C,1
C,2
C,3
C,8
D,6
D,9
D,10
'''

** Insert Query **
'''
load csv with headers from 'file:///ruanlovelin.csv' as row
MERGE (g:Group{name:row.Group})
MERGE (m:Member{name:row.Member})
Create(m)-[:MEMBER_OF]->(g)
'''

** Merge Query **

'''Match(g1:Group)<-[:MEMBER_OF]-(m:Member)-[:MEMBER_OF]->(g2:Group)
With g1,g2,size(collect(m)) as coll
Where coll>=3 and id(g1)>id(g2)
Match (m2:Member)-[rel2:MEMBER_OF]->(g1)
Merge (m2)-[rel1:MEMBER_OF]->(g2)
With m2,g1,g2
Match(g1) detach delete g1
Return g2
'''

First of all, thank you very much for taking the time to help me. I didn't make it clear. E.g:
Group A----Member{1,2,3,4}
GroupB------Memeber{3,4,5,6}
GroupC-----Member{1,2,3,8}
GroupD-----Member{6,9,10}
GroupE-----Member{6,9,10,11,12,14}
GroupF-----Member{6,9,13,15,16}
GroupG-----Member{3,4,11,13,15,16}

First iteration:
now Group A----Member{1,2,3,4}
now GroupB----Member{3,4,5,6}
now GroupC-----Member{1,2,3,8}
now GroupD----Member{6,9,10}
now GroupE-----Member{6,9,10,11,12,14}
now GroupF-----Member{6,9,13,15,16}
now GroupG-----Member{3,4,11,13,15,16}
now GroupA1----Member{1,2,3,4,8}
now GroupD1----Member{6,9,10,11,12,14}
now GroupF1-----Member{3,4,6,9,11,13,15,16}

Second iteration:
now Group A----Member{1,2,3,4}
now GroupB----Member{3,4,5,6}
now GroupC-----Member{1,2,3,8}
now GroupD----Member{6,9,10}
now GroupE-----Member{6,9,10,11,12,14}
now GroupF-----Member{6,9,13,15,16}
now GroupG-----Member{3,4,11,13,15,16}
now GroupA2----Member{1,2,3,4,8}
now GroupD2-----Member{3,4,6,9,10,11,12,13,14,15,16}

Third iteration:
now Group A----Member{1,2,3,4}
now GroupB----Member{3,4,5,6}
now GroupC-----Member{1,2,3,8}
now GroupD----Member{6,9,10}
now GroupE-----Member{6,9,10,11,12,14}
now GroupF-----Member{6,9,13,15,16}
now GroupG-----Member{3,4,11,13,15,16}
now GroupA3----Member{1,2,3,4,8}
now GroupD3-----Member{3,4,5,6,9,10,11,12,13,14,15,16}

Result: The original groups are still there, and we also marked the newly divided groups. In other words, A, C make up A3, B, D, E, F, G make up D3.
Thank you very much!