Hi everyone, I'm rather new with neo4j , cypher graphs and all. I have one Multidigraph and would like to find out the degrees of a node. What would be the generic approach to accomplish this? If this was a graph with single unidirected edges between nodes I could just match on edge pattern, but this is not the case in Mutidigraph. So Should I try solve this with a cypher query or a special any other plugin should be used?
Thank you
Can you provide an example? Is just the number of attached nodes
In graph theory, the degree of a vertex is the number of edges connecting it. Think of it as the number of "neighbors" a vertex has in the graph.
Thanks @ameyasoft, that is what I thought. If so, the degree can be determined using the following approach:
match (n)
return n, COUNT{(n)--()} as degree
Thank you both. I guess I was referring to the number of unique neighbors each node has. How should I approach this?
What determines uniqueness other them being separate nodes?
Hi Gary, the nodes have a single label named IP_HOST and each one is identified by unique IP address. I am thinking that perhaps I should aggregate all the edges between a pair of nodes into a single one, then build a new aggregated version of the original graph and count number of aggregated edges, so I could calculate the number of distinct nodes that a single node connects to. Was asking to see if there was any way of doing this in neo4j (cypher or any plugin library) rather than doing this in another graph framework like networkx.
Thanks a lot for your help
Maybe I understand. You could have multiple relationships between that same two IP_HOST nodes and you want to count the number of related nodes. If so, try this:
Test Data:
create(n:IP_HOST{id:0}),(m:IP_HOST{id:1}),(l:IP_HOST{id:2}),(k:IP_HOST{id:3}),(j:IP_HOST{id:4}),(i:IP_HOST{id:5})
create(n)-[:REL1]->(m),(n)-[:REL1]->(m),(n)-[:REL1]->(m)
create(l)<-[:REL2]-(k),(l)<-[:REL2]-(k),(l)<-[:REL2]-(k),(l)<-[:REL2]-(k),(l)<-[:REL2]-(k)
CREATE (n)-[:REL1]->(k),(n)-[:REL1]->(k),(n)-[:REL1]->(i)
create (l)<-[:REL2]-(k),(l)<-[:REL2]-(j),(l)<-[:REL2]-(i),(l)<-[:REL2]-(n)
Test Graph:
Query:
match(n:IP_HOST)--(m)
return n.id, count(distinct m)
Test Graph Results:
Worked perfectly fine!
I knew there was an elegant answer for this, thank you Sensei.
Thanks a lot Gary.
Jorge