
    k*ik                    r    S SK Jr  S SKJr  S SKJrJr  S rSSS.S jrSSS.S jr	SSS.S	 jr
SSS.S
 jrg)    )annotations)conv_sequences)is_nonesetupPandasc                   U (       d  [        U5      $ S[        U 5      -  S-
  nSnSnSn[        U 5      nS[        U 5      S-
  -  n0 nUR                  n	Sn
U  H  nU	" US5      U
-  X'   U
S-  n
M     U Hh  nU	" US5      nU) U-  S-  U-  nX-  U-   U-  U-  U-  nXN-  nX4U-  ) -  nXB-  nXoU-  S:g  -  nUUU-  S:g  -  nUS-  S-  nUS-  nUXO-  ) -  nX-  nUnMj     U$ )N   r   )lenget)s1s2VPVND0PM_j_oldcurrDistmaskblock	block_getxch1ch2PM_jTRHPHNs                    Y/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/rapidfuzz/distance/OSA_py.py_osa_distance_hyrroe2003r   	   sF   2w
s2w,!	B	
B	
BH2wHR1DE		I	AsA&*
	a  a t|!X-	R2%-2W G*_W 	$Y1$$R$Y1$$ Ag]1WBG*_W) , O    N)	processorscore_cutoffc               v    Ub  U" U 5      n U" U5      n[        X5      u  p[        X5      nUb  XC::  a  U$ US-   $ )a?  
Calculates the optimal string alignment (OSA) 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 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

Examples
--------
Find the OSA distance between two strings:

>>> from rapidfuzz.distance import OSA
>>> OSA.distance("CA", "AC")
2
>>> OSA.distance("CA", "ABC")
3
r   )r   r   )r   r   r   r    dists        r   distancer#   4   sN    P r]r]B#FB#B+D (D,@4W|VWGWWr   c                   Ub  U" U 5      n U" U5      n[        X5      u  p[        [        U 5      [        U5      5      n[        X5      nXE-
  nUb  Xc:  a  U$ S$ )a  
Calculates the optimal string alignment (OSA) similarity in the range [max, 0].

This is calculated as ``max(len1, len2) - 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
-------
similarity : int
    similarity between s1 and s2
r   )r   maxr	   r#   )r   r   r   r    maximumr"   sims          r   
similarityr(   e   sc    @ r]r]B#FB#b'3r7#GBD
.C'3+>3FQFr   c                  [        5         [        U 5      (       d  [        U5      (       a  gUb  U" U 5      n U" U5      n[        X5      u  p[        [	        U 5      [	        U5      5      n[        X5      nU(       a  XT-  OSnUb  Xc::  a  U$ S$ )a  
Calculates a normalized optimal string alignment (OSA) similarity in the range [1, 0].

This is calculated as ``distance / max(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   )r   r   r   r%   r	   r#   )r   r   r   r    r&   r"   	norm_dists          r   normalized_distancer,      s    > Mr{{gbkkr]r]B#FB#b'3r7#GBD")qI%-1J9RQRRr   c                   [        5         [        U 5      (       d  [        U5      (       a  gUb  U" U 5      n U" U5      n[        X5      u  p[        X5      nSU-
  nUb  XS:  a  U$ S$ )a  
Calculates a normalized optimal string alignment (OSA) 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+   norm_sims         r   normalized_similarityr/      si    > Mr{{gbkkr]r]B#FB#B+IYH$,0H8PqPr   )
__future__r   rapidfuzz._common_pyr   rapidfuzz._utilsr   r   r   r#   r(   r,   r/    r   r   <module>r4      sQ    # / 1(^ .Xj (G^ +Sd *Qr   