U
    9%e	                     @   s0   d dl mZ d dlZdgZdddZdd ZdS )    )defaultdictNk_clique_communitiesc           	      #   s    dk rt d  d|dkr,t | } fdd|D }tt}|D ]}|D ]}|| | qRqJt  }|| |D ]6}t||D ]&}t	|
| d kr||| qq~t |D ]}tj| V  qdS )u8  Find k-clique communities in graph using the percolation method.

    A k-clique community is the union of all cliques of size k that
    can be reached through adjacent (sharing k-1 nodes) k-cliques.

    Parameters
    ----------
    G : NetworkX graph

    k : int
       Size of smallest clique

    cliques: list or generator
       Precomputed cliques (use networkx.find_cliques(G))

    Returns
    -------
    Yields sets of nodes, one for each k-clique community.

    Examples
    --------
    >>> G = nx.complete_graph(5)
    >>> K5 = nx.convert_node_labels_to_integers(G, first_label=2)
    >>> G.add_edges_from(K5.edges())
    >>> c = list(nx.community.k_clique_communities(G, 4))
    >>> sorted(list(c[0]))
    [0, 1, 2, 3, 4, 5, 6]
    >>> list(nx.community.k_clique_communities(G, 6))
    []

    References
    ----------
    .. [1] Gergely Palla, Imre Derényi, Illés Farkas1, and Tamás Vicsek,
       Uncovering the overlapping community structure of complex networks
       in nature and society Nature 435, 814-818, 2005,
       doi:10.1038/nature03607
       zk=z, k must be greater than 1.Nc                    s    g | ]}t | krt|qS  )len	frozenset).0ckr   d/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/networkx/algorithms/community/kclique.py
<listcomp>2   s      z(k_clique_communities.<locals>.<listcomp>   )nxZNetworkXErrorZfind_cliquesr   listappendZGraphZadd_nodes_from_get_adjacent_cliquesr   intersectionZadd_edgeZconnected_componentsr   union)	Gr   Zcliquesmembership_dictcliquenodeZ
perc_graph
adj_clique	componentr   r
   r   r      s"    &

c                 C   s4   t  }| D ]$}|| D ]}| |kr|| qq
|S )N)setadd)r   r   Zadjacent_cliquesnr   r   r   r   r   H   s    r   )N)collectionsr   Znetworkxr   __all__r   r   r   r   r   r   <module>   s   
@