
    9iD                        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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_noneN)	processorscore_cutoffc                   | ||       }  ||      }t        | |      \  } }t        t        |       t        |            }t        | |      }||z
  }|||k  r|S |dz   S )a  
    Calculates the Prefix distance between two strings.

    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 : int or None, optional
        Maximum distance between s1 and s2, that is
        considered as a result. If the distance is bigger than score_cutoff,
        score_cutoff + 1 is returned instead. Default is None, which deactivates
        this behaviour.

    Returns
    -------
    distance : int
        distance between s1 and s2
       )r   maxlen
similarity)s1s2r	   r
   maximumsimdists          f/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/rapidfuzz/distance/Prefix_py.pydistancer      sr    < r]r]B#FB#b'3r7#G
R
CS=D (DL,@4W|VWGWW    c                   | ||       }  ||      }t        | |      \  } }d}t        | |      D ]  \  }}||k7  r n|dz  } |||k\  r|S dS )a  
    Calculates the prefix similarity between two strings.

    This is calculated as ``len1 - 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 : int, optional
        Maximum distance between s1 and s2, that is
        considered as a result. If the similarity is smaller than score_cutoff,
        0 is returned instead. Default is None, which deactivates
        this behaviour.

    Returns
    -------
    distance : int
        distance between s1 and s2
    r   r   )r   zip)r   r   r	   r
   r   ch1ch2s          r   r   r   6   sw    @ r]r]B#FB
CBK S#:q
  '3,+>3FQFr   c               l    t        |       st        |      ryt        | ||      }d|z
  }|||k  r|S dS )a3  
    Calculates a normalized prefix similarity in the range [1, 0].

    This is calculated as ``distance / (len1 + len2)``.

    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 norm_dist > score_cutoff 1.0 is returned instead. Default is 1.0,
        which deactivates this behaviour.

    Returns
    -------
    norm_dist : float
        normalized distance between s1 and s2 as a float between 0 and 1.0
          ?)r	   )r   normalized_similarity)r   r   r	   r
   norm_sim	norm_dists         r   normalized_distancer!   d   sC    > r{gbk$RyAHhI%-l1J9TQTTr   c                   t        |       st        |      ry| ||       }  ||      }t        | |      \  } }t        t        |       t        |            }t	        | |      }|r||z  nd}|||k\  r|S dS )a-  
    Calculates a normalized prefix similarity in the range [0, 1].

    This is calculated as ``1 - normalized_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 norm_sim < score_cutoff 0 is returned instead. Default is 0,
        which deactivates this behaviour.

    Returns
    -------
    norm_sim : float
        normalized similarity between s1 and s2 as a float between 0 and 1.0
    g        r   )r   r   r   r   r   )r   r   r	   r
   r   r   r   s          r   r   r      s    > r{gbkr]r]B#FB#b'3r7#G
R
C 'sW}SH$,L0H8RsRr   )
r   Sequence[Hashable]r   r#   r	   (Callable[..., Sequence[Hashable]] | Noner
   z
int | Nonereturnint)
r   r#   r   r#   r	   r$   r
   zfloat | Noner%   float)
__future__r   typingr   r   r   rapidfuzz._common_pyr   rapidfuzz._utilsr   r   r   r!   r    r   r   <module>r-      s   # / / / $ ;?#'X'X'X 8	'X
 'X 	'X\ ;?#+G+G+G 8	+G
 +G 	+Gd ;?!%%U%U%U 8	%U
 %U %UX ;?!%+S+S+S 8	+S
 +S +Sr   