I am trying to compute decimal numbers using graph algorithms and store it in new edges that I create? My code
MATCH path = (a:person) -[:connected_to*]- (b:person)
WHERE id(a) < id(b)
WITH a, b, length(path) as weight
CREATE (a)-[e:co_authors]->(b)
SET e.weight=1/weight
is setting 0 as a the e.weight and not 1/2 or 1/3 or whatever the algorithm finds. How can I work around this?
MATCH path = (a:Business {id:"bFzdJJ3wp3PZssNEsyU23g"}) -[*2..3]- (b:Business {id:"45bWSZtniwPRiqlivpS8Og"})
WHERE id(a) < id(b)
WITH a, b, length(path) as weight
return toFloat(1/weight)
MATCH path = (a:person) -[:connected_to*]- (b:person)
WHERE id(a) < id(b)
WITH a, b, length(path) as weight
CREATE (a)-[:co_authors {weight: toFloat(1/weight)}]->(b)
Sorry I'm not being much help, I'm at a loss at the moment. I'll sit down here in a bit and work on it some more.
Just realized and fixed - below code does the trick. Lesson relearnt: convert variables to float before using it in an expression whose output is float.
MATCH path = (a:person) -[:connected_to*]- (b:person)
WHERE id(a) < id(b)
WITH a, b, tofloat(length(path)) as weight
CREATE (a)-[:co_authors {weight: toFloat(1/weight)}]->(b)