o
    Õj±  ã                   @  sŒ   d dl mZ d dlmZ d dlmZmZ dd„ Zdd„ Zdd	„ Z	d
d„ 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)Úconv_sequences)Úis_noneÚsetupPandasc                 C  s<   |d }d}|||  7 }||| 7 }||| | 7 }|d S )Né   ç        g      @© )Úpattern_lenÚtext_lenÚcommon_charsZtranspositionsÚsimr   r   ú[/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/rapidfuzz/distance/Jaro_py.pyÚ_jaro_calculate_similarity	   s   r   c                 C  s(   | r|sdS t | |t| |ƒdƒ}||kS )zC
    filter matches below score_cutoff based on string lengths
    Fr   )r   Úmin)r	   r
   Úscore_cutoffr   r   r   r   Ú_jaro_length_filter   s   r   c                 C  s   |sdS t | ||dƒ}||kS )zY
    filter matches below score_cutoff based on string lengths and common characters
    Fr   )r   )r	   r
   r   r   r   r   r   r   Ú_jaro_common_char_filter   s   r   c                 C  sx   t | ƒ}t |ƒ}d}||kr#|d d }||| kr"|d|| … }n|d d }||| kr7| d|| … } | ||fS )zB
    find bounds and skip out of bound parts of the sequences
    r   r   é   N)Úlen)Ús1Ús2r	   r
   Úboundr   r   r   Ú_jaro_bounds(   s   €
r   N©Ú	processorr   c                C  s´  t ƒ  t| ƒst|ƒrdS |dur|| ƒ} ||ƒ}| s|sdS |du r%d}t| |ƒ\} }t| ƒ}t|ƒ}t|||ƒs<dS |dkrN|dkrNt| d |d kƒS t| |ƒ\} }}dg| }dg| }d}	t| ƒD ]6\}
}td|
| ƒ}t	|
| |d ƒ}t
||d ƒD ]}|| s›|| |kr›d ||
< ||< |	d7 }	 nqqft|||	|ƒs¦dS d }}t|ƒD ]$\}
}|rÒt
||ƒD ]}|| rÅ|d } nq¹| |
 || krÒ|d7 }q®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   Nç      ð?r   r   FT)r   r   r   r   r   Úfloatr   Ú	enumerateÚmaxr   Úranger   r   )r   r   r   r   r	   r
   r   Zs1_flagsZs2_flagsr   ÚiZs1_chÚlowÚhiÚjÚkZtrans_countZs1_fr   r   r   Ú
similarity=   sX   

€þ€r%   c                C  ó   t | |||d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   )r%   ©r   r   r   r   r   r   r   Únormalized_similarity—   ó   r(   c                C  s|   t ƒ  t| ƒst|ƒrdS |dur|| ƒ} ||ƒ}|du s!|dkr#dnd| }t| ||d}d| }|du s:||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   r%   )r   r   r   r   Zcutoff_distancer   Údistr   r   r   Údistance·   s   r+   c                C  r&   )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   )r+   r'   r   r   r   Únormalized_distanceâ   r)   r,   )Ú
__future__r   Zrapidfuzz._common_pyr   Zrapidfuzz._utilsr   r   r   r   r   r   r%   r(   r+   r,   r   r   r   r   Ú<module>   s&   	û^û$û/û