Ë
    ¡[;jk  ã                  ój   — d dl mZ d dlmZ d dlmZmZ d„ Zdddœd„Zdddœd„Z	dddœd	„Z
dddœd
„Zy)é    )Úannotations)Úconv_sequences)Úis_noneÚsetupPandasc                óÂ  — | st        |«      S dt        | «      z  dz
  }d}d}d}t        | «      }dt        | «      dz
  z  }i }|j                  }	d}
| D ]  } |	|d«      |
z  ||<   |
dz  }
Œ |D ]n  } |	|d«      }| |z  dz  |z  }||z  |z   |z  |z  |z  }||z  }|||z   z  }||z  }|||z  dk7  z  }|||z  dk7  z  }|dz  dz  }|dz  }|||z   z  }||z  }|}Œp |S )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                    úbG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\rapidfuzz/distance/OSA_py.pyÚ_osa_distance_hyrroe2003r   	   sV  € ÙÜ�2‹wˆà
Œs�2‹w‰,˜!Ñ	€BØ	
€BØ	
€BØ€HÜ�2‹w€HØ”�R“˜1‘Ñ€Dà€EØ—	‘	€IØ	€AÛˆÙ˜s AÓ&¨Ñ*ˆˆc‰
Ø	ˆa‰‰ð ó ˆá˜˜aÓ ˆØ��t‰| Ñ! XÑ-ˆØ�r‘	˜RÑ 2Ñ%¨Ñ-°Ñ2ˆØ�"‰Wˆð �B˜‘G�*‰_ˆØ�"‰Wˆð 	�R˜$‘Y 1Ñ$Ñ$ˆØ�R˜$‘Y 1Ñ$Ñ$ˆð �A‰g˜‰]ˆØ�1‰WˆØ�B˜‘G�*‰_ˆØ�"‰WˆØ‰ð) ð, €Oó    N)Ú	processorÚscore_cutoffc               óx   — |� || «      }  ||«      }t        | |«      \  } }t        | |«      }|�||k  r|S |dz   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   sV   € ðP ÐÙ�r‹]ˆÙ�r‹]ˆä˜B Ó#�F€BˆÜ# B¨Ó+€DØ Ð(¨D°LÒ,@ˆ4ÐWÀ|ÐVWÑGWÐWr   c               ó¸   — |� || «      }  ||«      }t        | |«      \  } }t        t        | «      t        |«      «      }t        | |«      }||z
  }|�||k\  r|S dS )a5  
    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   sm   € ð@ ÐÙ�r‹]ˆÙ�r‹]ˆä˜B Ó#�F€BˆÜ”#�b“'œ3˜r›7Ó#€GÜ�B˜Ó€DØ
�D‰.€CØÐ'¨3°,Ò+>ˆ3ÐFÀQÐFr   c               ó  — t        «        t        | «      st        |«      ry|� || «      }  ||«      }t        | |«      \  } }t        t	        | «      t	        |«      «      }t        | |«      }|r||z  nd}|�||k  r|S dS )aM  
    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„{”g˜b”kØàÐÙ�r‹]ˆÙ�r‹]ˆä˜B Ó#�F€BˆÜ”#�b“'œ3˜r›7Ó#€GÜ�B˜Ó€DÙ")��w’¨q€IØ%Ð-°¸lÒ1Jˆ9ÐRÐQRÐRr   c               ó¾   — t        «        t        | «      st        |«      ry|� || «      }  ||«      }t        | |«      \  } }t        | |«      }d|z
  }|�||k\  r|S dS )aE  
    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/   ¾   sm   € ô> „MÜˆr„{”g˜b”kØàÐÙ�r‹]ˆÙ�r‹]ˆä˜B Ó#�F€BˆÜ# B¨Ó+€IØ�Y‰€HØ$Ð,°¸LÒ0Hˆ8ÐPÈqÐ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   