
    xnh                    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                   t        t        |       t        |            dz   }i }|j                  }t        |      dz   }|g|z  }|g|z  }t        t	        |            }||d<   t	        dt        |       dz         D ]  }	||}}d}
|d   }|	|d<   |}t	        dt        |      dz         D ]  }||dz
     | |	dz
     ||dz
     k7  z   }||dz
     dz   }||   dz   }t        |||      }| |	dz
     ||dz
     k(  r|}
||dz
     ||<   |}nM |||dz
     d      }|
}||z
  dk(  r||   |	|z
  z   }t        ||      }n|	|z
  dk(  r|||z
  z   }t        ||      }||   }|||<    |	|| |	dz
     <    |t        |         S )N      r   )maxlengetlistrangemin)s1s2maxVallast_row_idlast_row_id_getsizeFRR1Rilast_col_id	last_i2l1Tjdiagleftuptempkl	transposes                        i/var/www/html/profi_bot/bot/venv/lib/python3.12/site-packages/rapidfuzz/distance/DamerauLevenshtein_py.py"_damerau_levenshtein_distance_zhaor'   	   s   R#b'"Q&FK!ooOr7Q;D
DB
DBU4[AAbE1c"gk"A2aD	!q#b'A+&Aa!e91q5	RAY 67DQU8a<DABtT2&D!a%yBq1uI%1q5	1#Bq1uIr2Ea< "1QItY/D!e\ !QUItY/D!IAaD- '0 "#Bq1uI? #B SW:    N)	processorscore_cutoffc               x    | ||       }  ||      }t        | |      \  } }t        | |      }|||k  r|S |dz   S )a  
    Calculates the Damerau-Levenshtein 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 Damerau-Levenshtein distance between two strings:

    >>> from rapidfuzz.distance import DamerauLevenshtein
    >>> DamerauLevenshtein.distance("CA", "ABC")
    2
    r   )r   r'   )r   r   r)   r*   dists        r&   distancer-   7   sV    L r]r]B#FB-b"5D (DL,@4W|VWGWWr(   c                   | ||       }  ||      }t        | |      \  } }t        t        |       t        |            }t        | |      }||z
  }|||k\  r|S dS )a*  
    Calculates the Damerau-Levenshtein 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   r   r   r-   )r   r   r)   r*   maximumr,   sims          r&   
similarityr1   f   sm    @ r]r]B#FB#b'3r7#GBD
D.C'3,+>3FQFr(   c                  t                t        |       st        |      ry| ||       }  ||      }t        | |      \  } }t        t	        |       t	        |            }t        | |      }|r||z  nd}|||k  r|S dS )a@  
    Calculates a normalized Damerau-Levenshtein distance 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_distancer5      s    > Mr{gbkr]r]B#FB#b'3r7#GBD")wqI%-l1J9RQRRr(   c                   t                t        |       st        |      ry| ||       }  ||      }t        | |      \  } }t        | |      }d|z
  }|||k\  r|S dS )a:  
    Calculates a normalized Damerau-Levenshtein 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        r3   r   )r   r   r   r5   )r   r   r)   r*   r4   norm_sims         r&   normalized_similarityr8      sm    > Mr{gbkr]r]B#FB#B+IYH$,L0H8PqPr(   )
__future__r   rapidfuzz._common_pyr   rapidfuzz._utilsr   r   r'   r-   r1   r5   r8    r(   r&   <module>r=      sQ    # / 1+d ,Xf (G^ +Sd *Qr(   