I want to regroup large amounts of connected nodes

Hi,

I have a graph, that contains persons that are all linked via Link nodes and therefore kept together in groups using a Group node. (See step 1)
It should be possible to delete links, which results in seperated clusters of linked persons still remaining in the same group. (See step 2)
I need a query that reorganizes the clusters and give them seperate group nodes. (See step 3)

I have tried to accomplish this by iterating through the connected persons on the originating group and doing an aopc.subgraph on the LINKS_TO edges to get a cluster and reattach them to a new group node. But when I do a subgraph starting with Person "B", i later have not to do it for Person "C" and "D", because they are already in a new group (Maybe Blacklist them for the subgraph method, but how?). Can anybody help solving this without GDS library (I did it with projection and weakly connected component search, but this is overkill and I don't want to use the GDS library)

To create the sample graph with the lost links:
CREATE (n6:Person {Name: "D"})-[:LINKS_TO]->(:Link)<-[:LINKS_TO]-(:Person {Name: "B"})-[:IS_PART]->(n0:Group)<-[:IS_PART]-(:Person {Name: "C"})-[:LINKS_TO]->(:Link)<-[:LINKS_TO]-(n6),
(n6)-[:IS_PART]->(n0)<-[:IS_PART]-(:Person {Name: "A"}),
(n0)<-[:IS_PART]-(:Person {Name: "E"})-[:LINKS_TO]->(:Link)<-[:LINKS_TO]-(:Person {Name: "F"})-[:IS_PART]->(n0)

Thanks for suggestions...

Try this:
Step 1: 
match (a:Person)-[r]->(b:Group)
where a.Name = "A"
merge (a)-[:IS_PART]->(n0:Group1)
delete r
return a, n0

Step 2:

match (a:Person)-[r]->(b:Group)
where a.Name = "E"
match (c:Person)-[r1]->(b)
where c.Name = "F"

merge (a)-[:IS_PART]->(n:Group2)
merge (c)-[:IS_PART]->(n)
delete r
delete r1
return a, c, n

Result:

Thanks for your suggestion,

I don't need to solve the sample by directly attaching the nodes together :joy:.

I will have millions of nodes and groups of some hunderts or thousands. So, I need an algorithm which analyzes the situation for one starting node with type of person which might start a restructuring of involved clusters.
For example a person links to another person in another cluster, or links are removed and the cluster is splitted in more clusters. And we talk also about a combination of both...

I don't fully understand the flow from your first message to your last - but perhaps look at it from a different perspective?

why not have the design as tiers from the group:

(Group)-[:connects]->(Link)-[:hasMember]->(Person)

Sort of a spanning tree, and when your links change it is easier to evaluate.

Try apoc.nodes.collapse