cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

The problem with "apoc.coll.union"

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.

In the past few days I tried to use py2neo to solve this problem in python. But I think the efficiency of loop traversal is relatively slow. So I think whether it can be solved directly with neo4j。For example,apoc.coll.intersection(first, second)、apoc.coll.union(first, second)、apoc.periodic.commit()。
Thank you very much!

2 REPLIES 2

Can you please explain better what you want to do. Didn’t understand

Sorry, my English is poor. There are 7 groups (here is an example), there may be duplicate nodes (the number is not the same) between groups, or there may not be. We need to regroup according to the number of repeated nodes (in this case, the standard is 3). In the end, the original group logo still exists. The nodes in the regrouped group are distinguished by a regenerated attribute value or label value. Similar to the result of Union-Find algorithm.
Thank you very much!