Multiple relationshipProjection for degree centrality

I have unit nodes and event nodes that are connected with 2 types of relationships named "FROM" and "TO". There are multiple event nodes and they are connected with another different relationship ("NEXT")
I want to calculate degree centrality of unit nodes and want to consider both "FROM" and "TO" edges.
I can only get one type of relationship using below query.

example : degree centrality of unit nodes considering "FROM" edges

CALL gds.degree.stream({
                      nodeProjection: ['Unit','Event'],
                      relationshipProjection: {all: {type:'FROM',orientation:'REVERSE'}}
                    })
                    YIELD nodeId, score
                    RETURN gds.util.asNode(nodeId).name AS unit, score AS degree_centrality
                    ORDER BY degree_centrality DESC

Is there a way to include both "FROM" and "TO" relationshipProjection to get degree centrality of unit nodes considering both "FROM" and "TO"?
I used "*" , but it gives all other edges between events ("NEXT") as well.

relationshipProjection: {all: {type:'*',orientation:'REVERSE'}}

Hi @krishwera

Just as you are specifying more than one node label in the nodeProjection, you can specify more than one relationship type in your relationshipProjection. Does something like this get you started in the right direction?

CALL gds.degree.stream({
                      nodeProjection: ['Unit','Event'],
                      relationshipProjection: {
                            FROM: {type:'FROM', orientation:'REVERSE'},
                            TO: {type:'TO', orientation:'REVERSE'}
                     }
                    })
                    YIELD nodeId, score
                    RETURN gds.util.asNode(nodeId).name AS unit, score AS degree_centrality
                    ORDER BY degree_centrality DESC
1 Like

I also have found this blog post helpful in working with multigraphs in GDS. Analyzing multigraphs in Neo4j Graph data science library | by Tomaz Bratanic | Towards Data Science

1 Like

Hi @nsmith_piano

Thank you so much. It works like a charm.
Thank you for the link to the article too. Will definitely check it out!

1 Like