
    9i                        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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y	)    )annotations)CallableHashableSequence)conv_sequences)is_nonec                P    |dz  }d}||| z  z  }|||z  z  }|||z
  |z  z  }|dz  S )N           g      @ )pattern_lentext_lencommon_charstranspositionssims        d/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/rapidfuzz/distance/Jaro_py.py_jaro_calculate_similarityr      sM    qN
C<+%%C<(""CL>)\99C9    c                F    | r|sy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      s/     h
$[(CX<VXY
ZC,r   c                .    |sy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%     
$[(L!
LC,r   c                    t        |       }t        |      }d}||kD  r|dz  dz
  }|||z   kD  r!|d||z    }n|dz  dz
  }|||z   kD  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2wH E+A!kE)))kE)*Bq 1$E))&h&'Br5=r   N	processorr   c                  t        |       st        |      ry| ||       }  ||      }| s|sy|d}t        | |      \  } }t        |       }t        |      }t        |||      sy|dk(  r|dk(  rt	        | d   |d   k(        S t        | |      \  } }}dg|z  }dg|z  }d}	t        |       D ]Y  \  }
}t        d|
|z
        }t        |
|z   |dz
        }t        ||dz         D ]!  }||   r	||   |k(  sdx||
<   ||<   |	dz  }	 Y [ t        |||	|      sydx}}t        |      D ]6  \  }
}|s	t        ||      D ]  }||   s	|dz   } n | |
   |   k7  s2|dz  }8 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         ?r   r   FT)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   
similarityr4   @   s   : r{gbkr]r]bB#FBb'K2wH {HlCaHMRUbe^$$ R(MBEw$Hw!H LbM 5!QYUHqL)sBF# 	AA;2a5E>,00hqk!		 $K<V AX& !41h' A;AA !u1~q ! &k8\;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"   )r4   r   r   r#   r   s       r   normalized_similarityr7      s    : b"	MMr   c                   t        |       st        |      ry| ||       }  ||      }||dkD  rdnd|z
  }t        | ||      }d|z
  }|||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   r4   )r   r   r#   r   cutoff_distancer   dists          r   distancer;      st    : r{gbkr]r]+3|c7IdPSVbPbO
R/
:C9D (DL,@4Js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;   r6   s       r   normalized_distancer=      s    : BilKKr   )
r   intr   r>   r   r>   r   r>   returnr&   )r   r>   r   r>   r   r&   r?   bool)
r   r>   r   r>   r   r>   r   r&   r?   r@   )r   Sequence[Hashable]r   rA   r?   z2tuple[Sequence[Hashable], Sequence[Hashable], int])
r   rA   r   rA   r#   z(Callable[..., Sequence[Hashable]] | Noner   zfloat | Noner?   r&   )
__future__r   typingr   r   r   rapidfuzz._common_pyr   rapidfuzz._utilsr   r   r   r   r!   r4   r7   r;   r=   r   r   r   <module>rF      s7   # / / / $2 ;?!%VXVXVX 8	VX
 VX VXz ;?!%NNN 8	N
 N NH ;?!%'K'K'K 8	'K
 'K 'K\ ;?!%LLL 8	L
 L Lr   