Hi,
I am using the node similarity algorithm. When I write the output as relationships, it is creating bidirectional edges for some of the nodes:
Person1 |
Person2 |
similarity |
"Alice" |
"Bob" |
0.666666666666667 |
"Bob" |
"Alice" |
0.666666666666667 |
Considering the above example, I want to write only one edge between Alice and Bob with the similarity score. How can I do that?
Thanks
AFAIK, you can only do this as post-processing with a Cypher statement as there is no configuration option to store only a single relationship between a pair of nodes.
Could you please help me with the cypher query? I tried the one below, it did not work:
MATCH (p1:Person)-[r:SIMILAR]-(p2:Person) with p1, p2, r limit 1 delete r
Thanks a lot!
Yeah, the LIMIT
is global, so you only delete a single relationship. You can use something like ->
MATCH (a)-[r:SIMILAR]-(b)
WITH a, b, collect(r) as rels
WHERE size(rels) = 2
UNWIND tail(rels) as rel
DELETE rel
If you have a big graph, you might want to batch this using operation.
1 Like
Hi @bratanic_tomaz,
I noticed that this cypher command deletes all the relationships between some of the nodes. I just need to delete one of the bidirectional edges between the nodes.
Thanks