
    NiF                       % S r SSKJr  SrS\S'   SrS\S'   SrS\S	'   SS
KJs  J	r
  SS
KJs  Jr  SS
KJs  Jr  SS
KJs  Jr  SS
KJs  Jr  SSKJr  SSKJr  SSKJrJrJrJ r J!r!J"r"  / SQr#SS
S
S
S.S jrS
S
S.S jr$SS
S
S.S jr%S
S
S.S"S jjr&SS
S
S.S"S jjr'\\l(        \$\$l(        \%\%l(        \&\&l(        \'\'l(        \R                  RR                  \l)        \RT                  RR                  \$l)        \
R                  RR                  \%l)        \RV                  RR                  \&l)        \RV                  RR                  \'l)        \," \R                  S5      (       a  \R                  RZ                  \l-        \," \RT                  S5      (       a  \RT                  RZ                  \$l-        \," \
R                  S5      (       a  \
R                  RZ                  \%l-        \," \RV                  S5      (       a  \RV                  RZ                  \&l-        \," \RV                  S5      (       a  \RV                  RZ                  \'l-        S r.S r/S r0S r1S  r2S! r3g
)#a  
A C extension module for fast computation of:
- Levenshtein (edit) distance and edit sequence manipulation
- string similarity
- approximate median strings, and generally string averaging
- string sequence and set similarity

Levenshtein has a some overlap with difflib (SequenceMatcher).  It
supports only strings, not arbitrary sequence types, but on the
other hand it's much faster.

It supports both normal and Unicode strings, but can't mix them, all
arguments to a function (method) have to be of the same type (or its
subclasses).
    )annotationszMax Bachmannstr
__author__GPL__license__z0.27.3__version__N)Editops)Opcodes)medianmedian_improvequickmedianseqratio	setmediansetratio)r   r   r   r   r   r   distanceratiohammingjarojaro_winklereditopsopcodesmatching_blocks
apply_editsubtract_editinverse)   r   r   weights	processorscore_cutoff
score_hintc          	     4    [         R                  " U UUUUUS9$ )a  
Calculates the minimum number of insertions, deletions, and substitutions
required to change one sequence into the other according to Levenshtein with custom
costs for insertion, deletion and substitution

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
weights : Tuple[int, int, int] or None, optional
    The weights for the three operations in the form
    (insertion, deletion, substitution). Default is (1, 1, 1),
    which gives all three operations a weight of 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 : 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.
score_hint : int, optional
    Expected distance between s1 and s2. This is used to select a
    faster implementation. Default is None, which deactivates this behaviour.

Returns
-------
distance : int
    distance between s1 and s2

Raises
------
ValueError
    If unsupported weights are provided a ValueError is thrown

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

>>> from Levenshtein import distance
>>> distance("lewenstein", "levenshtein")
2

Setting a maximum distance allows the implementation to select
a more efficient implementation:

>>> distance("lewenstein", "levenshtein", score_cutoff=1)
2

It is possible to select different weights by passing a `weight`
tuple.

>>> distance("lewenstein", "levenshtein", weights=(1,1,2))
3
r   )_Levenshteinr   )s1s2r   r   r    r!   s         S/var/www/html/land-tabula/venv/lib/python3.13/site-packages/Levenshtein/__init__.pyr   r   A   s*    t   

!     r   r    c               ,    [         R                  " XX#S9$ )aD  
Calculates a normalized indel similarity in the range [0, 1].
The indel distance calculates the minimum number of insertions and deletions
required to change one sequence into the other.

This is calculated as ``1 - (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_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

Examples
--------
Find the normalized Indel similarity between two strings:

>>> from Levenshtein import ratio
>>> ratio("lewenstein", "levenshtein")
0.85714285714285

Setting a score_cutoff allows the implementation to select
a more efficient implementation:

>>> ratio("lewenstein", "levenshtein", score_cutoff=0.9)
0.0

When a different processor is used s1 and s2 do not have to be strings

>>> ratio(["lewenstein"], ["levenshtein"], processor=lambda s: s[0])
0.8571428571428572
r(   )_Indelnormalized_similarityr$   r%   r   r    s       r&   r   r      s    \ '')__r'   Tpadr   r    c               .    [         R                  " XX#US9$ )aK  
Calculates the Hamming distance between two strings.
The hamming distance is defined as the number of positions
where the two strings differ. It describes the minimum
amount of substitutions required to transform s1 into s2.

Parameters
----------
s1 : Sequence[Hashable]
    First string to compare.
s2 : Sequence[Hashable]
    Second string to compare.
pad : bool, optional
   should strings be padded if there is a length difference.
   If pad is False and strings have a different length
   a ValueError is thrown instead. Default is True.
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

Raises
------
ValueError
    If s1 and s2 have a different length
r-   )_Hammingr   )r$   r%   r.   r   r    s        r&   r   r      s    H RP\]]r'   c               ,    [         R                  " XX#S9$ )a  
Calculates the jaro similarity

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 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
r(   )_Jaro
similarityr,   s       r&   r   r      s    . BiSSr'   g?prefix_weightr   r    c               2    [         R                  " U UUUUS9$ )aO  
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
r4   )_JaroWinklerr3   )r$   r%   r5   r   r    s        r&   r   r      s&    > ""

#! r'   
_RF_Scorerc                 6   [        U 5      S:X  ac  U u  pn[        U[        5      (       a  UO
[        U5      n[        U[        5      (       a  UO
[        U5      n[        XU5      R	                  5       $ U u  p[
        R                  " X5      R	                  5       $ )ak  
Find sequence of edit operations transforming one string to another.

editops(source_string, destination_string)
editops(edit_operations, source_length, destination_length)

The result is a list of triples (operation, spos, dpos), where
operation is one of 'equal', 'replace', 'insert', or 'delete';  spos
and dpos are position of characters in the first (source) and the
second (destination) strings.  These are operations on single
characters.  In fact the returned list doesn't contain the 'equal',
but all the related functions accept both lists with and without
'equal's.

Examples
--------
>>> editops('spam', 'park')
[('delete', 0, 0), ('insert', 3, 2), ('replace', 3, 3)]

The alternate form editops(opcodes, source_string, destination_string)
can be used for conversion from opcodes (5-tuples) to editops (you can
pass strings or their lengths, it doesn't matter).
   )len
isinstanceint_Editopsas_listr#   r   argsarg1arg2arg3len1len2s         r&   r   r   :  s    2 4yA~D!$,,t#d)!$,,t#d)D)1133 JD+3355r'   c                 6   [        U 5      S:X  ac  U u  pn[        U[        5      (       a  UO
[        U5      n[        U[        5      (       a  UO
[        U5      n[        XU5      R	                  5       $ U u  p[
        R                  " X5      R	                  5       $ )a  
Find sequence of edit operations transforming one string to another.

opcodes(source_string, destination_string)
opcodes(edit_operations, source_length, destination_length)

The result is a list of 5-tuples with the same meaning as in
SequenceMatcher's get_opcodes() output.  But since the algorithms
differ, the actual sequences from Levenshtein and SequenceMatcher
may differ too.

Examples
--------
>>> for x in opcodes('spam', 'park'):
...     print(x)
...
('delete', 0, 1, 0, 0)
('equal', 1, 3, 0, 2)
('insert', 3, 3, 2, 3)
('replace', 3, 4, 3, 4)

The alternate form opcodes(editops, source_string, destination_string)
can be used for conversion from editops (triples) to opcodes (you can
pass strings or their lengths, it doesn't matter).
r:   )r;   r<   r=   _Opcodesr?   r#   r   r@   s         r&   r   r   ^  s    6 4yA~D!$,,t#d)!$,,t#d)D)1133 JD+3355r'   c                $   [        U[        5      (       a  UO
[        U5      n[        U[        5      (       a  UO
[        U5      nU (       a  [        U S   5      S:X  a  [        XU5      R	                  5       $ [        XU5      R	                  5       $ )a  
Find identical blocks in two strings.

Parameters
----------
edit_operations : list[]
    editops or opcodes created for the source and destination string
source_string : str | int
    source string or the length of the source string
destination_string : str | int
    destination string or the length of the destination string

Returns
-------
matching_blocks : list[]
    List of triples with the same meaning as in SequenceMatcher's
    get_matching_blocks() output.

Examples
--------
>>> a, b = 'spam', 'park'
>>> matching_blocks(editops(a, b), a, b)
[(1, 0, 2), (4, 4, 0)]
>>> matching_blocks(editops(a, b), len(a), len(b))
[(1, 0, 2), (4, 4, 0)]

The last zero-length block is not an error, but it's there for
compatibility with difflib which always emits it.

One can join the matching blocks to get two identical strings:

>>> a, b = 'dog kennels', 'mattresses'
>>> mb = matching_blocks(editops(a,b), a, b)
>>> ''.join([a[x[0]:x[0]+x[2]] for x in mb])
'ees'
>>> ''.join([b[x[1]:x[1]+x[2]] for x in mb])
'ees'
r   r:   )r<   r=   r;   r>   as_matching_blocksrH   edit_operationssource_stringdestination_stringrE   rF   s        r&   r   r     sx    N '}c::=M@RD!+,>!D!D#N`JaDc/!"45:t4GGIIO40CCEEr'   c                    [        U 5      S:X  a  U$ [        U5      n[        U5      n[        U S   5      S:X  a  [        XU5      R                  X5      $ [        XU5      R                  X5      $ )aF  
Apply a sequence of edit operations to a string.

apply_edit(edit_operations, source_string, destination_string)

In the case of editops, the sequence can be arbitrary ordered subset
of the edit sequence transforming source_string to destination_string.

Examples
--------
>>> e = editops('man', 'scotsman')
>>> apply_edit(e, 'man', 'scotsman')
'scotsman'
>>> apply_edit(e[:3], 'man', 'scotsman')
'scoman'

The other form of edit operations, opcodes, is not very suitable for
such a tricks, because it has to always span over complete strings,
subsets can be created by carefully replacing blocks with 'equal'
blocks, or by enlarging 'equal' block at the expense of other blocks
and adjusting the other blocks accordingly.

>>> a, b = 'spam and eggs', 'foo and bar'
>>> e = opcodes(a, b)
>>> apply_edit(inverse(e), b, a)
'spam and eggs'
r   r:   )r;   r>   applyrH   rK   s        r&   r   r     sn    8 ?q }D!"D
?1!#t4::=]]O4066}YYr'   c                l    Sn[        XU5      R                  [        XU5      5      R                  5       $ )a|  
Subtract an edit subsequence from a sequence.

subtract_edit(edit_operations, subsequence)

The result is equivalent to
editops(apply_edit(subsequence, s1, s2), s2), except that is
constructed directly from the edit operations.  That is, if you apply
it to the result of subsequence application, you get the same final
string as from application complete edit_operations.  It may be not
identical, though (in amibuous cases, like insertion of a character
next to the same character).

The subtracted subsequence must be an ordered subset of
edit_operations.

Note this function does not accept difflib-style opcodes as no one in
his right mind wants to create subsequences from them.

Examples
--------
>>> e = editops('man', 'scotsman')
>>> e1 = e[:3]
>>> bastard = apply_edit(e1, 'man', 'scotsman')
>>> bastard
'scoman'
>>> apply_edit(subtract_edit(e, e1), bastard, 'scotsman')
'scotsman'
l        )r>   remove_subsequencer?   )rL   subsequencestr_lens      r&   r   r     s1    < G73		H[7C	D	r'   c                4   [        U 5      S:X  a  / $ [        U S   5      S:X  a>  U S   S   S-   nU S   S   S-   n[        XU5      R                  5       R                  5       $ U S   S   nU S   S   n[	        XU5      R                  5       R                  5       $ )a3  
Invert the sense of an edit operation sequence.

In other words, it returns a list of edit operations transforming the
second (destination) string to the first (source).  It can be used
with both editops and opcodes.

Parameters
----------
edit_operations : list[]
    edit operations to invert

Returns
-------
edit_operations : list[]
    inverted edit operations

Examples
--------
>>> editops('spam', 'park')
[('delete', 0, 0), ('insert', 3, 2), ('replace', 3, 3)]
>>> inverse(editops('spam', 'park'))
[('insert', 0, 0), ('delete', 2, 3), ('replace', 3, 3)]
r   r:   r         )r;   r>   r   r?   rH   )rL   rE   rF   s      r&   r   r     s    2 ?q 	
?1!#r"1%)r"1%)t4<<>FFHH2q!D2q!DO4088:BBDDr'   )returnfloat)4__doc__
__future__r   r   __annotations__r   r   rapidfuzz.distance.Hammingr   Hammingr0   rapidfuzz.distance.IndelIndelr*   rapidfuzz.distance.JaroJaror2   rapidfuzz.distance.JaroWinklerJaroWinklerr7   rapidfuzz.distance.LevenshteinLevenshteinr#   rapidfuzz.distancer	   r>   r
   rH   Levenshtein.levenshtein_cppr   r   r   r   r   r   __all__r   r   r   r   _RF_OriginalScorer_RF_ScorerPyr+   r3   hasattrr8   r   r   r   r   r   r    r'   r&   <module>ro      s)    # 
C  S S  - - ) ) ' ' 5 5 5 5 * !*TY] AH  $$ .`b  4d $^N # T4 +.D %V '   $  ". $--:: 11>> ((55 $$11 (33@@ 
<  ,//&//::H
6''6633>>E
8l++!**55G
5\**&&11DO
<""L11*55@@L!6H#6L-F`%ZP#L$Er'   