Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-28-2021 07:22 PM
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'}}
Solved! Go to Solution.
09-28-2021 07:52 PM
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
09-28-2021 07:52 PM
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
09-28-2021 07:55 PM
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
09-28-2021 07:59 PM
Thank you so much. It works like a charm.
Thank you for the link to the article too. Will definitely check it out!
All the sessions of the conference are now available online