
    k*iy#                        S SK Jr  S SKJr  S SKJrJr  S SKJrJ	r	  SSSS.S jr
SSSS.S	 jrSSSS.S
 jrSSSS.S jrSSS.S jrSSS.S jrg)    )annotations)conv_sequences)is_nonesetupPandas)EditopEditopsTN)pad	processorscore_cutoffc               l   Ub  U" U 5      n U" U5      n[        X5      u  pU(       d%  [        U 5      [        U5      :w  a  Sn[        U5      e[        [        U 5      [        U5      5      n[	        [        U 5      [        U5      5      n[        U5       H  nXpU   X   :H  -  nM     Ub  Xt::  a  U$ US-   $ )aL  
Calculates the Hamming distance between two strings.
The hamming distance is defined as the number of positions
where the two strings differ. It describes the minimum
amount of substitutions required to transform s1 into s2.

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
pad : bool, optional
   should strings be padded if there is a length difference.
   If pad is False and strings have a different length
   a ValueError is thrown instead. Defaults is True.
processor: callable, optional
    Optional callable that is used to preprocess the strings before
    comparing them. Default is None, which deactivates this behaviour.
score_cutoff : int or None, optional
    Maximum distance between s1 and s2, that is
    considered as a result. If the distance is bigger than score_cutoff,
    score_cutoff + 1 is returned instead. Default is None, which deactivates
    this behaviour.

Returns
-------
distance : int
    distance between s1 and s2

Raises
------
ValueError
    If s1 and s2 have a different length
"Sequences are not the same length.   )r   len
ValueErrorminmaxrange)	s1s2r	   r
   r   msgmin_lendistis	            ]/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/rapidfuzz/distance/Hamming_py.pydistancer   
   s    V r]r]B#FB3r7c"g%2o#b'3r7#Gs2wB D7^1  !(D,@4W|VWGWW    c                   Ub  U" U 5      n U" U5      n[        X5      u  p[        [        U 5      [        U5      5      n[        XUS9nXV-
  nUb  Xt:  a  U$ S$ )a  
Calculates the Hamming similarity between two strings.

This is calculated as ``len1 - distance``.

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
pad : bool, optional
   should strings be padded if there is a length difference.
   If pad is False and strings have a different length
   a ValueError is thrown instead. Defaults is True.
processor: callable, optional
    Optional callable that is used to preprocess the strings before
    comparing them. Default is None, which deactivates this behaviour.
score_cutoff : int, optional
    Maximum distance between s1 and s2, that is
    considered as a result. If the similarity is smaller than score_cutoff,
    0 is returned instead. Default is None, which deactivates
    this behaviour.

Returns
-------
distance : int
    distance between s1 and s2

Raises
------
ValueError
    If s1 and s2 have a different length
r	   r   )r   r   r   r   )r   r   r	   r
   r   maximumr   sims           r   
similarityr!   G   se    T r]r]B#FB#b'3r7#GB$D
.C'3+>3FQFr   c                  [        5         [        U 5      (       d  [        U5      (       a  gUb  U" U 5      n U" U5      n[        X5      u  p[        [	        U 5      [	        U5      5      n[        XUS9nU(       a  Xe-  OSnUb  Xt::  a  U$ S$ )a  
Calculates a normalized Hamming similarity in the range [1, 0].

This is calculated as ``distance / (len1 + len2)``.

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
pad : bool, optional
   should strings be padded if there is a length difference.
   If pad is False and strings have a different length
   a ValueError is thrown instead. Defaults is True.
processor: callable, optional
    Optional callable that is used to preprocess the strings before
    comparing them. Default is None, which deactivates this behaviour.
score_cutoff : float, optional
    Optional argument for a score threshold as a float between 0 and 1.0.
    For norm_dist > score_cutoff 1.0 is returned instead. Default is 1.0,
    which deactivates this behaviour.

Returns
-------
norm_dist : float
    normalized distance between s1 and s2 as a float between 0 and 1.0

Raises
------
ValueError
    If s1 and s2 have a different length
g      ?r   r   )r   r   r   r   r   r   )r   r   r	   r
   r   r   r   	norm_dists           r   normalized_distancer$   }   s    R Mr{{gbkkr]r]B#FB#b'3r7#GB$D")qI%-1J9TQTTr   c                   [        5         [        U 5      (       d  [        U5      (       a  g[        X5      u  p[        XX#S9nSU-
  nUb  Xd:  a  U$ S$ )a  
Calculates a normalized Hamming similarity in the range [0, 1].

This is calculated as ``1 - normalized_distance``

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
pad : bool, optional
   should strings be padded if there is a length difference.
   If pad is False and strings have a different length
   a ValueError is thrown instead. Defaults is True.
processor: callable, optional
    Optional callable that is used to preprocess the strings before
    comparing them. Default is None, which deactivates this behaviour.
score_cutoff : float, optional
    Optional argument for a score threshold as a float between 0 and 1.0.
    For norm_sim < score_cutoff 0 is returned instead. Default is 0,
    which deactivates this behaviour.

Returns
-------
norm_sim : float
    normalized similarity between s1 and s2 as a float between 0 and 1.0

Raises
------
ValueError
    If s1 and s2 have a different length
g        r	   r
   r   )r   r   r   r$   )r   r   r	   r
   r   r#   norm_sims          r   normalized_similarityr(      sT    R Mr{{gbkkB#FB#BII9}H$,0H8RsRr   r&   c          
        Ub  U" U 5      n U" U5      n[        X5      u  pU(       d%  [        U 5      [        U5      :w  a  Sn[        U5      e/ n[        [        U 5      [        U5      5      n[	        U5       H*  nX   X   :w  d  M  UR                  [        SXw5      5        M,     [	        U[        U 5      5       H(  nUR                  [        SU[        U5      5      5        M*     [	        U[        U5      5       H(  nUR                  [        S[        U 5      U5      5        M*     [        R                  " [        5      n[        U 5      Ul	        [        U5      Ul
        XXl        U$ )ao  
Return Editops describing how to turn s1 into s2.

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
pad : bool, optional
   should strings be padded if there is a length difference.
   If pad is False and strings have a different length
   a ValueError is thrown instead. Defaults is True.
processor: callable, optional
    Optional callable that is used to preprocess the strings before
    comparing them. Default is None, which deactivates this behaviour.

Returns
-------
editops : Editops
    edit operations required to turn s1 into s2
r   replacedeleteinsert)r   r   r   r   r   appendr   r   __new___src_len	_dest_len_editops)	r   r   r	   r
   r   ops_listr   r   opss	            r   editopsr4      s   : r]r]B#FB3r7c"g%2oH#b'3r7#G7^5BE>OOF9a34  7CG$xCG45 % 7CG$xR!45 % //'
"Cr7CLGCMLJr   c               2    [        XX#S9R                  5       $ )ao  
Return Opcodes describing how to turn s1 into s2.

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
pad : bool, optional
   should strings be padded if there is a length difference.
   If pad is False and strings have a different length
   a ValueError is thrown instead. Defaults is True.
processor: callable, optional
    Optional callable that is used to preprocess the strings before
    comparing them. Default is None, which deactivates this behaviour.

Returns
-------
opcodes : Opcodes
    edit operations required to turn s1 into s2
r&   )r4   
as_opcodes)r   r   r	   r
   s       r   opcodesr7   %  s    : 2s8CCEEr   )
__future__r   rapidfuzz._common_pyr   rapidfuzz._utilsr   r   !rapidfuzz.distance._initialize_pyr   r   r   r!   r$   r(   r4   r7    r   r   <module>r=      sw    # / 1 = 	:XB 	3Gt 	6Uz 	1Sp 	8~ 	Fr   