
    wnhw%                        d dl mZ d dlZd dlZ	 ddlmZ ddl
mZ ej                  ej                  ej                  d	                      Zej                  ej                  ej                  d
                      ZddZej                  dd       ZddZddZej                  dd       ZddZddZddZddZddZddZy# e$ r/  ej                         dk7  r ej                  d       d dl	mZ Y w xY w)    )unicode_literalsN   )StringMatcherPyPyzYUsing slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning)SequenceMatcher)utilsc                     t        j                  | |      \  } }t        d | |      }t        j                  d|j	                         z        S )Nd   )r   make_type_consistentr   intrratio)s1s2ms      P/var/www/html/profi_bot/bot/venv/lib/python3.12/site-packages/fuzzywuzzy/fuzz.pyr   r      sA     ''B/FBb"%A::cAGGIo&&    c                    t        j                  | |      \  } }t        |       t        |      k  r| }|}n|}| }t        d||      }|j	                         }g }|D ]e  }|d   |d   z
  dkD  r|d   |d   z
  nd}|t        |      z   }	|||	 }
t        d||
      }|j                         }|dkD  r y|j                  |       g t        j                  dt        |      z        S )zR"Return the ratio of the most similar substring
    as a number between 0 and 100.Nr   r   gףp=
?r
   )	r   r   lenr   get_matching_blocksr   appendr   max)r   r   shorterlongerr   blocksscoresblock
long_startlong_endlong_substrm2rs                r   partial_ratior"      s     ''B/FB
2w#b'gv.A""$F F-21Xa-@A,EU1Xa(1
G,Z1T7K8HHJt8MM!  ::cCK'((r   c                     |rt        j                  | |      n| }|j                         }dj                  t	        |            }|j                         S )z*Return a cleaned string with token sorted.force_ascii )r   full_processsplitjoinsortedstrip)sr%   r'   tstokenssorted_strings         r   _process_and_sortr0   K   sI     <H		A;	7QBXXZF IIfVn-M  r   c                 n    t        | ||      }t        |||      }|rt        ||      S t        ||      S )Nr'   )r0   r"   r   )r   r   partialr%   r'   sorted1sorted2s          r   _token_sortr6   Z   s;    KlKGKlKGWg..Wg&&r   c                 "    t        | |d||      S )zpReturn a measure of the sequences' similarity between 0 and 100
    but sorting the token before comparing.
    Fr3   r%   r'   r6   r   r   r%   r'   s       r   token_sort_ratior;   e   s     r2u+T`aar   c                 "    t        | |d||      S )z}Return the ratio of the most similar substring as a number between
    0 and 100 but sorting the token before comparing.
    Tr8   r9   r:   s       r   partial_token_sort_ratior=   l   s     r2tS_``r   c                 $   |s| |k(  ry|rt        j                  | |      n| }|rt        j                  ||      n|}t        j                  |      syt        j                  |      syt        |j	                               }t        |j	                               }|j                  |      }	|j                  |      }
|j                  |      }dj                  t        |	            }dj                  t        |
            }dj                  t        |            }|dz   |z   }|dz   |z   }|j                         }|j                         }|j                         }|rt        }nt        } |||       |||       |||      g}t        |      S )a	  Find all alphanumeric tokens in each string...
        - treat them as a set
        - construct two strings of the form:
            <sorted_intersection><sorted_remainder>
        - take ratios of those two strings
        - controls for unordered partial matchesr
   r$   r   r&   )r   r'   validate_stringsetr(   intersection
differencer)   r*   r+   r"   r   r   )r   r   r3   r%   r'   p1p2tokens1tokens2rA   diff1to2diff2to1sorted_sectsorted_1to2sorted_2to1combined_1to2combined_2to1
ratio_funcpairwises                      r   
_token_setrP   s   sq    B"H<H		BK	8bB<H		BK	8bB  $  $ "((*oG"((*oG''0L!!'*H!!'*H((6,/0K((6(+,K((6(+,K#%3M#%3M ##%K!'')M!'')M"

 	;.;.=-0H
 x=r   c                 "    t        | |d||      S )NFr8   rP   r:   s       r   token_set_ratiorS      s    b"eS_``r   c                 "    t        | |d||      S )NTr8   rR   r:   s       r   partial_token_set_ratiorU      s    b"dR^__r   c                     |r/t        j                  | |      }t        j                  ||      }n| }|}t        j                  |      syt        j                  |      syt        ||      S )a  
    Quick ratio comparison between two strings.

    Runs full_process from utils on both strings
    Short circuits if either of the strings is empty after processing.

    :param s1:
    :param s2:
    :param force_ascii: Allow only ASCII characters (Default: True)
    :full_process: Process inputs, used here to avoid double processing in extract functions (Default: True)
    :return: similarity ratio
    r$   r   )r   r'   r?   r   )r   r   r%   r'   rC   rD   s         r   QRatiorW      sc     <<  $  $R=r   c                      t        | |d|      S )z
    Unicode quick ratio

    Calls QRatio with force_ascii set to False

    :param s1:
    :param s2:
    :return: similarity ratio
    Fr%   r'   )rW   r   r   r'   s      r   UQRatior[      s     "be,GGr   c                    |r/t        j                  | |      }t        j                  ||      }n| }|}t        j                  |      syt        j                  |      syd}d}d}t        ||      }	t	        t        t        |      t        |                  t        t        |      t        |            z  }
|
dk  rd}|
dkD  rd	}|rXt        ||      |z  }t        ||d
      |z  |z  }t        ||d
      |z  |z  }t        j                  t        |	|||            S t        ||d
      |z  }t        ||d
      |z  }t        j                  t        |	||            S )aj  
    Return a measure of the sequences' similarity between 0 and 100, using different algorithms.

    **Steps in the order they occur**

    #. Run full_process from utils on both strings
    #. Short circuit if this makes either string empty
    #. Take the ratio of the two processed strings (fuzz.ratio)
    #. Run checks to compare the length of the strings
        * If one of the strings is more than 1.5 times as long as the other
          use partial_ratio comparisons - scale partial results by 0.9
          (this makes sure only full results can return 100)
        * If one of the strings is over 8 times as long as the other
          instead scale by 0.6

    #. Run the other ratio functions
        * if using partial ratio functions call partial_ratio,
          partial_token_sort_ratio and partial_token_set_ratio
          scale all of these by the ratio based on length
        * otherwise call token_sort_ratio and token_set_ratio
        * all token based comparisons are scaled by 0.95
          (on top of any partial scalars)

    #. Take the highest value from these results
       round it and return it as an integer.

    :param s1:
    :param s2:
    :param force_ascii: Allow only ascii characters
    :type force_ascii: bool
    :full_process: Process inputs, used here to avoid double processing in extract functions (Default: True)
    :return:
    r$   r   Tgffffff?g?g      ?F   g333333?r2   )r   r'   r?   r   floatr   r   minr"   r=   rU   r   r;   rS   )r   r   r%   r'   rC   rD   try_partialunbase_scalepartial_scalebase	len_ratior3   ptsorptsertsortsers                   r   WRatiori      sg   F <<  $  $ KLMR=Dc#b'3r7+,s3r7CG/DDI 3 1}B'-7(ReD*+'BUC*+ zz#dGUE:;;BU;lJr2E:\Izz#dD$/00r   c                      t        | |d|      S )zReturn a measure of the sequences' similarity between 0 and 100,
    using different algorithms. Same as WRatio but preserving unicode.
    FrY   )ri   rZ   s      r   UWRatiork   .  s     "be,GGr   )T)TTT)TT)
__future__r   platformwarningsr   r   ImportErrorpython_implementationwarndifflib r   check_for_nonecheck_for_equivalencecheck_empty_stringr   r"   r0   r6   r;   r=   rP   rS   rU   rW   r[   ri   rk    r   r   <module>rx      s+   (  (?  '   ' ")   ")R! ' 'ba 1 1ha`:
HK1\HK	  (%x%%'61qr'(s   C 1C;:C;