6.14. Complex similarity computations
Calculate similarities by complex calculations
Here, a similarity between two players in a game is calculated by the number of times they have eaten the same food.
Query
MATCH (me { name: 'me' })[r1:ATE]>(food)<[r2:ATE](you) WITH me,count(DISTINCT r1) AS H1,count(DISTINCT r2) AS H2,you MATCH (me)[r1:ATE]>(food)<[r2:ATE](you) RETURN sum((1ABS(r1.times/H1r2.times/H2))*(r1.times+r2.times)/(H1+H2)) AS similarity
The two players and their similarity measure.
Result
similarity 

1 row 

Try this query live create (_0 {`name`:"me"}) create (_1 {`name`:"meat"}) create (_2 {`name`:"you"}) create (_0)[:`ATE` {`times`:10}]>(_1) create (_2)[:`ATE` {`times`:5}]>(_1) MATCH (me {name: 'me'})[r1:ATE]>(food)<[r2:ATE](you) WITH me,count(distinct r1) as H1,count(distinct r2) as H2,you MATCH (me)[r1:ATE]>(food)<[r2:ATE](you) RETURN sum((1ABS(r1.times/H1r2.times/H2))*(r1.times+r2.times)/(H1+H2)) as similarity