
    c
                     d    d dl Z d dlmZmZ  e j        e          Z G d dej                  ZdS )    N)
interfacesmatutilsc                   2    e Zd ZdZd	dZd Zd Zd Zd ZdS )
	NormModelzPObjects of this class realize the explicit normalization of vectors (l1 and l2).Nl2c                 F    || _         ||                     |           dS dS )aN  Compute the l1 or l2 normalization by normalizing separately for each document in a corpus.

        If :math:`v_{i,j}` is the 'i'th component of the vector representing document 'j', the l1 normalization is

        .. math:: l1_{i, j} = \frac{v_{i,j}}{\sum_k |v_{k,j}|}

        the l2 normalization is

        .. math:: l2_{i, j} = \frac{v_{i,j}}{\sqrt{\sum_k v_{k,j}^2}}


        Parameters
        ----------
        corpus : iterable of iterable of (int, number), optional
            Input corpus.
        norm : {'l1', 'l2'}, optional
            Norm used to normalize.

        N)norm	calc_norm)selfcorpusr	   s      7lib/python3.11/site-packages/gensim/models/normmodel.py__init__zNormModel.__init__   s0    ( 	 	NN6"""""D    c                 P    | j         j        d| j        d| j        d| j        dS )Nz
<num_docs=z
, num_nnz=z, norm=>)	__class____name__num_docsnum_nnzr	   )r   s    r   __str__zNormModel.__str__+   s2    N###T]]]DLLL$)))
 	
r   c                    t                               d| j                   g }d}d}|D ]F}|dz  }|t          |          z  }|                    t          j        || j                             G|| _        || _        || _	        dS )zCalculate the norm by calling :func:`~gensim.matutils.unitvec` with the norm parameter.

        Parameters
        ----------
        corpus : iterable of iterable of (int, number)
            Input corpus.

        zPerforming %s normalization...r      N)
loggerinfor	   lenappendr   unitvecr   r   norms)r   r   r   numnnzdocnobows         r   r
   zNormModel.calc_norm0   s     	4di@@@ 	; 	;CQJEc#hhFLL)#ty99::::


r   c                 :    t          j        || j                  }|S )a  Normalize a simple count representation.

        Parameters
        ----------
        bow : list of (int, number)
            Document in BoW format.

        Returns
        -------
        list of (int, number)
            Normalized document.


        )r   r   r	   )r   r!   vectors      r   	normalizezNormModel.normalizeE   s     !#ty11r   c                 ,    |                      |          S )a  Call the :func:`~gensim.models.normmodel.NormModel.normalize`.

        Parameters
        ----------
        bow : list of (int, number)
            Document in BoW format.

        Returns
        -------
        list of (int, number)
            Normalized document.

        )r$   )r   r!   s     r   __getitem__zNormModel.__getitem__W   s     ~~c"""r   )Nr   )	r   
__module____qualname____doc__r   r   r
   r$   r&    r   r   r   r      sj        ZZ   4
 
 

  *  $# # # # #r   r   )	logginggensimr   r   	getLoggerr   r   TransformationABCr   r*   r   r   <module>r/      s{     ' ' ' ' ' ' ' '		8	$	$W# W# W# W# W#
, W# W# W# W# W#r   