
    tniW                     &   d Z ddlZddlZddlmZmZmZmZmZm	Z	 ddl
mZmZ ddlmZ deeegef         dedeeeeeef         f                  d	ed
eeeef                  f
dZ	 	 	 ddeded	ededeeegef         d
eeeef                  fdZdS )zNModule contains the async interface to match needle against haystack in batch.    N)AnyCallableDictListUnioncast)SCORE_INDICES
fzy_scorer)	HAYSTACKSscorerneedle	haystackskeyreturnc                    K   g }|D ]F} | |t          t          |          |                   \  }}|-|                    |||d           G|                    d d           |S )a  Calculate the score for needle against given list of haystacks and rank them.

    Args:
        scorer: Scorer to be used to do the calculation.
        needle: Substring to search.
        haystacks: List of dictionary containing the haystack to be searched.
        key: The key within the `haystacks` dictionary that contains the actual string value.

    Return:
        Sorted list of haystacks based on the needle score with additional keys for the `score`
        and `indices`.
    N)scoreindiceshaystackc                     | d         S Nr    xs    G/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/pfzy/match.py<lambda>z_rank_task.<locals>.<lambda>(   s
    aj     Tr   reverse)r   r   appendsort)r   r   r   r   resultr   r   r   s           r   
_rank_taskr"   
   s      $ F 

 

T8(<(<S(ABBw?"$ 	
 	
 	
 	
 KK(($K777Mr       
batch_sizec           	         K   t           t                    D ]%\  }}t          |t                    ssd|i|<   &st	          dt
          j         d          t          j         fdt          dt                              D               d{V }t          j        |d dd	}g }	|D ].}
|
d
         |
d         d
<   |	                    |
d                    /|	S )a  Fuzzy find the needle within list of haystacks and get matched results with matching index.

    Note:
        The `key` argument is optional when the provided `haystacks` argument is a list of :class:`str`.
        It will be given a default key `value` if not present.

    Warning:
        The `key` argument is required when provided `haystacks` argument is a list of :class:`dict`.
        If not present, :class:`TypeError` will be raised.

    Args:
        needle: String to search within the `haystacks`.
        haystacks: List of haystack/longer strings to be searched.
        key: If `haystacks` is a list of dictionary, provide the key that
            can obtain the haystack value to search.
        batch_size: Number of entry to be processed together.
        scorer (Callable[[str, str], SCORE_indices]): Desired scorer to use. Currently only :func:`~pfzy.score.fzy_scorer` and :func:`~pfzy.score.substr_scorer` is supported.

    Raises:
        TypeError: When the argument `haystacks` is :class:`list` of :class:`dict` and the `key` argument
            is missing, :class:`TypeError` will be raised.

    Returns:
        List of matching `haystacks` with additional key indices and score.

    Examples:
        >>> import asyncio
        >>> asyncio.run(fuzzy_match("ab", ["acb", "acbabc"]))
        [{'value': 'acbabc', 'indices': [3, 4]}, {'value': 'acb', 'indices': [0, 2]}]
    Nvalue$z\ missing 1 required argument: 'key', 'key' is required when haystacks is an instance of dictc           	   3   R   K   | ]!}t          ||z                      V  "d S )N)r"   ).0offsetr%   r   r   r   r   s     r   	<genexpr>zfuzzy_match.<locals>.<genexpr>`   s^       

 

  &6J#667	 

 

 

 

 

 

r   r   c                     | d         S r   r   r   s    r   r   zfuzzy_match.<locals>.<lambda>j   s
    !G* r   Tr   r   r   )r
   	enumerate
isinstancedict	TypeErrorfuzzy_match__name__asynciogatherrangelenheapqmerger   )r   r   r   r%   r   indexr   batchesresultschoices	candidates   `````      r   r2   r2   ,   su     J ~$Y// / /x(D)) 	/  #XIe 
 C$  C  C  C
 
 	
 N

 

 

 

 

 

 

 

  3y>>:>>

 

 


 
 
 
 
 
 
G k7(<(<dKKKGG . .	+4Y+?	*i(y,----Nr   )r#   r$   N)__doc__r4   r8   typingr   r   r   r   r   r   
pfzy.scorer	   r
   
pfzy.typesr   strr"   intr2   r   r   r   <module>rE      sz   T T   9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 0 0 0 0 0 0 0 0            c3Z./ E#tCH~-./ 
	
 
$sCx.   J 26C CCC 
C 	C
 c3Z./C 
$sCx.C C C C C Cr   