
    Ng                    ~    d dl mZ d dlmZ d dlmZmZ d Zd Zd Z	d Z
ddd	d
Zddd	dZddd	dZddd	dZdS )    )annotations)conv_sequences)is_nonesetupPandasc                P    |dz  }d}||| z  z  }|||z  z  }|||z
  |z  z  }|dz  S )N           g      @ )pattern_lentext_lencommon_charstranspositionssims        V/var/www/html/ai-engine/env/lib/python3.11/site-packages/rapidfuzz/distance/Jaro_py.py_jaro_calculate_similarityr   	   sM    qN
C<+%%C<(""CL>)\99C9    c                Z    | 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   s       r   _jaro_length_filterr      sA      h u
$[(CX<V<VXY
Z
ZC,r   c                :    |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   s        r   _jaro_common_char_filterr      s/      u
$[(L!
L
LC,r   c                    t          |           }t          |          }d}||k    r|dz  dz
  }|||z   k    r|d||z            }n|dz  dz
  }|||z   k    r| d||z            } | ||fS )zB
    find bounds and skip out of bound parts of the sequences
    r   r      N)len)s1s2r   r   bounds        r   _jaro_boundsr   (   s     b''K2wwH E+A!kE))))kE))*Bq 1$E)))&h&&'Br5=r   N	processorr   c                  t                       t          |           st          |          rdS | ||           }  ||          }| s|sdS |d}t          | |          \  } }t          |           }t          |          }t	          |||          sdS |dk    r%|dk    rt          | d         |d         k              S t          | |          \  } }}dg|z  }dg|z  }d}	t          |           D ]i\  }
}t          d|
|z
            }t          |
|z   |dz
            }t          ||dz             D ]'}||         s||         |k    rdx||
<   ||<   |	dz  }	 n(jt          |||	|          sdS dx}}t          |          D ]@\  }
}|r9t          ||          D ]}||         r|dz   } n| |
         ||         k    r|dz  }At          |||	|          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   s1_flagss2_flagsr   is1_chlowhijktrans_counts1_fs                     r   
similarityr2   =   sb   : MMMr{{ gbkk sYr]]Yr]] b sB##FBb''K2wwH {HlCC qaHMMRUbe^$$$ R((MBEw$Hw!H LbMM  5!QYUHqL))sBF## 	 	AA; 2a5E>>,00hqk! $K<VV q AX&& ! !4 	!1h''  A; AAE !u1~~q %k8\;WWWr   c               (    t          | |||          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    )r2   r   r   r!   r   s       r   normalized_similarityr5      s    : b"	MMMMr   c                   t                       t          |           st          |          rdS | ||           }  ||          }||dk    rdnd|z
  }t          | ||          }d|z
  }|||k    r|n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   r2   )r   r   r!   r   cutoff_distancer   dists          r   distancer9      s    : MMMr{{ gbkk sYr]]Yr]]+3|c7I7IddPSVbPbO
R/
:
:
:C9D (DL,@,@44sJr   c               (    t          | |||          S )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    )r9   r4   s       r   normalized_distancer;      s    : BilKKKKr   )
__future__r   rapidfuzz._common_pyr   rapidfuzz._utilsr   r   r   r   r   r   r2   r5   r9   r;   r
   r   r   <module>r?      s+   # " " " " " / / / / / / 1 1 1 1 1 1 1 1        2 WX WX WX WX WX| N N N N NH (K (K (K (K (K^ L L L L L L Lr   