cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to Visualize Secondary Relationships?


So I have this network (screenshot above) of Research Publications. I am trying to visualize which Institutions (pink) are publishing together.
Each Publication (brown) has Author nodes (blue) connected by the AUTHORED relationship. Each Author has an AFFILIATED_WITH relationship to an Institution.

I am trying to visualize which Institutions share a common Publication together and have been really struggling with how to do this with Cypher

4 REPLIES 4

intouch_vivek
Graph Steward

Hi @athahireen.

You can try below

Match(p:Publication)-[:AUTHORED]->(a:Author)-[:AFFILIATED_WITH]->(i:Institution)
With p, collect(distinct i) as institutions
CALL apoc.nodes.link(institutions , 'SAME_PUB')
Return p

Hi! Thank you for the help, but the direction of the relationship between Author and Publication goes Author - AUTHORED -> Publication which is what I'm struggling with

What is happening when you try

Match(p:Publication)<-[:AUTHORED]-(a:Author)-[:AFFILIATED_WITH]->(i:Institution)
With p, collect(distinct i) as institutions
CALL apoc.nodes.link(institutions , 'SAME_PUB')
Return p

mark3
Node Link

Off the top of my head, you could try:

MATCH(i1:Institution)<-[:AFFILIATED_WITH]-(a1:Author)-[:AUTHORED]->(p:Publication)<-[AUTHORED]-(a2:Author)-[:AFFILIATED_WITH]->(i2:Institution)
WHERE id(i1) <> id(i2)
RETURN i1, i2, p, a1, a2

The WHERE will ensure that the query doesn't go back to the same publication if more that one author has worked on it.

As I said, this is off the top of my head. I haven't tried it out, so:
a) it may not work
b) it might take forever to run, depending on how much data you have