a
     ˜ëjQ  ã                   @  s€   d dl mZ d dlmZ d dlmZmZ d dlmZ	 ddddœdd	„Z
ddddœd
d„Zddddœdd„Zddddœdd„ZdS )é    )Úannotations)Úconv_sequences)Úis_noneÚsetupPandas)ÚJaro_pygš™™™™™¹?N©Úprefix_weightÚ	processorÚscore_cutoffc                C  s<  t ƒ  t| ƒst|ƒrdS |dur2|| ƒ} ||ƒ}|du r>d}|dksN|dk rZd}t|ƒ‚t| |ƒ\} }t| ƒ}t|ƒ}t||ƒ}d}	t|dƒ}
t|
ƒD ] }| |	 ||	 kr° qº|	d7 }	q˜|}|dkrò|	| }|dkrÜd}ntd|| |d  ƒ}tj	| ||d	�}|dk�r*||	| d|  7 }t|dƒ}||k�r8|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   ç      ð?z.prefix_weight has to be in the range 0.0 - 1.0é   é   gffffffæ?)r
   )
r   r   Ú
ValueErrorr   ÚlenÚminÚrangeÚmaxÚJaroÚ
similarity)Ús1Ús2r   r	   r
   ÚmsgZP_lenZT_lenZmin_lenÚprefixZ
max_prefixÚ_Zjaro_score_cutoffZ
prefix_simZSim© r   ú`/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/rapidfuzz/distance/JaroWinkler_py.pyr   
   s@    &




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_similarity\   s    &ûr   c                C  s~   t ƒ  t| ƒst|ƒrdS |dur2|| ƒ} ||ƒ}|du sB|dkrFdnd| }t| |||d�}d| }|du sv||krz|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	   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   Zrapidfuzz._common_pyr   Zrapidfuzz._utilsr   r   Zrapidfuzz.distancer   r   r   r   r    r!   r   r   r   r   Ú<module>   s&   úVú3ú8ú