
    xnh                    |    d dl mZ d dlmZ d dlmZmZ d Zd Zd Z	d Z
ddd	d
Zddd	dZddd	dZddd	dZy)    )annotations)conv_sequences)is_nonesetupPandasc                P    |dz  }d}||| z  z  }|||z  z  }|||z
  |z  z  }|dz  S )N           g      @ )pattern_lentext_lencommon_charstranspositionssims        [/var/www/html/profi_bot/bot/venv/lib/python3.12/site-packages/rapidfuzz/distance/Jaro_py.py_jaro_calculate_similarityr   	   sM    qN
C<+%%C<(""CL>)\99C9    c                F    | r|syt        | |t        | |      d      }||k\  S )zC
    filter matches below score_cutoff based on string lengths
    Fr   )r   min)r   r   score_cutoffr   s       r   _jaro_length_filterr      s/     h
$[(CX<VXY
ZC,r   c                .    |syt        | ||d      }||k\  S )zY
    filter matches below score_cutoff based on string lengths and common characters
    Fr   )r   )r   r   r   r   r   s        r   _jaro_common_char_filterr      s%     
$[(L!
LC,r   c                    t        |       }t        |      }d}||kD  r|dz  dz
  }|||z   kD  r!|d||z    }n|dz  dz
  }|||z   kD  r| d||z    } | ||fS )zB
    find bounds and skip out of bound parts of the sequences
    r   r      N)len)s1s2r   r   bounds        r   _jaro_boundsr   (   s     b'K2wH E+A!kE)))kE)*Bq 1$E))&h&'Br5=r   N	processorr   c                  t                t        |       st        |      ry| ||       }  ||      }| s|sy|d}t        | |      \  } }t        |       }t        |      }t	        |||      sy|dk(  r|dk(  rt        | d   |d   k(        S t        | |      \  } }}dg|z  }dg|z  }d}	t        |       D ]Y  \  }
}t        d|
|z
        }t        |
|z   |dz
        }t        ||dz         D ]!  }||   r	||   |k(  sdx||
<   ||<   |	dz  }	 Y [ t        |||	|      sydx}}t        |      D ]6  \  }
}|s	t        ||      D ]  }||   s	|dz   } n | |
   |   k7  s2|dz  }8 t        |||	|      S )a  
    Calculates the jaro similarity

    Parameters
    ----------
    s1 : Sequence[Hashable]
        First string to compare.
    s2 : Sequence[Hashable]
        Second string to compare.
    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 ratio < score_cutoff 0 is returned instead. Default is None,
        which deactivates this behaviour.

    Returns
    -------
    similarity : float
        similarity between s1 and s2 as a float between 0 and 1.0
    r	         ?r   r   FT)r   r   r   r   r   floatr   	enumeratemaxr   ranger   r   )r   r   r!   r   r   r   r   s1_flagss2_flagsr   is1_chlowhijktrans_counts1_fs                     r   
similarityr2   =   s   : Mr{gbkr]r]bB#FBb'K2wH {HlCaHMRUbe^$$ R(MBEw$Hw!H LbM5!QYUHqL)sBF#AA;2a5E>,00hqk!	 $ " $K<V AX&41h'A;AA ( !u1~q  ' &k8\;WWr   c                    t        | |||      S )a  
    Calculates the normalized jaro similarity

    Parameters
    ----------
    s1 : Sequence[Hashable]
        First string to compare.
    s2 : Sequence[Hashable]
        Second string to compare.
    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 ratio < score_cutoff 0 is returned instead. Default is None,
        which deactivates this behaviour.

    Returns
    -------
    normalized similarity : float
        normalized similarity between s1 and s2 as a float between 0 and 1.0
    r    )r2   r   r   r!   r   s       r   normalized_similarityr5      s    : b"	MMr   c                   t                t        |       st        |      ry| ||       }  ||      }||dkD  rdnd|z
  }t        | ||      }d|z
  }|||k  r|S dS )a  
    Calculates the jaro distance

    Parameters
    ----------
    s1 : Sequence[Hashable]
        First string to compare.
    s2 : Sequence[Hashable]
        Second string to compare.
    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 ratio < score_cutoff 0 is returned instead. Default is None,
        which deactivates this behaviour.

    Returns
    -------
    distance : float
        distance between s1 and s2 as a float between 1.0 and 0.0
    r#   N)r   )r   r   r2   )r   r   r!   r   cutoff_distancer   dists          r   distancer9      sy    : Mr{gbkr]r]+3|c7IdPSVbPbO
R/
:C9D (DL,@4JsJr   c                    t        | |||      S )a  
    Calculates the normalized jaro distance

    Parameters
    ----------
    s1 : Sequence[Hashable]
        First string to compare.
    s2 : Sequence[Hashable]
        Second string to compare.
    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 ratio < score_cutoff 0 is returned instead. Default is None,
        which deactivates this behaviour.

    Returns
    -------
    normalized distance : float
        normalized distance between s1 and s2 as a float between 1.0 and 0.0
    r    )r9   r4   s       r   normalized_distancer;      s    : BilKKr   )
__future__r   rapidfuzz._common_pyr   rapidfuzz._utilsr   r   r   r   r   r   r2   r5   r9   r;   r
   r   r   <module>r?      s`    # / 12 WX| NH (K^ Lr   