This is my initial graph.
I created a cypher projection(memory graph) and ran the node similarity algorithm to find nodes that are similar to the node 'AE2001'. I ran it in stream mode, creating a relationship 'SIMILAR' having a property 'score' which has the similarity score(we got from the result of the algorithm) between the nodes. (I did not use write mode because it created 2 relationships for every node).
This is my code for the memory graph:
My code to run the algorithm:
YIELD node1, node2, similarity
WITH gds.util.asNode(node1) AS n1, gds.util.asNode(node2) AS n2, similarity
SET s.score = similarity
RETURN n1, n2, similarity
order by similarity desc
My graph after creating the relationships looks like this:
I want to show all the similarity pairs with the relationships they have in common. (In this case, I should get the 3 following pairs:
- Node AE2001 and Node AE0001
- Node AE2001 and Node AE007
- Node AE2001 and Node AE0005
I am attaching the picture for the first case below for more clarity
I researched a lot but couldn't find a solution. Any help is greatly appreciated. Thanks in advance!
PS: Apologies for the last image, I just used the eraser tool in paint
Would something like this work? So if two nodes have a SIMILARITY relationship, you would like to see all other nodes the both have relationships as well?
where id(e1) < id(e2)
with e1, e2
Hi @johnmattgrogan , thanks for your reply. This will not work because I have multiple relationships of type 'SIMILAR' going out from the node 'AE2001'. I want to get the node pairs with 'SIMILAR' relationship. This querry gave me the following result.
On the other hand, I wanted to return pairs of nodes (of type Adverse_Event) having all the common nodes, as I showed in my main post picture 3.
I see. Is the problem having more than two Adverse_Event nodes displaying in the same graph? Is it looks, the only difference between your picture 3 and the picture with my query is the additional 'AE007' and 'AE0005' nodes. However, I could be miss understanding what your asking
You are correct. That is the only difference. I want to compare 'AE2001' with all the other nodes one by one, and the only problem in your query is we're getting 'AE007' and 'AE0005' nodes.
Gotcha. So are you wanting to visualize these pairs relationships in the Neo4j browsers? When you specify the patttern (n)-[:SIMILAR]->(m) the cypher will connect all nodes together that match this pattern. This pattern is then rendered in the browser.
If you need the individual pairs visualization and the number of nodes is small you could hard code those individual nodes into the browser and get a new viz for each query. On the other hand, if you have any experience using using Python and one of the drivers (py2neo, neo4j) you can write a little script to query each of the pairs and return the data for later processing.
I'm not saying there isn't another way to do this, however to the best of my knowledge there is no way to "plot" pairs of non distinct nodes in the same visualization. However, I'll leave this open to any others out there who know better then I.
Thanks for your quick reply Matt. I am using Neovis to visualize the graph in an HTML file. I have also worked with neo4j(python driver) before and I can use a loop to compare it node-wise. Thanks for the suggestion
Great! If you get something that works I’d love to see what you did. I’ve never really used any of the viz techniques outside the browser so I’d be very interested in seeing that.