How can make groups/clusters , based on the weight of the relationship


(Mehdi Ajroud) #1

I started by uploading my database and then I set the weight for all relationships by running this query :

match (a:Attributaires)--(h:Attributaires)
with a, count(h) as AttributaireCount
match (a)-[r]-()
set r.weight = AttributaireCount

Now I want to regroup/put in clusters , all '"Attributaires" that have the same relationships' weight .
How can I make this ? thanks in advance everyone :)


(Bratanic Tomaz) #2

If i understand correctly from you are trying to find groups of nodes that have the same number of relationships.

I don't know how you want them returned but here is a simple query that would return that stream results:

MATCH (a:Attributaires)
WITH a, size((a)--()) as number_of_rels
RETURN number_of_rels,collect(a) as members

If you want to write back results in the graph you could do:

MATCH (a:Attributaires)
WITH a, size((a)--()) as number_of_rels
MERGE (cluster:Cluster{size: number_of_rels})
MERGE (a)-[:PART_OF]->(cluster)