cancel
Showing results for 
Search instead for 
Did you mean: 

How can I display groups of nodes which realized more than n realtionships with different nodes in the graph

mehdi_ajroud
Graph Buddy

I have many groups in my graph , but I want to display only those which worked together more than n times .
And here is an example :

1 ACCEPTED SOLUTION

paul_thomas
Node Clone

Apoc can be installed manually on the community version I'm fairly certain.

You'll you need to download the various apoc jars and copy them to the correct location and re-start Neo4j.

View solution in original post

8 REPLIES 8

paul_thomas
Node Clone

I am not quite sure what you are asking but ...

If you load the sample data in this article https://medium.com/@paul13thomas/graph-analytics-of-shareholder-data-6f6b5333bd1c then install apoc and use apoc's unionFind to find the clusters ...

CALL algo.unionFind(
'match (n) return id(n) as id',
'match (n1:Person)--(n2) return id(n1) as source, id(n2) as target',
{graph:'cypher', write:true, partitionProperty:"clusterId"})
YIELD nodes, setCount, loadMillis, computeMillis, writeMillis;

then to only show the big clusters run

match (n1)
with n1.clusterId as clusterId, count(n1) as clusterSize
where clusterSize > 10
match (n2) where n2.clusterId = clusterId
return n2

That will only bring back 1 cluster which has 15 nodes.

So a similar query to count the number of relationships

match (n1)-[r]-()
with n1.clusterId as clusterId, count(distinct r) as numberOfRels
where numberOfRels > 10
match (n2) where n2.clusterId = clusterId
return n2

again will only show the large cluster.

This would seem to work if this is what you are looking to do ...

mehdi_ajroud
Graph Buddy

I will try it and let you know . Btw there is no access to the link ! I am having 404 not found when I open it

mehdi_ajroud
Graph Buddy

I am using community version , I cannot apply the clustering algo !

mehdi_ajroud
Graph Buddy

What if I use this query ?

match (n1:attribfxplaf)-[r]-()
with n1.clusterId as clusterId, count(n1) as clusterSize,count(distinct r) as numberOfRels
where clusterSize > 10 AND  numberOfRels > 10
match (n2) where n2.clusterId = clusterId
return n2,clusterId

yes that looks like it should work ...

Thanks Paul ! It works yes 🙂

paul_thomas
Node Clone

Apoc can be installed manually on the community version I'm fairly certain.

You'll you need to download the various apoc jars and copy them to the correct location and re-start Neo4j.

Hello Paul!

I have read the Medium article and I foun it very helpful.
However, I would like to know one thing.

In the example, for plotting the relations between compnay and persons (the two labels) we have to write all the relations. Here you have it:

(p1)-[:OWNER {holding:45}]->(c1)<-[:OWNER {holding:55}]-(p2),
(p2)-[:OWNER {holding:70}]->(c2)<-[:OWNER {holding:30}]-(p3),
(p3)-[:OWNER {holding:60}]->(c3)<-[:OWNER {holding:40}]-(p1)

I was wondering if it could be possible to, instead of writting all this code, using a loop (foreach statement) as we could do with Python.

Thanks!!

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.