
    d                    r    d dl mZ d dlmZmZmZ d dlmZ dddddZdddddZ	dddddZ
dddddZdS )    )annotations)CallableHashableSequence)is_noneN)	processorscore_cutoffs1Sequence[Hashable]s2r   (Callable[..., Sequence[Hashable]] | Noner	   
int | Nonereturnintc                   | ||           }  ||          }t          t          |           t          |                    }t          | |          }||z
  }|||k    r|n|dz   S )a  
    Calculates the postfix distance between two strings.

    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 : 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
    N   )maxlen
similarity)r
   r   r   r	   maximumsimdists          a/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/rapidfuzz/distance/Postfix_py.pydistancer      sv    < Yr]]Yr]]#b''3r77##G
R

CS=D (DL,@,@44|VWGWW    c                   | ||           }  ||          }d}t          t          |           t          |                    D ]\  }}||k    r n|dz  }|||k    r|ndS )a  
    Calculates the postfix 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.
    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
    Nr   r   )zipreversed)r
   r   r   r	   r   ch1ch2s          r   r   r   4   s    @ Yr]]Yr]]
Chrll33  S#::Eq'3,+>+>33QFr   float | Nonefloatc                   t          |           st          |          rdS t          | ||          }d|z
  }|||k    r|ndS )a4  
    Calculates a normalized postfix 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.
    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
          ?)r   )r   normalized_similarity)r
   r   r   r	   norm_sim	norm_dists         r   normalized_distancer(   a   s[    > r{{ gbkk s$RyAAAHhI%-l1J1J99QTTr   c                  t          |           st          |          rdS | ||           }  ||          }t          t          |           t          |                    }t          | |          }|r||z  nd}|||k    r|ndS )a.  
    Calculates a normalized postfix 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.
    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
    g        Nr$   )r   r   r   r   )r
   r   r   r	   r   r   r&   s          r   r%   r%      s    > r{{ gbkk sYr]]Yr]]#b''3r77##G
R

C '0sW}}SH$,L0H0H88sRr   )
r
   r   r   r   r   r   r	   r   r   r   )
r
   r   r   r   r   r   r	   r!   r   r"   )
__future__r   typingr   r   r   rapidfuzz._utilsr   r   r   r(   r%    r   r   <module>r.      s   # " " " " " / / / / / / / / / / $ $ $ $ $ $ ;?#&X &X &X &X &X &XZ ;?#*G *G *G *G *G *Gb ;?!%%U %U %U %U %U %UX ;?!%*S *S *S *S *S *S *S *Sr   