
    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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y)    )annotations)CallableHashableSequence)conv_sequences)is_none)Jaro_pyg?Nprefix_weight	processorscore_cutoffc                  t        |       st        |      ry| ||       }  ||      }|d}t        | |      \  } }t        |       }t        |      }t        ||      }d}t        |d      }	t	        |	      D ]  }
| |   ||   k7  r n|dz  } |}|dkD  r"||z  }|dk\  rd}nt        d||z
  |dz
  z        }t        j                  | ||      }|dkD  r|||z  d|z
  z  z  }||k\  r|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        r         gffffff?      ?)r   )r   r   lenminrangemaxJaro
similarity)s1s2r   r   r   P_lenT_lenmin_lenprefix
max_prefix_jaro_score_cutoff
prefix_simSims                 k/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/rapidfuzz/distance/JaroWinkler_py.pyr   r      s0   L r{gbkr]r]B#FBGEGE%GFWaJ: f:F#!
 %3m+
 # #C*7H*HZZ]M])^ _
//"b/@
AC
Syv%s33%3,1,    c               "    t        | ||||      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   s        r#   normalized_similarityr'   Y   s!    L 

#! r$   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 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   cutoff_distancesimdists           r#   distancer,      sw    L r{gbkr]r]+3|c7IdPSVbPbO
R=
WC9D (DL,@4JsJr$   c               "    t        | ||||      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&   s        r#   normalized_distancer.      s!    L 

#! r$   )r   Sequence[Hashable]r   r/   r   floatr   z(Callable[..., Sequence[Hashable]] | Noner   zfloat | Nonereturnr0   )
__future__r   typingr   r   r   rapidfuzz._common_pyr   rapidfuzz._utilsr   rapidfuzz.distancer	   r   r   r'   r,   r.    r$   r#   <module>r8      sJ   # / / / $ . :>!%I-I-I- 	I-
 8I- I- I-` :>!%,,, 	,
 8, , ,f :>!%0K0K0K 	0K
 80K 0K 0Kn :>!%,,, 	,
 8, , ,r$   