
    j	                        U d Z ddlmZ ddlZddlZddlZddlmZmZ 	 ddl	Z	eegef   Zdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Zdd
ZddZddZddZeZded<   ddZeZded<   y# e
$ r dZ	Y Lw xY w)z0Shared text preprocessing utilities for metrics.    )annotationsN)CallableLiteralTFNFKC)	lowercasestrip_accentsremove_punctuation
keep_emojinormalize_formc                   t        j                  ||       }|r|j                         }|st        |      }|rt	        |      }|rt        |      }t        |      }|j                         S )a  Normalize text before metric processing.

    Args:
        text: Input string.
        lowercase: Whether to lowercase the text.
        strip_accents: Remove diacritical marks.
        remove_punctuation: Strip ASCII punctuation.
        keep_emoji: Preserve emoji characters; if False they are removed.
        normalize_form: Unicode normalization form to apply (default NFKC).
    )unicodedata	normalizelower_remove_emoji_strip_accents_remove_punctuation_collapse_whitespacestrip)textr   r   r	   r
   r   
normalizeds          v/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/evaluation/preprocessing.pynormalize_textr      sg    ( &&~t<J%%'
":.
#J/
(4
%j1J    c                l    t         dj                  d | D              S t        j                  | d      S )N c              3  P   K   | ]  }t        j                  |      d vs|   yw)>   SkSoNr   category.0chs     r   	<genexpr>z _remove_emoji.<locals>.<genexpr>9   s&      
2!5!5b!9!MBs   &&)replace)emojijoinreplace_emojir   s    r   r   r   7   s:    }ww 

 
 	
 tR00r   c                ^    t        j                  d|       }dj                  d |D              S )NNFDr   c              3  R   K   | ]  }t        j                  |      d k7  s| ! yw)MnNr   r!   s     r   r$   z!_strip_accents.<locals>.<genexpr>A   s#     O
"k.B.B2.F$.N2
s   '')r   r   r'   )r   
decomposeds     r   r   r   ?   s)    &&ud3J77O
OOOr   c                    t         j                  ddt        j                        }| j	                  |      }t        j                  dd|      S )Nr   z6[\u2010-\u2015\u2018-\u201f\u2020-\u2027\u2030-\u2043])str	maketransstringpunctuation	translateresub)r   
translatorstrippeds      r   r   r   D   s@    r2v'9'9:J~~j)H66A2x r   c                0    t        j                  dd|       S )Nz\s+ )r5   r6   r)   s    r   r   r   L   s    66&#t$$r   _NormalizerDEFAULT_NORMALIZERc                     t        | ddd      S )NTF)r   r	   r
   )r   r)   s    r   ascii_normalizerr>   S   s    	 r   ASCII_NORMALIZER)r   r0   r   boolr   r@   r	   r@   r
   r@   r   z%Literal['NFC', 'NFD', 'NFKC', 'NFKD']returnr0   )r   r0   rA   r0   )__doc__
__future__r   r5   r2   r   typingr   r   r&   ImportErrorr0   r;   r   r   r   r   r   r<   __annotations__r>   r?    r   r   <module>rH      s    6 " 	   $ ucz" $<B"
" " 	"
 " " :" 	"J1P
% #1 K 0 !1 + 0a  Es   A& &A0/A0