Have GDS Similarity write to existing relationship

Hi,

Scenario:

I have 3 basic node labels: Document, Classification, and Word and I am running some similarity algorithms against them. Basically I am finding documents that share similar classification connections and separately I am finding documents that share similar words (in abstract). I have used nodeSimilarity and it does seem to produce the desired result with one exception between nodes I have multiple relationships each with a score for the node similarity.

andy_hegedus_0-1655155728766.png

For a given pair there are four relationships (in this case) all labeled Similar since that is the term I used as the write property and each relationship contains one score value.

What I would like is 1 pair of relationships with the different scores as properties of that relationship.

Have

A - Similar - B classScore 0.98

A - Similar - B wordScore 0.95

...

I would like a singular relationship akin to to a merge statement that would contain the score values.

Is there a simple way to force GDS.algorithm.write to execute the equivalent of a merge statement and just append a new score or change an existing one?

Andy

Hello @andy_hegedus :blush:

  1. The first solution is to use the stream function instead of write and manually create the relation at the end.
  2. The second solution is to merge all the relations when all the calculations are done. (Make sure to have a different name for each written property and SIMILAR relations must have the same direction or it won't work)
MATCH (a)-[r:SIMILAR]-(b)
WITH a, b, collect(r) AS relations
CALL apoc.refactor.mergeRelationships(relations, {properties: "combine"})
YIELD rel
RETURN count(*)

Regards,

Cobra

I have added a feature request.

Andy

I think you can raise it as a feature request on the repository to merge the results instead of just adding new relationships.

https://github.com/neo4j/graph-data-science/issues