o
    f                     @  s  U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZmZmZ dadd Ze  G dd	 d	Zd.ddZd.ddZd.ddZd.ddZd/ddZd0ddZd1d!d"Zd2d%d&Zd3d'd(Zd)eiZded*< d)eiZded+< d)eiZded,< d)eiZded-< dS )4    )annotationsN)isnan)AnyCallable)AVX2SSE2supportsc                  C  s0   t d u rtjd} t| dr| ja d S d S d S )NpandasNA)	pandas_NAsysmodulesgethasattrr
   )r	    r   I/home/ubuntu/webapp/venv/lib/python3.10/site-packages/rapidfuzz/_utils.pysetupPandas   s   

r   c                   @  s   e Zd ZdZdZdZdZdS )
ScorerFlag    @      i   N)__name__
__module____qualname__
RESULT_F64
RESULT_I64RESULT_SIZE_T	SYMMETRICr   r   r   r   r      s
    r   _kwargsr   returndict[str, Any]c                  K     ddt jt jB dS )Nr       optimal_scoreworst_scoreflagsr   r   r   r   r   r   r   _get_scorer_flags_distance#      
r)   c                  K  r!   )Nr"   r   r#   r'   r(   r   r   r   _get_scorer_flags_similarity+   r*   r+   c                  K  r!   )Nr      r#   r   r   r   r(   r   r   r   %_get_scorer_flags_normalized_distance3   r*   r.   c                  K  r!   )Nr,   r   r#   r-   r(   r   r   r   '_get_scorer_flags_normalized_similarity;   r*   r/   sboolc                 C  s.   | d u s| t u r
dS t| trt| rdS dS )NTF)r   
isinstancefloatr   )r0   r   r   r   is_noneC   s
   r4   funccached_scorer_call(dict[str, Callable[..., dict[str, Any]]]c                 C  s   || _ | | _d S )N)_RF_ScorerPy_RF_OriginalScorer)r5   r6   r   r   r   add_scorer_attrsM   s   
r:   modulestrc                 C  s"   zt | W S  ty   Y dS w )z6
    try to import module. Return None on failure
    N)	importlibimport_module	Exception)r;   r   r   r   optional_import_moduleS   s
   r@   nametuple[Any, list[Any]]c                 C  sJ   t trt| d }|dur|S t tr t| d }|dur |S t| S )z4
    import module best fitting for current CPU
    _avx2N_sse2)r   r   r@   r   r=   r>   )rA   r;   r   r   r   vectorized_import]   s   
rE   c                 C  s   t jd}t| d }t||}|s&d|d|jd|j d}t||dkr1t	| d }n|d	kr7|S zt	| d }W n t
yJ   | Y S w t||}|sdd|d|jd|j d}t||S )
z}
    import library function and possibly fall back to a pure Python version
    when no C++ implementation is available
    RAPIDFUZZ_IMPLEMENTATION_pyzcannot import name z from z ()cpp_cpppython)osenvironr   r=   r>   getattr__name__file__ImportErrorrE   r?   )r;   rA   implpy_modpy_funcmsgcpp_modcpp_funcr   r   r   fallback_importm   s(   

rX   get_scorer_flagsdefault_distance_attributedefault_similarity_attribute%default_normalized_distance_attribute'default_normalized_similarity_attribute)r   r   r   r    )r0   r   r   r1   )r5   r   r6   r7   )r;   r<   r   r   )rA   r<   r   rB   )r;   r<   rA   r<   r   r   )
__future__r   r=   rL   r   mathr   typingr   r   rapidfuzz._feature_detectorr   r   r   r   r   r   r)   r+   r.   r/   r4   r:   r@   rE   rX   rZ   __annotations__r[   r\   r]   r   r   r   r   <module>   s6   










"