0

I can find the highest densely connected component in the graph using the code below:

CALL algo.unionFind.stream('', ':pnHours', {})
YIELD nodeId,setId
// groupBy setId, storing all node ids of the same set id into a list
MATCH (node) where id(node) = nodeId
WITH setId, collect(node) as nodes
// order by the size of nodes list descending
ORDER BY size(nodes) DESC
LIMIT 1 // limiting to 3
RETURN nodes;

But it does not help me visualize the topmost densely connected component (sub-graph) because the output graph it emits are disjoint nodes. Is it possible to visualize the densely connected component. If yes, then how

enter image description here

Jannat Arora
  • 2,759
  • 8
  • 44
  • 70
  • If you return only the topmost node in the query result and double click it in web console, it should visualize all the connected nodes with relationships.. – Rahul Jan 31 '19 at 04:50
  • @Rahul I have attached picture of graph I get. This is not connected. I want to see the relationships between the nodes – Jannat Arora Jan 31 '19 at 05:58
  • @Rahul Clicking on individual nodes does not work for me because there are too many – Jannat Arora Jan 31 '19 at 06:00
  • You can use the node id of the topmost node returned from your query to get all the connected nodes and relationships: match (n:node)-{rel}-(m) where id(n)=*topmost nodeid* return * – Rahul Jan 31 '19 at 06:24
  • @Rahul Sure is *topmost nodeid* a keyword. If not how do I find the topmost nodeid – Jannat Arora Jan 31 '19 at 06:26
  • Are you getting only the disconnected nodes(as in your screenshot) when you double click on the topmost node returned from query? – Rahul Jan 31 '19 at 06:27
  • it's not a keyword. Every node has an automatically generated identifier(a number) called node id. Click on the topmost node in web console to see it. – Rahul Jan 31 '19 at 06:29
  • @Rahul Clicking on individual nodes does not work for me because there are too many and on clicking the nodes only the immediate neighborhood nodes get expanded. Thus I do not get the fully connected view of the graph – Jannat Arora Jan 31 '19 at 06:56
  • ok, did the query worked? It should be -[rel]- instead of -{rel}- in the query that I wrote.. If the query is also showing disjoint nodes, then you can use limit to visualize a small number of nodes at a time. Also, if you just want to look at the data(visualization not necessary), then you can check the query result in notepad.. – Rahul Jan 31 '19 at 08:55

3 Answers3

0

I tried this query but I am getting different the result.

I haven't used these algorithms and I don't know much about it, but I think you added an extra character (colon) in the query.

Can you check with pnHours instead of :pnHours.

I remove colon(:) from the query and I am getting the proper result (also I am able to get the relationships as well because Neo4j browser fetches it although it's not specified in the query).

If you still don't get check the following query:

CALL algo.unionFind.stream('', 'pnHours', {})
YIELD nodeId,setId
// groupBy setId, storing all node ids of the same set id into a list
MATCH (node) where id(node) = nodeId
WITH setId, collect(node) as nodes
// order by the size of nodes list descending
ORDER BY size(nodes) DESC
LIMIT 1 // limiting to 3
WITH nodes
UNWIND nodes AS node
MATCH (node)-[r:pnHours]-()
RETURN node,r;
Rajendra Kadam
  • 4,004
  • 1
  • 10
  • 24
0

If you want to visualize then in Neo4j browser then use:

CALL algo.unionFind.stream('', ':pnHours', {})
YIELD nodeId,setId
// groupBy setId, storing all node ids of the same set id into a list
MATCH p=(node)-->() where id(node) = nodeId
WITH setId, collect(p) as paths
// order by the size of nodes list descending
ORDER BY size(paths) DESC
LIMIT 1 // limiting to 3
// Maybe you need to unwind paths to be able to visualize in Neo4j browser
RETURN paths;

It is not the most optimized query but should do just fine on small datasets.

Tomaž Bratanič
  • 6,319
  • 2
  • 18
  • 31
0

The following query should return all the single-step paths in the largest pnHours-connected component (i.e., the one having the most nodes). It only gets the paths for the largest component.

CALL algo.unionFind.stream(null, 'pnHours', {}) YIELD nodeId, setId
WITH setId, COLLECT(nodeId) as nodeIds
ORDER BY SIZE(nodeIds) DESC
LIMIT 1
UNWIND nodeIds AS nodeId
MATCH path = (n)-[:pnHours]->()
WHERE ID(n) = nodeId
RETURN path

The neo4j browser's Graph visualization of the results will show all the nodes in the component and their relationships.

cybersam
  • 63,203
  • 6
  • 53
  • 76