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.

Creation of new relationships based on other relationships

depire
Node Clone

Hello,
My problem is the following.
I have 4 nodes A B C D.
I have relationships with percentage.
I consider that two nodes are in the same cluster if it exists a relationship with a percentage above 50%.
“A - > B [100]“ means A owns B with 100% share, so A and B must be in the same cluster.
My data are:

  • A->B[100]
  • A->C[100]
  • B->D[40]
  • C->D[30]

So A, B and C are in the same cluster.
But D must be in the same cluster because the relationships between the cluster and D are above 50 (40+30).

Have you an idea to create automatically the correct cluster?
Best regards,
Alexandre

2 REPLIES 2

ameyasoft
Graph Maven

With my little understanding of your scenario, here is my solution.

I created your scenario:

merge (a:Name {name: "A", val: toInteger("100")})
merge (b:Name {name: "B", val: toInteger("100")})
merge (c:Name {name: "C", val: toInteger("100")})
merge (d:Name {name: "D", val: toInteger("30")})
merge (d1:Name {name: "D", val: toInteger("40")})

merge (a)-[:REL]->(b)
merge (a)-[:REL]->(c)
merge (b)-[:REL]->(d1)
merge (c)-[:REL]->(d)
return a, b, c, d, d1

Result:

Run this query:

match (a:Name)
with a.name as name, sum(a.val) as sum1
with collect ({nme: name, sumval: sum1}) as reslt

unwind reslt as row
with row where row.sumval >= 80

return row.nme as name, row.sumval as Val

Result:

Thanks for you help.
But the value of percent is a property of relationship, not of a node.
Moreover, the goal is to build an algorithm (or to reuse one) in order to build a new relationship between the cluster and the node D since the sum of percents is above 50.0. I think that the final relationship created must have "A" as parent; because A is the first common parent of B and C.
Is it more clear ?