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.

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'}}
1 ACCEPTED SOLUTION

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

View solution in original post

3 REPLIES 3

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

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!