403Webshell
Server IP : 54.37.205.81  /  Your IP : 216.73.216.76
Web Server : nginx/1.22.1
System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64
User : debian ( 1000)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/nltk/cluster/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/nltk/cluster/__pycache__/util.cpython-311.pyc
�

 T�c&���ddlZddlmZddlmZddlmZ	ddlZn#e$rYnwxYwddl	m
Z
Gd�de
��Zd�Zd	�Z
Gd
�d��ZGd�d
��ZdS)�N)�abstractmethod)�sqrt)�stdout)�ClusterIc�l�eZdZdZd
d�Zdd�Zed���Zd�Zed���Z	d	�Z
d
�Zd�Zd�Z
dS)�VectorSpaceClustererz�
    Abstract clusterer which takes tokens and maps them into a vector space.
    Optionally performs singular value decomposition to reduce the
    dimensionality.
    FNc�0�d|_||_||_dS)a)
        :param normalise:       should vectors be normalised to length 1
        :type normalise:        boolean
        :param svd_dimensions:  number of dimensions to use in reducing vector
                                dimensionsionality with SVD
        :type svd_dimensions:   int
        N)�_Tt�_should_normalise�_svd_dimensions)�self�	normalise�svd_dimensionss   �3/usr/lib/python3/dist-packages/nltk/cluster/util.py�__init__zVectorSpaceClusterer.__init__s!�����!*���-�����c����t|��dksJ��jr"tt�j|����}�jr��jt|d��kr�tj�t
j	t
j
|������\}}}|d�j�t
j�jtj��z}|dd�d�j�f}|d�j�dd�f}	t
j	t
j
||	����}t
j	|���_��||��|r�fd�|D��SdS)Nrc�:��g|]}��|����S�)�classify)�.0�vectorr
s  �r�
<listcomp>z0VectorSpaceClusterer.cluster.<locals>.<listcomp>?s%���@�@�@�f�D�M�M�&�)�)�@�@�@r)�lenr�list�map�
_normaliser�numpy�linalg�svd�	transpose�array�identity�float64�dotr
�cluster_vectorspace)
r
�vectors�assign_clusters�trace�u�d�vt�S�T�Dts
`         r�clusterzVectorSpaceClusterer.cluster(sr����7�|�|�a������!�	:��3�t���8�8�9�9�G���	*�D�$8�3�w�q�z�?�?�$J�$J���)�)�%�/�%�+�g�:N�:N�*O�*O�P�P�J�Q��2��(�D�(�(�)�E�N��$�e�m�-�-��A��!�!�!�+�t�+�+�+�,�A��*�d�*�*�A�A�A�-�.�B��o�e�i��2�&6�&6�7�7�G���q�)�)�D�H�	
� � ��%�0�0�0��	A�@�@�@�@��@�@�@�@�	A�	Arc��dS)zD
        Finds the clusters using the given set of vectors.
        Nr)r
r'r)s   rr&z(VectorSpaceClusterer.cluster_vectorspaceA����rc���|jr|�|��}|j�tj|j|��}|�|��}|�|��S�N)rrr
rr%�classify_vectorspace�cluster_name)r
rr0s   rrzVectorSpaceClusterer.classifyGs`���!�	-��_�_�V�,�,�F��8���Y�t�x��0�0�F��+�+�F�3�3��� � ��)�)�)rc��dS)zN
        Returns the index of the appropriate cluster for the vector.
        Nr�r
rs  rr5z)VectorSpaceClusterer.classify_vectorspaceOr2rc��|jr|�|��}|j�tj|j|��}|�||��Sr4)rrr
rr%�likelihood_vectorspace)r
r�labels   r�
likelihoodzVectorSpaceClusterer.likelihoodUsO���!�	-��_�_�V�,�,�F��8���Y�t�x��0�0�F��*�*�6�5�9�9�9rc�@�|�|��}||krdndS)zP
        Returns the likelihood of the vector belonging to the cluster.
        g�?g)r5)r
rr0�	predicteds    rr:z+VectorSpaceClusterer.likelihood_vectorspace\s+���-�-�f�5�5�	���*�*�s�s��3rc��|jr|�|��}|j�tj|j|��}|S)zU
        Returns the vector after normalisation and dimensionality reduction
        )rrr
rr%r8s  rrzVectorSpaceClusterer.vectorcs@���!�	-��_�_�V�,�,�F��8���Y�t�x��0�0�F��
rc�L�|ttj||����zS)z7
        Normalises the vector to unit length.
        �rrr%r8s  rrzVectorSpaceClusterer._normalisems#����U�Y�v�v�6�6�7�7�7�7r)FN)FF)�__name__�
__module__�__qualname__�__doc__rr0rr&rr5r<r:rrrrrrrs���������
.�
.�
.�
.�A�A�A�A�2����^��
*�*�*�����^��
:�:�:�4�4�4����8�8�8�8�8rrc�P�||z
}ttj||����S)z}
    Returns the euclidean distance between vectors u and v. This is equivalent
    to the length of the vector (u - v).
    rA)r*�v�diffs   r�euclidean_distancerIts'��

�q�5�D���	�$��%�%�&�&�&rc	��dtj||��ttj||����ttj||����zzz
S)zw
    Returns 1 minus the cosine of the angle between vectors v and u. This is
    equal to ``1 - (u.v / |u||v|)``.
    �)rr%r)r*rGs  r�cosine_distancerL}sG��

��	�!�Q���4��	�!�Q���#8�#8�4��	�!�Q���;P�;P�#P�Q�R�Rrc�,�eZdZdZd�Zdd�Zd�Zd�ZdS)	�_DendrogramNodezTree node of a dendrogram.c�"�||_||_dSr4)�_value�	_children)r
�value�childrens   rrz_DendrogramNode.__init__�s�����!����rTc��|jr6g}|jD]*}|�|�|�����+|S|r|jgS|gSr4)rQ�extend�leavesrP)r
�valuesrV�childs    rrVz_DendrogramNode.leaves�sa���>�	��F���
4�
4���
�
�e�l�l�6�2�2�3�3�3�3��M�
�	��K�=� ��6�Mrc���|j|fg}t|��|kr�|���\}}|js|�||f��nl|jD]=}|jr|�|j|f���&|�d|f���>|���t|��|k��g}|D],\}}|�|������-|S�Nr)rPr�poprQ�push�append�sortrV)r
�n�queue�priority�noderX�groupss       rrcz_DendrogramNode.groups�s����+�t�$�%���%�j�j�1�n�n�"�Y�Y�[�[�N�H�d��>�
��
�
�H�d�+�,�,�,����
-�
-���?�-��L�L�%�,��!6�7�7�7�7��L�L�!�U��,�,�,�,��J�J�L�L�L��%�j�j�1�n�n���#�	)�	)�N�H�d��M�M�$�+�+�-�-�(�(�(�(��
rc�>�t|j|j��dkSrZ)rLrP)r
�
comparators  r�__lt__z_DendrogramNode.__lt__�s���t�{�J�,=�>�>��B�BrN)T)rBrCrDrErrVrcrfrrrrNrN�s`������$�$�"�"�"�	�	�	�	����*C�C�C�C�CrrNc�8�eZdZdZgfd�Zd�Zd�Zgfd�Zd�ZdS)�
Dendrograma
    Represents a dendrogram, a tree with a specified branching order.  This
    must be initialised with the leaf items, then iteratively call merge for
    each branch. This class constructs a tree representing the order of calls
    to the merge function.
    c�r�d�|D��|_tj|j��|_d|_dS)zs
        :param  items: the items at the leaves of the dendrogram
        :type   items: sequence of (any)
        c�,�g|]}t|����Sr)rN)r�items  rrz'Dendrogram.__init__.<locals>.<listcomp>�s ��?�?�?���t�,�,�?�?�?rrKN)�_items�copy�_original_items�_merge)r
�itemss  rrzDendrogram.__init__�s9��
@�?��?�?�?���#�y���5�5�������rc����t|��dksJ�t�jg�fd�|D���R�}�xjdz
c_|�j|d<|dd�D]
}�j|=�dS)a=
        Merges nodes at given indices in the dendrogram. The nodes will be
        combined which then replaces the first node specified. All other nodes
        involved in the merge will be removed.

        :param  indices: indices of the items to merge (at least two)
        :type   indices: seq of int
        �c3�2�K�|]}�j|V��dSr4)rl)r�ir
s  �r�	<genexpr>z#Dendrogram.merge.<locals>.<genexpr>�s)�����-N�-N��d�k�!�n�-N�-N�-N�-N�-N�-NrrKrN)rrNrorl)r
�indicesrbrts`   r�mergezDendrogram.merge�s�����7�|�|�q� � � � ��t�{�O�-N�-N�-N�-N�g�-N�-N�-N�O�O�O�����q����"&���G�A�J�������	�	�A���A���	�	rc��t|j��dkrt|jg|j�R�}n
|jd}|�|��S)z�
        Finds the n-groups of items (leaves) reachable from a cut at depth n.
        :param  n: number of groups
        :type   n: int
        rKr)rrlrNrorc)r
r_�roots   rrczDendrogram.groups�sO���t�{���a���"�4�;�=���=�=�=�D�D��;�q�>�D��{�{�1�~�~�rc�B�����d\}}}t|j��dkrt|jg|j�R�}n
|jd}|j}|r|}nd�|D��}tt
t|����dz��dz�t��z
dz
���d��fd�	�d�}|j|fg}	�fd	�|D��}
|	�r�|	�	��\}}tt
d
�|j����}
tt
|j|
����}|
rt|��}t|��}tt|����D]�}|||
vr_||kr|�|d|����n3||kr|�||d����n|�|||�����|��|
|<�k||cxkr|krnn|�|||������||
|����|d��|jD]%}|jr|	�|j|f���&|	���|
D]
}||���|d��|	���|d��fd
�|D������|d��dS)z�
        Print the dendrogram in ASCII art to standard out.

        :param leaf_labels: an optional list of strings to use for labeling the
                            leaves
        :type leaf_labels: list
        )�+�-�|rKrc�"�g|]}d|jz��
S)z%s)rP)r�leafs  rrz#Dendrogram.show.<locals>.<listcomp>�s��>�>�>�t��t�{�*�>�>�>rrr� c� ���|z�|�|�z��Sr4r)�centre�left�right�lhalf�rhalfs   ��r�formatzDendrogram.show.<locals>.format�s!����d�l�;�F�;�E�E�M�;�;�;rc�.�tj|��dSr4)r�write)�strs r�displayz Dendrogram.show.<locals>.display�s���L������rc�&��g|]
}�d����S)r�r)rrr�s  �rrz#Dendrogram.show.<locals>.<listcomp>s!���4�4�4�T�V�V�C�[�[�4�4�4rc�8�|�d��dS)NFr)rV)�cs r�<lambda>z!Dendrogram.show.<locals>.<lambda>s�����%����1C�r�
�c3�B�K�|]}|����V��dSr4)�center)rrk�widths  �rruz"Dendrogram.show.<locals>.<genexpr>#s/�����@�@�t����E�*�*�@�@�@�@�@�@rN)r�r�)rrlrNrorn�maxr�intrPr[rrQ�index�min�ranger]r^�join)r
�leaf_labels�JOIN�HLINK�VLINKryrV�last_rowr�r`�	verticalsrarb�child_left_leafrv�min_idx�max_idxrtrX�verticalr�r�r�r�s                    @@@@r�showzDendrogram.show�sX������+���e�U��t�{���a���"�4�;�=���=�=�=�D�D��;�q�>�D��%���	?�"�H�H�>�>�v�>�>�>�H��C��X�&�&�'�'�!�+����
���E�E�M�A�%�&�&��	<�	<�	<�	<�	<�	<�	<�	�	�	��+�t�$�%��4�4�4�4�V�4�4�4�	��	�"�Y�Y�[�[�N�H�d�"�3�'C�'C�T�^�#T�#T�U�U�O��3�v�|�_�=�=�>�>�G��
'��g�,�,���g�,�,���3�v�;�;�'�'�
*�
*���!�9��/�/��G�|�|�����t�S�%� 8� 8�9�9�9�9��g�������t�U�C� 8� 8�9�9�9�9�����t�U�E� :� :�;�;�;�#)�6�%�=�=�I�a�L�L���,�,�,�,�W�,�,�,�,�,��G�F�F�5�%��7�7�8�8�8�8��G�I�a�L�)�)�)�)��G�D�M�M�M���
8�
8���?�8��L�L�%�,��!6�7�7�7���J�J�L�L�L�%�
"�
"�����!�!�!�!��G�D�M�M�M�9�	�>	�����@�@�@�@�x�@�@�@�@�@�A�A�A����
�
�
�
�
rc���t|j��dkrt|jg|j�R�}n
|jd}|�d��}dt|��zS)NrKrFz<Dendrogram with %d leaves>)rrlrNrorV)r
ryrVs   r�__repr__zDendrogram.__repr__&s_���t�{���a���"�4�;�=���=�=�=�D�D��;�q�>�D����U�#�#��,�s�6�{�{�:�:rN)	rBrCrDrErrwrcr�r�rrrrhrh�s��������� �������� 
�
�
� "�G�G�G�G�R;�;�;�;�;rrh)rm�abcr�mathr�sysrr�ImportError�nltk.cluster.apirrrIrLrNrhrrr�<module>r�sK������������������������	��L�L�L�L���	�	�	��D�	����&�%�%�%�%�%�\8�\8�\8�\8�\8�8�\8�\8�\8�~'�'�'�S�S�S�(C�(C�(C�(C�(C�(C�(C�(C�V|;�|;�|;�|;�|;�|;�|;�|;�|;�|;s��%�%

Youez - 2016 - github.com/yon3zu
LinuXploit