
    d4                        d dl mZ d dlZd dlmZmZmZ d dlmZm	Z	m
Z
mZmZ dddddd$dZddd%dZddddd&dZddddd'dZdddd(dZdddd(dZd ddd!d)d#ZdS )*    )annotationsN)CallableHashableSequence)EditopHammingJaroJaroWinklerLevenshtein)   r   r   )weights	processormaxscore_cutoffs1Sequence[Hashable]s2r   tuple[int, int, int] | Noner   (Callable[..., Sequence[Hashable]] | Noner   
int | Noner   returnintc               t    t          j        dt          d           |p|}t          j        | ||||          S )a[  
    Calculates the minimum number of insertions, deletions, and substitutions
    required to change one sequence into the other according to Levenshtein with custom
    costs for insertion, deletion and substitution

    Parameters
    ----------
    s1 : Sequence[Hashable]
        First string to compare.
    s2 : Sequence[Hashable]
        Second string to compare.
    weights : Tuple[int, int, int] or None, optional
        The weights for the three operations in the form
        (insertion, deletion, substitution). Default is (1, 1, 1),
        which gives all three operations a weight of 1.
    processor: callable, optional
        Optional callable that is used to preprocess the strings before
        comparing them. Default is None, which deactivates this behaviour.
    max : int or None, optional
        Maximum distance between s1 and s2, that is
        considered as a result. If the distance is bigger than max,
        max + 1 is returned instead. Default is None, which deactivates
        this behaviour.

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

    Raises
    ------
    ValueError
        If unsupported weights are provided a ValueError is thrown

    .. deprecated:: 2.0.0
        Use :func:`rapidfuzz.distance.Levenshtein.distance` instead.
        This function will be removed in v3.0.0.

    Examples
    --------
    Find the Levenshtein distance between two strings:

    >>> from rapidfuzz.string_metric import levenshtein
    >>> levenshtein("lewenstein", "levenshtein")
    2

    Setting a maximum distance allows the implementation to select
    a more efficient implementation:

    >>> levenshtein("lewenstein", "levenshtein", max=1)
    2

    It is possible to select different weights by passing a `weight`
    tuple.

    >>> levenshtein("lewenstein", "levenshtein", weights=(1,1,2))
    3
    z\This function will be remove in v3.0.0. Use rapidfuzz.distance.Levenshtein.distance instead.   
stacklevelr   r   r   )warningswarnDeprecationWarningr   distance)r   r   r   r   r   r   s         [/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/rapidfuzz/string_metric.pylevenshteinr#      sX    F Mf   
  &3L
B9<       r   list[Editop]c                   t          j        dt          d           t          j        | ||                                          S )a  
    Return list of 3-tuples describing how to turn s1 into s2.
    Each tuple is of the form (tag, src_pos, dest_pos).

    The tags are strings, with these meanings:
    'replace':  s1[src_pos] should be replaced by s2[dest_pos]
    'delete':   s1[src_pos] should be deleted.
    'insert':   s2[dest_pos] should be inserted at s1[src_pos].

    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.

    Returns
    -------
    editops : list[]
        edit operations required to turn s1 into s2

    .. deprecated:: 2.0.0
        Use :func:`rapidfuzz.distance.Levenshtein.editops` instead.
        This function will be removed in v3.0.0.

    Examples
    --------
    >>> from rapidfuzz.string_metric import levenshtein_editops
    >>> for tag, src_pos, dest_pos in levenshtein_editops("qabxcd", "abycdf"):
    ...    print(("%7s s1[%d] s2[%d]" % (tag, src_pos, dest_pos)))
     delete s1[1] s2[0]
    replace s1[3] s2[2]
     insert s1[6] s2[5]
    z[This function will be remove in v3.0.0. Use rapidfuzz.distance.Levenshtein.editops instead.r   r   r%   )r   r   r    r   editopsas_list)r   r   r   s      r"   levenshtein_editopsr*   Z   sM    V Me   
 r2;;;CCEEEr$   r   float | Nonefloatc               r    t          j        dt          d           t          j        | ||||          dz  S )al  
    Calculates a normalized levenshtein distance using custom
    costs for insertion, deletion and substitution.

    Parameters
    ----------
    s1 : Sequence[Hashable]
        First string to compare.
    s2 : Sequence[Hashable]
        Second string to compare.
    weights : Tuple[int, int, int] or None, optional
        The weights for the three operations in the form
        (insertion, deletion, substitution). Default is (1, 1, 1),
        which gives all three operations a weight of 1.
    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 100.
        For ratio < score_cutoff 0 is returned instead. Default is 0,
        which deactivates this behaviour.

    Returns
    -------
    similarity : float
        similarity between s1 and s2 as a float between 0 and 100

    Raises
    ------
    ValueError
        If unsupported weights are provided a ValueError is thrown

    .. deprecated:: 2.0.0
        Use :func:`rapidfuzz.distance.Levenshtein.normalized_similarity` instead.
        This function will be removed in v3.0.0.

    See Also
    --------
    levenshtein : Levenshtein distance

    Examples
    --------
    Find the normalized Levenshtein distance between two strings:

    >>> from rapidfuzz.string_metric import normalized_levenshtein
    >>> normalized_levenshtein("lewenstein", "levenshtein")
    81.81818181818181

    Setting a score_cutoff allows the implementation to select
    a more efficient implementation:

    >>> normalized_levenshtein("lewenstein", "levenshtein", score_cutoff=85)
    0.0

    It is possible to select different weights by passing a `weight`
    tuple.

    >>> normalized_levenshtein("lewenstein", "levenshtein", weights=(1,1,2))
    85.71428571428571

     When a different processor is used s1 and s2 do not have to be strings

    >>> normalized_levenshtein(["lewenstein"], ["levenshtein"], processor=lambda s: s[0])
    81.81818181818181
    ziThis function will be remove in v3.0.0. Use rapidfuzz.distance.Levenshtein.normalized_similarity instead.r   r   r   d   )r   r   r    r   normalized_similarity)r   r   r   r   r   s        r"   normalized_levenshteinr0      sX    R Ms    	)Gy|	
 	
 	
 	r$   )r   r   r   c               r    t          j        dt          d           |p|}t          j        | |||          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.
    processor: callable, optional
        Optional callable that is used to preprocess the strings before
        comparing them. Default is None, which deactivates this behaviour.
    max : int or None, optional
        Maximum distance between s1 and s2, that is
        considered as a result. If the distance is bigger than max,
        max + 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

    .. deprecated:: 2.0.0
        Use :func:`rapidfuzz.distance.Hamming.distance` instead.
        This function will be removed in v3.0.0.
    zXThis function will be remove in v3.0.0. Use rapidfuzz.distance.Hamming.distance instead.r   r   r   r   )r   r   r    r   r!   )r   r   r   r   r   s        r"   hammingr3      sM    V Mb   
  &3LBilSSSSr$   r2   c               p    t          j        dt          d           t          j        | |||          dz  S )a  
    Calculates a normalized hamming 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 100.
        For ratio < score_cutoff 0 is returned instead. Default is 0,
        which deactivates this behaviour.

    Returns
    -------
    similarity : float
        similarity between s1 and s2 as a float between 0 and 100

    Raises
    ------
    ValueError
        If s1 and s2 have a different length

    See Also
    --------
    hamming : Hamming distance

    .. deprecated:: 2.0.0
        Use :func:`rapidfuzz.distance.Hamming.normalized_similarity` instead.
        This function will be removed in v3.0.0.
    zeThis function will be remove in v3.0.0. Use rapidfuzz.distance.Hamming.normalized_similarity instead.r   r   r2   r.   )r   r   r    r   r/   r   r   r   r   s       r"   normalized_hammingr6     sV    T Mo    	%il	
 	
 	
 	r$   c               p    t          j        dt          d           t          j        | |||          dz  S )aV  
    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 100.
        For ratio < score_cutoff 0 is returned instead. Default is 0,
        which deactivates this behaviour.

    Returns
    -------
    similarity : float
        similarity between s1 and s2 as a float between 0 and 100

    .. deprecated:: 2.0.0
        Use :func:`rapidfuzz.distance.Jaro.similarity` instead.
        This function will be removed in v3.0.0.
    zWThis function will be remove in v3.0.0. Use rapidfuzz.distance.Jaro.similarity instead.r   r   r2   r.   )r   r   r    r	   
similarityr5   s       r"   jaro_similarityr9   N  sH    B Ma   
 ?2rY\RRRUXXXr$   g?prefix_weightr   r   r;   c               r    t          j        dt          d           t          j        | ||||          dz  S )aG  
    Calculates the jaro winkler similarity

    Parameters
    ----------
    s1 : Sequence[Hashable]
        First string to compare.
    s2 : Sequence[Hashable]
        Second string to compare.
    prefix_weight : float, optional
        Weight used for the common prefix of the two strings.
        Has to be between 0 and 0.25. Default is 0.1.
    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 100.
        For ratio < score_cutoff 0 is returned instead. Default is 0,
        which deactivates this behaviour.

    Returns
    -------
    similarity : float
        similarity between s1 and s2 as a float between 0 and 100

    Raises
    ------
    ValueError
        If prefix_weight is invalid

    .. deprecated:: 2.0.0
        Use :func:`rapidfuzz.distance.JaroWinkler.similarity` instead.
        This function will be removed in v3.0.0.
    z^This function will be remove in v3.0.0. Use rapidfuzz.distance.JaroWinkler.similarity instead.r   r   r:   r.   )r   r   r    r
   r8   )r   r   r;   r   r   s        r"   jaro_winkler_similarityr=   w  s\    T Mh    	'%	
 	
 	
 		r$   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r&   )r   r   r   r   r   r   r   r   r   r+   r   r,   )r   r   r   r   r   r   r   r   r   r   r   r   )
r   r   r   r   r   r   r   r+   r   r,   )r   r   r   r   r;   r,   r   r   r   r+   r   r,   )
__future__r   r   typingr   r   r   rapidfuzz.distancer   r   r	   r
   r   r#   r*   r0   r3   r6   r9   r=    r$   r"   <module>rB      s   # " " " " "  / / / / / / / / / / N N N N N N N N N N N N N N ,5:>#K K K K K Kd ;?	0F 0F 0F 0F 0F 0Fn ,5:>!%S S S S S St ;?#1T 1T 1T 1T 1T 1Tp ;?!%4 4 4 4 4 4v ;?!%&Y &Y &Y &Y &Y &YZ :>!%8 8 8 8 8 8 8 8r$   