apache-sparkneo4jcypherstrongly-connected-graphneo4j-mazerunner

Visualize Strongly Connected Components result using Cypher


I've used neo4j-mazerunner to analyze strongly_connected_components relationship on my graph. The process has ended and now I got the strongly_connected_components property on my nodes.

I have used the following query to get rows of nodes distinct nodes:

MATCH (n) WHERE has(n.strongly_connected_components)
RETURN DISTINCT "node" as element, n.strongly_connected_components
AS strongly_connected_components
LIMIT 25 UNION ALL MATCH ()-[r]-()
WHERE has(r.strongly_connected_components)
RETURN DISTINCT "relationship" AS element, r.strongly_connected_components 
AS strongly_connected_components LIMIT 25

I'm not sure how to cypher query the graph in order to visualize the generated clusters.

Any help would be appericiated.


Solution

  • This query should return 25 clusters, and you should be able to visualize each cluster in the browser as strongly connected nodes. The query assumes that FOO was the relationship specified to neo4j-mazerunner when asking it to generate the strongly_connected_components values.

    NOTE: Turn OFF the browser's AUTO-COMPLETE feature (in the lower right-hand corner of the result pane) to only see the FOO relationships between the nodes in each cluster:

    MATCH p=(n1)-[:FOO]->()
    RETURN n1.strongly_connected_components AS clusterId, COLLECT(p) AS paths
    LIMIT 25;
    

    Since neo4j-mazerunner assigns the same strongly_connected_components value to all the nodes in the same cluster, this query simply aggregates all the paths with the same strongly_connected_components value (identified as clusterId).