
    d                        d dl mZ d dlmZmZmZ d dl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)CallableHashableSequence)is_nonepattern_leninttext_lencommon_charstranspositionsreturnfloatc                P    |dz  }d}||| z  z  }|||z  z  }|||z
  |z  z  }|dz  S )N           g      @ )r   r
   r   r   sims        ^/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/rapidfuzz/distance/Jaro_py.py_jaro_calculate_similarityr      sO     qN
C<+%%C<(""CL>)\99C9    score_cutoffboolc                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
   r   r   s       r   _jaro_length_filterr      sG      h u
$Xs;991 C ,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   s1Sequence[Hashable]s22tuple[Sequence[Hashable], Sequence[Hashable], int]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)r   r    r   r
   bounds        r   _jaro_boundsr&   0   s     b''K2wwH E+A!kE))))kE))*Bq 1$E)))&h&&'Br5=r   N	processorr   r(   (Callable[..., Sequence[Hashable]] | Nonefloat | Nonec               \   t          |           st          |          rdS | ||           }  ||          }|d}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   Nr   r#   FT)r   r$   r   r   r&   	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   
similarityr9   G   s2   : r{{ gbkk sYr]]Yr]]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'   )r9   r   r    r(   r   s       r   normalized_similarityr<      s    : b"	MMMMr   c                   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
    g      ?N)r   )r   r9   )r   r    r(   r   cutoff_distancer   dists          r   distancer@      s    : r{{ gbkk sYr]]Yr]] %););#BT  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'   )r@   r;   s       r   normalized_distancerB      s    : BilKKKKr   )
r   r	   r
   r	   r   r	   r   r	   r   r   )r   r	   r
   r	   r   r   r   r   )
r   r	   r
   r	   r   r	   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&   r9   r<   r@   rB   r   r   r   <module>rF      s^   # " " " " " / / / / / / / / / / $ $ $ $ $ $   
 
 
 

 
 
 
   6 ;?!%RX RX RX RX RX RXr ;?!%N N N N N NH ;?!%)K )K )K )K )K )K` ;?!%L L L L L L L Lr   