
    cg                     D    d Z ddlZ ej        e          Zd Zd Zd ZdS )zKThis module contains functions to perform segmentation on a list of topics.    Nc                     g }| D ]]}g }t          |dd                   D ],\  }}|d|dz            D ]}|                    ||f           -|                    |           ^|S )a  Performs segmentation on a list of topics.

    Notes
    -----
    Segmentation is defined as
    :math:`s_{pre} = {(W', W^{*}) | W' = w_{i}; W^{*} = {w_j}; w_{i}, w_{j} \in W; i > j}`.

    Parameters
    ----------
    topics : list of np.array
        list of topics obtained from an algorithm such as LDA.

    Returns
    -------
    list of list of (int, int)
        :math:`(W', W^{*})` for all unique topic ids.

    Examples
    --------
    .. sourcecode:: pycon

        >>> import numpy as np
        >>> from gensim.topic_coherence import segmentation
        >>>
        >>> topics = [np.array([1, 2, 3]), np.array([4, 5, 6])]
        >>> segmentation.s_one_pre(topics)
        [[(2, 1), (3, 1), (3, 2)], [(5, 4), (6, 4), (6, 5)]]

       N	enumerateappend)topicss_one_pre_res	top_wordss_one_pre_tw_prime_indexw_primew_stars          Clib/python3.11/site-packages/gensim/topic_coherence/segmentation.py	s_one_prer      s    < M * *	&/	!""&>&> 	6 	6"M7#$6]Q%6$67 6 6""GV#455556[))))    c                     g }| D ]a}g }t          |          D ]8\  }}t          |          D ]#\  }}||k    r|                    ||f           $9|                    |           b|S )a  Perform segmentation on a list of topics.
    Segmentation is defined as
    :math:`s_{one} = {(W', W^{*}) | W' = {w_i}; W^{*} = {w_j}; w_{i}, w_{j} \in W; i \neq j}`.

    Parameters
    ----------
    topics : list of `numpy.ndarray`
        List of topics obtained from an algorithm such as LDA.

    Returns
    -------
    list of list of (int, int).
        :math:`(W', W^{*})` for all unique topic ids.

    Examples
    -------
    .. sourcecode:: pycon

        >>> import numpy as np
        >>> from gensim.topic_coherence import segmentation
        >>>
        >>> topics = [np.array([1, 2, 3]), np.array([4, 5, 6])]
        >>> segmentation.s_one_one(topics)
        [[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)], [(4, 5), (4, 6), (5, 4), (5, 6), (6, 4), (6, 5)]]

    r   )r   s_one_one_resr
   s_one_one_tr   r   w_star_indexr   s           r   	s_one_oner   8   s    6 M * *	&/	&:&: 	: 	:"M7(1)(<(< : :$f L0 :&&'89999	:
 	[))))r   c                 z    g }| D ]5}g }|D ]}|                     ||f           |                     |           6|S )a  Perform s_one_set segmentation on a list of topics.
    Segmentation is defined as
    :math:`s_{set} = {(W', W^{*}) | W' = {w_i}; w_{i} \in W; W^{*} = W}`

    Parameters
    ----------
    topics : list of `numpy.ndarray`
        List of topics obtained from an algorithm such as LDA.

    Returns
    -------
    list of list of (int, int).
        :math:`(W', W^{*})` for all unique topic ids.

    Examples
    --------
    .. sourcecode:: pycon

        >>> import numpy as np
        >>> from gensim.topic_coherence import segmentation
        >>>
        >>> topics = [np.array([9, 10, 7])]
        >>> segmentation.s_one_set(topics)
        [[(9, array([ 9, 10,  7])), (10, array([ 9, 10,  7])), (7, array([ 9, 10,  7]))]]

    )r   )r   s_one_set_resr
   s_one_set_tr   s        r   	s_one_setr   b   se    6 M * *	  	5 	5G34444[))))r   )__doc__logging	getLogger__name__loggerr   r   r    r   r   <module>r!      sb    R Q 		8	$	$' ' 'T' ' 'T# # # # #r   