
    ^j                    8    d dl mZ dddZ	 d	 	 	 	 	 	 	 	 	 ddZy)    )annotationsc           	        |s | j                         } |j                         }t        |       t        |      k  r|| }} t        t        t        |      dz               }dgt        |      dz   z  }t        dt        |       dz         D ]f  }||d<   t        dt        |      dz         D ]@  }| |dz
     ||dz
     k(  rd}nd}t	        ||   dz   ||dz
     dz   ||dz
     |z         ||<   B ||}}h |t        |         S )a  
    Calculates the minimum number of single-character edits required
    to transform one string into another. Allowed operations are insertion,
    deletion, and substitution.

    Args:
        string_1: The source string to be transformed.
        string_2: The target string to transform into.
        case_sensitive: Whether comparison should be case-sensitive.
            Defaults to True.

    Returns:
        The minimum number of edits required to convert `string_1`
        into `string_2`.

    Examples:
        ```pycon
        >>> import supervision as sv
        >>> sv.edit_distance("hello", "hello")
        0
        >>> sv.edit_distance("Test", "test", case_sensitive=True)
        1
        >>> sv.edit_distance("abc", "xyz")
        3
        >>> sv.edit_distance("hello", "")
        5
        >>> sv.edit_distance("", "")
        0
        >>> sv.edit_distance("hello world", "helloworld")
        1

        ```
       r   )lowerlenlistrangemin)string_1string_2case_sensitiveprev_rowcurr_rowijsubstitution_costs           k/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/detection/utils/vlms.pyedit_distancer      s'   D >>#>>#
8}s8}$%x(E#h-!+,-Hsc(ma'(H1c(ma'( 0q#h-!+, 		AA(1q5/1$%!$%!aQ!#Q"33HQK		 &x(0 CM""    c                T    t        |       D ]  \  }}t        |||      |k  s|c S  y)af  
    Searches for the first string in `candidates` whose edit distance
    to `query` is less than or equal to `threshold`.

    Args:
        candidates: List of strings to search.
        query: String to compare against the candidates.
        threshold: Maximum allowed edit distance for a match.
        case_sensitive: Whether matching should be case-sensitive.

    Returns:
        Index of the first matching string in candidates,
        or None if no match is found.

    Examples:
        ```pycon
        >>> from supervision.detection.utils.vlms import fuzzy_match_index
        >>> fuzzy_match_index(["cat", "dog", "rat"], "dat", threshold=1)
        0
        >>> fuzzy_match_index(["alpha", "beta", "gamma"], "bata", threshold=1)
        1
        >>> fuzzy_match_index(["one", "two", "three"], "xyz", threshold=2) is None
        True

        ```
    )r   N)	enumerater   )
candidatesquery	thresholdr   idx	candidates         r   fuzzy_match_indexr   A   s8    @ $J/ YE.IYVJ r   N)T)r   strr   r   r   boolreturnint)
r   z	list[str]r   r   r   r!   r   r   r    z
int | None)
__future__r   r   r    r   r   <module>r$      sF    ":#B  	### # 	#
 #r   