U
    -e}                     @  s   d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ ddddd	d	d
ddd
dddZddddd	d	d
ddd
dddZddddd	d	d
ddd
dddZddddd	d	d
ddd
dddZdS )    )annotations)CallableHashableSequence)conv_sequences)is_none)Jaro_pyg?Nprefix_weight	processorscore_cutoffzSequence[Hashable]floatz(Callable[..., Sequence[Hashable]] | Nonezfloat | None)s1s2r
   r   r   returnc                C  s  t | st |rdS |dk	r,|| } ||}|dkr8d}t| |\} }t| }t|}t||}d}t|d}	t|	D ] }
| | || kr q|d7 }qv|}|dkr|| }|dkrd}ntd|| |d  }tj| ||d}|dkr||| d|  7 }||kr
|S dS )	a  
    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 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

    Raises
    ------
    ValueError
        If prefix_weight is invalid
    g        Nr         gffffff?      ?)r   )r   r   lenminrangemaxJaro
similarity)r   r   r
   r   r   ZP_lenZT_lenmin_lenprefixZ
max_prefix_Zjaro_score_cutoffZ
prefix_simZSim r   b/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/rapidfuzz/distance/JaroWinkler_py.pyr      s6    &


r   c                C  s   t | ||||dS )a  
    Calculates the normalized 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 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

    Raises
    ------
    ValueError
        If prefix_weight is invalid
    r	   )r   r   r   r
   r   r   r   r   r   normalized_similarityY   s    &r    c                C  sx   t | st |rdS |dk	r,|| } ||}|dks<|dkr@dnd| }t| |||d}d| }|dksp||krt|S dS )a  
    Calculates the jaro winkler distance

    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 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

    Raises
    ------
    ValueError
        If prefix_weight is invalid
    r   N)r
   r   )r   r   )r   r   r
   r   r   Zcutoff_distancesimdistr   r   r   distance   s    &r#   c                C  s   t | ||||dS )a  
    Calculates the normalized jaro winkler distance

    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 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

    Raises
    ------
    ValueError
        If prefix_weight is invalid
    r	   )r#   r   r   r   r   normalized_distance   s    &r$   )
__future__r   typingr   r   r   Zrapidfuzz._common_pyr   Zrapidfuzz._utilsr   Zrapidfuzz.distancer   r   r   r    r#   r$   r   r   r   r   <module>   s(   P37