o
    KÎµi«  ã                   @   sp   d Z ddlmZ ddlZddlZddlmZmZmZ dd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )z“
@authors:aniruddha-adhikary,Mahir Labib Chowdhury
source:https://github.com/banglakit/number-to-bengali-word/blob/main/number_to_bengali/utils.py
é    )Úprint_functionNé   )Únumeric_wordsÚnumbersÚunitsc                 C   sj   t | tƒst | tƒst | tƒr3t | tƒr1zd| v r t| ƒ} W | S t| ƒ} W | S  ty0   Y dS w | S dS )z 
        sanitizes an input
    Ú.N)Ú
isinstanceÚfloatÚintÚstrÚ
ValueError)Únumber© r   úI/home/ubuntu/.local/lib/python3.10/site-packages/bnnumerizer/numerizer.pyÚinput_sanitizer   s   ÿ


ýþÿr   c                 C   sz   t ƒ }t | d ¡|d< | d } t | d ¡|d< | d } t | d ¡|d< | d } t | d ¡|d< | d } | |d	< |S )
z;
    Generating the unit segments such as koti, lokkho
    i€–˜ Úkotii † Úlokkhoiè  Úhazaréd   ÚsotokÚekok)ÚdictÚmathÚfloor)r   Úsegmentsr   r   r   Úgenerate_segments#   s   r   c                 C   sF   d}| D ]}| | r|t t| | ƒ d t|  d 7 }q|dd… S )zF
    Generating the bengali word for the whole part of the number
    Ú ú Néþÿÿÿ)r   r   r   )r   Úgenerated_wordsÚsegmentr   r   r   Úwhole_part_word_gen3   s   ÿÿÿ€r!   c                 C   s.   d}t | ƒD ]
}|t| d 7 }q|dd… S )zG
    Generating bengali words for the part after the decimal point
    r   r   Néÿÿÿÿ)r   r   )Úfractionr   Údigitr   r   r   Úfraction_to_words@   s   r%   c                 C   s0   t | ƒ}d|v rtdd„ | d¡D ƒƒS | dfS )z›
    Extracting the float and int part from the passed number. The first return
    is the part before the decimal point and the rest is the fraction.
    r   c                 S   s   g | ]}t |ƒ‘qS r   )r
   )Ú.0Úxr   r   r   Ú
<listcomp>P   s    z(float_int_extraction.<locals>.<listcomp>N)r   ÚtupleÚsplit)r   Ú_numberr   r   r   Úfloat_int_extractionI   s   r,   c                 C   sP   d}t | ƒ} t| ƒ\}}t|ƒ}t|ƒ}|r&|r |d t|ƒ S dt|ƒ S |S )zN
    Takes a number and outputs the word form in Bengali for that number.
    r   u    à¦¦à¦¶à¦®à¦¿à¦• u   à¦¦à¦¶à¦®à¦¿à¦• )r   r,   r   r!   r%   )r   r   Úwholer#   Úwhole_segmentsr   r   r   Ú
to_bn_wordU   s   r/   c           
      C   sÆ   g }d}t | ƒD ]\}}|tv r||7 }q| |¡ d}q| |¡ dd„ |D ƒ}g }|D ]$}d}|D ]}|dkrC|tt |¡ƒ7 }q3||7 }q3| |t|ƒf¡ q-|D ]}|\}}	|  ||	¡} qT| S )z,
        numerizes a given bangla text 
    r   c                 S   s   g | ]}|d kr|‘qS )r   r   )r&   Únr   r   r   r(   {   s    znumerize.<locals>.<listcomp>r   )Ú	enumerater   Úappendr   Úindexr/   Úreplace)
ÚtextÚnumsÚnumÚidxr0   ÚnumdataÚennumÚiÚkÚvr   r   r   Únumerizem   s*   



r>   )Ú__doc__Ú
__future__r   Úenumr   Úwordsr   r   r   r   r   r!   r%   r,   r/   r>   r   r   r   r   Ú<module>   s   	