public int buildCommunities(Graph hgraph) {
   int[] comStructure = new int[hgraph.getNodeCount()];
   computeModularity(hgraph, structure, comStructure, resolution);
   Set<Integer> communityCount = new HashSet<>();
   int idx = 0;
   for (Node n : hgraph.getNodes()) {
     communityCount.add(comStructure[idx]);
     n.setProperty("communityID", comStructure[idx++]);
   }
   return communityCount.size();
 }