def k_clique_communities(G, k, cliques=None):
 if (k < 2):
  raise nx.NetworkXError(('k=%d, k must be greater than 1.' % k))
 if (cliques is None):
  cliques = nx.find_cliques(G)
 cliques = [frozenset(c) for c in cliques if (len(c) >= k)]
 membership_dict = defaultdict(list)
 for clique in cliques:
  for node in clique:
   membership_dict[node].append(clique)
 perc_graph = nx.Graph()
 perc_graph.add_nodes_from(cliques)
 for clique in cliques:
  for adj_clique in _get_adjacent_cliques(clique, membership_dict):
   if (len(clique.intersection(adj_clique)) >= (k - 1)):
    perc_graph.add_edge(clique, adj_clique)
 for component in nx.connected_components(perc_graph):
  (yield frozenset.union(*component))

def k_clique_communities ( G , k , cliques = None ) : if ( k < 2 ) : raise nx . NetworkXError ( ( 'k=%d, k must be greater than 1.' % k ) ) if ( cliques is None ) : cliques = nx . find_cliques ( G ) cliques = [ frozenset ( c ) for c in cliques if ( len ( c ) >= k ) ] membership_dict = defaultdict ( list ) for clique in cliques : for node in clique : membership_dict [ node ] . append ( clique ) perc_graph = nx . Graph ( ) perc_graph . add_nodes_from ( cliques ) for clique in cliques : for adj_clique in _get_adjacent_cliques ( clique , membership_dict ) : if ( len ( clique . intersection ( adj_clique ) ) >= ( k - 1 ) ) : perc_graph . add_edge ( clique , adj_clique ) for component in nx . connected_components ( perc_graph ) : ( yield frozenset . union ( * component ) )
find k-clique communities in graph using the percolation method .