o
    noiC                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ deded	efd
dZ	dede
de
d	ee eee ee f B fddZdedee de
d	ee fddZdS )    N)DIRECT_DICT)NUMBER_SCALE_DICT)PREFIX_REPLACEMENTS)VARIATIONS_DICT)combineprimary_textsecondary_textreturnc                    s   t  fddtD d}|rTt|  D ]?\}}t fdd|D d}|rS dt|  t| |   |dv r=|dksI|dv sI|dkrQ|d	krQt|d  nq  }td
|}|S )a<  
    Combine two morphemes according to Sanskrit samasa rules.

    Args:
        primary_text (str): The primary text to be combined.
        secondary_text (str): The secondary text to be attached to the primary.

    Returns:
        str: The resulting combined text with a normalized Unicode representation.
    c                 3       | ]
}  |r|V  qd S N)endswith).0key)r    Q/home/ubuntu/.local/lib/python3.10/site-packages/indic_numtowords/san/cardinal.py	<genexpr>       z$combine_morphemes.<locals>.<genexpr>Nc                 3   r
   r   )
startswith)r   val)r   r   r   r      r   )   दu   विu   त्रिu   चu   पu   षu   सu   नu   लu   शu   कोu   खu   मu   जu	   एकं)u   अu   उr   u	   षट्NFC)nextr   itemslenunicodedata	normalize)r   r   suffixsuffixesreplacementmatched_prefixcombined
normalizedr   )r   r   r   combine_morphemes   s   (r"   
number_strindex
number_lenc                    sf  g }g }|dkrt | dkrdn|dkr|dkrdnd t | dkrw| d dkrA|t| d   |dd t| d g D  | d	d d
} |dkrPdnd || r`tt|  d  gng  | fddt| g D  ||fS  r|dkr|tt|  d  g | fddt| g D  |S |t|   |dd t| g D  |S )z
    Convert a number to its text representation.

    Args:
        number_str (str): The number to convert.

    Returns:
        list[str]: The text representation of the number.
       u   उत्तरr      अधिकN1c                 s       | ]}|V  qd S r   r   r   	variationr   r   r   r   4       z"convert_to_text.<locals>.<genexpr>   0c                       g | ]}t | qS r   r"   r*   r   r   r   
<listcomp>9       z#convert_to_text.<locals>.<listcomp>c                    r/   r   r0   r*   r1   r   r   r2   @   r3   c                 s   r)   r   r   r*   r   r   r   r   C   r,   )r   extendr   r   getlstripr"   )r#   r$   r%   textsprefixesr   r1   r   convert_to_text!   s&   
0 "  r9   r7   c                    s&  t | tr
t  tstd| dv s dkr| dkr|S | dp"d} tt  d  dkrft| dkr_t|  |\}}|dkrCdnd fdd	|D pPg}t|fd
d	|D d}n.t|  |}n'| dkrpt|  |ng }|rvdndfdd	|D pg}fdd	|D }t||dS )a  
    Convert a number string to its text representation and append it to a list.

    Args:
        number_str (str): The number string to process.
        texts (list[str]): A list of texts to update with the converted number.
        index (int): The position of the number in the sequence, affecting scaling.
        number_len (int): The total length of the original number.

    Returns:
        list[str]: The updated list with the number's text representation appended.
    zInvalid input type>   00000r   r.   r&   r'    c                    s"   g | ]}t |tt  d  qS )r   )r"   r   strr   prefix)r$   r   r   r2   b   s   " z process_text.<locals>.<listcomp>c                    r/   r   r0   r   combined_prefixr1   r   r   r2   d   r3   r(   c                    r/   r   r0   r>   )scaler   r   r2   k   r3   c                    r/   r   r0   r@   r1   r   r   r2   l   r3   )	
isinstancer=   int
ValueErrorr6   r   r   r9   r   )r#   r7   r$   r%   r8   converted_textcombined_prefixesr   )r$   rB   r   r   process_textG   s*   rH   )r   indic_numtowords.san.data.numsr   r   r   r   indic_numtowords.san.utilsr   r=   r"   rD   listtupler9   rH   r   r   r   r   <module>   s    2&&