o
    qi -                     @   s  U d Z ddlmZ ddlmZ ddlmZmZ i dddgd	d
gdddgdg ddg ddg ddg ddg ddg ddg ddg dddd gd!d"d#gd$d%d&gd'd(d)gd*g d+d,g d-i d.g d/d0g d1d2d3d4gd5g d6d7g d8d9g d:d;g d<d=g d>d?g d@dAg dBdCg dDdEg dFdGdHdIgdJdKdLgdMdNgdOg dPdQg dRi dSdTdUgdVg dWdXdYgdZg d[d\g d]d^g d_d`gdadbgdcg dddedfdggdhg didjg dkdlgdmdngdodpgdqdrgdsdtgdugdvgdwgdxgdygg g g g dzd{gd|gd}Zeed~< i Z	e
 D ]\ZZe	eeeee q.dedefddZdd	djdZeeef ed< dedefddZdedefddZdedefddZdkgdmgdogdqgdsgdgdgdgdgdgd
Zeed< i Ze
 D ]\ZZeeeeee qdgdgdgdgdgdgdgdgdgdgd
Zeed< i Ze
 D ]\ZZeeeeee qddededefddZdedefddZdS )z
Character Normalization functions
provides functionality to put proper spaces before and after numeric digits, urdu digits
and punctuations.
    )Dict   )_DIACRITICS_RE)_SPACE_AFTER_PUNCTUATIONS_RE$_REMOVE_SPACE_BEFORE_PUNCTUATIONS_REu   آu   ﺁu   ﺂu   أu   ﺃu   اu   ﺍu   ﺎu   ب)u   ﺏu   ﺐu   ﺑu   ﺒu   پ)u   ﭖu   ﭘu   ﭙu   ت)u   ﺕu   ﺖu   ﺗu   ﺘu   ٹ)u   ﭦu   ﭧu   ﭨu   ﭩu   ث)u   ﺛu   ﺜu   ﺚu   ج)u   ﺝu   ﺞu   ﺟu   ﺠu   ح)u   ﺡu   ﺣu   ﺤu   ﺢu   خ)u   ﺧu   ﺨu   ﺦu   دu   ﺩu   ﺪu   ذu   ﺬu   ﺫu   رu   ﺭu   ﺮu   زu   ﺯu   ﺰu   س)u   ﺱu   ﺲu   ﺳu   ﺴu   ش)u   ﺵu   ﺶu   ﺷu   ﺸu   ص)u   ﺹu   ﺺu   ﺻu   ﺼu   ض)u   ﺽu   ﺾu   ﺿu   ﻀu   طu   ﻃu   ﻄu   ظ)u   ﻅu   ﻇu   ﻈu   ع)u   ﻉu   ﻊu   ﻋu   ﻌu   غ)u   ﻍu   ﻏu   ﻐu   ف)u   ﻑu   ﻒu   ﻓu   ﻔu   ق)u   ﻕu   ﻖu   ﻗu   ﻘu   ل)u   ﻝu   ﻞu   ﻟu   ﻠu   م)u   ﻡu   ﻢu   ﻣu   ﻤu   ن)u   ﻥu   ﻦu   ﻧu   ﻨu   چ)u   ﭺu   ﭻu   ﭼu   ﭽu   ڈu   ﮈu   ﮉu   ڑu   ﮍu   ﮌu   ژu   ﮋu   ک)u   ﮎu   ﮏu   ﮐu   ﮑu   ﻛu   كu   گ)u   ﮒu   ﮓu   ﮔu   ﮕu   ںu   ﮞu   ﮟu   و)   ﻮu   ﻭr   u   ؤu   ﺅu   ھ)u   ﮪu   ﮬu   ﮭu   ﻬu   ﻫu   ﮫu   ہ)u   ﻩu   ﮦu   ﻪu   ﮧu   ﮩu   ﮨu   هu   ۂu   ۃu   ةu   ءu   ﺀu   ی)	u   ﯼu   ىu   ﯽu   ﻰu   ﻱu   ﻲu   ﯾu   ﯿu   يu   ئu   ﺋu   ﺌu   ے)u   ﮮu   ﮯu   ﻳu   ﻴu   ۓ   ۰u   ٠   ۱u   ١   ۲u   ٢   ۳u   ٣   ۴u   ٤u   ٥u   ٦u   ٧u   ٨u   ٩u   ﻻu   ﻼu   ـ)   ۵   ۶   ۷   ۸   ۹u   ۔u   ؟u   ٫u   ،u   لا CORRECT_URDU_CHARACTERStextreturnc                 C   s
   |  tS )uQ  
    The most important module in the UrduHack is the :py:mod:`~urduhack.normalization.character` module,
    defined in the module with the same name. You can use this module separately to normalize
    a piece of text to a proper specified Urdu range (0600-06FF). To get an understanding of how this module works, one
    needs to understand unicode. Every character has a unicode. You can search for any character unicode from any
    language you will find it. No two characters can have the same unicode. This module works with reference to the
    unicodes. Now as urdu language has its roots in Arabic, Parsian and Turkish. So we have to deal with all those
    characters and convert them to a normal urdu character. To get a bit more of what the above explanation means is.::

    >>> all_fes = ['ﻑ', 'ﻒ', 'ﻓ', 'ﻔ', ]
    >>> urdu_fe = 'ف'

    All the characters in all_fes are same but they come from different languages and they all have different unicodes.
    Now as computers deal with numbers, same character appearing in more than one place in a different language will
    have a different unicode and that will create confusion which will create problems in understanding the context of
    the data. :py:mod:`~character` module will eliminate this problem by replacing all the characters in all_fes by
    urdu_fe.

    This provides the functionality to replace wrong arabic characters with correct urdu characters and fixed the
    combine|join characters issue.

    Replace ``urdu`` text characters with correct ``unicode`` characters.

    Args:
        text (str): ``Urdu`` text
    Returns:
        str: Returns a ``str`` object containing normalized text.
    Examples:
        >>> from urduhack.normalization import normalize_characters
        >>> # Text containing characters from Arabic Unicode block
        >>> text = "مجھ کو جو توڑا ﮔیا تھا"
        >>> normalized_text = normalize_characters(text)
        >>> # Normalized text - Arabic characters are now replaced with Urdu characters
        >>> normalized_text
        مجھ کو جو توڑا گیا تھا
    )	translate_TRANSLATORr    r   T/home/ubuntu/.local/lib/python3.10/site-packages/urduhack/normalization/character.pynormalize_charactersS   s   
%r   )u   آu   أu   ۓCOMBINE_URDU_CHARACTERSc                 C   s"   t  D ]
\}}| ||} q| S )uJ  
    To normalize combine characters with single character unicode text, use the
    :py:func:`~urduhack.normalization.character.normalize_combine_characters` function in the
    :py:mod:`~urduhack.normalization.character` module.

    Replace combine|join ``urdu`` characters with single unicode character

    Args:
        text (str): ``Urdu`` text
    Returns:
        str: Returns a ``str`` object containing normalized text.
    Examples:
        >>> from urduhack.normalization import normalize_combine_characters
        >>> # In the following string, Alif ('ا') and Hamza ('ٔ ') are separate characters
        >>> text = "جرأت"
        >>> normalized_text = normalize_combine_characters(text)
        >>> # Now Alif and Hamza are replaced by a Single Urdu Unicode Character!
        >>> normalized_text
        جرأت
    )r   itemsreplace)r   _key_valuer   r   r   normalize_combine_characters   s   r!   c                 C   s   t d| } td| } | S )u  
    Add spaces after punctuations used in ``urdu`` writing

    Args:
        text (str): ``Urdu`` text
    Returns:
        str: Returns a ``str`` object containing normalized text.
    Examples:
        >>> from urduhack.normalization.character import punctuations_space
        >>> text = "ہوتا ہے   ۔  ٹائپ"
        >>> normalized_text = punctuations_space(text)
        >>> normalized_text
        ہوتا ہے۔ ٹائپ
     z\1)r   subr   r   r   r   r   punctuations_space   s   r$   c                 C   s   t d| S )u-  
    Remove ``urdu`` diacritics from text. It is an important step in pre-processing of the Urdu data.
    This function returns a String object which contains the original text minus Urdu diacritics.

    Args:
        text (str): ``Urdu`` text
    Returns:
        str: Returns a ``str`` object containing normalized text.
    Examples:
        >>> from urduhack.normalization import remove_diacritics
        >>> text = "شیرِ پنجاب"
        >>> normalized_text = remove_diacritics(text)
        >>> normalized_text
        شیر پنجاب
    r   )r   r#   r   r   r   r   remove_diacritics   s   r%   r   r   r   r   r   )
0123456789ENG_URDU_DIGITS_MAPr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   )
r   r	   r
   r   r   r   r   r   r   r   URDU_ENG_DIGITS_MAPTwith_engc                 C   s   |r|  tS |  tS )z
    Replace urdu digits with English digits and vice versa

    Args:
        text (str): Urdu text string
        with_eng (bool): Boolean to convert digits from one language to other
    Returns:
        Text string with replaced digits
    )r   _ENG_DIGITS_TRANSLATOR_URDU_DIGITS_TRANSLATOR)r   r2   r   r   r   replace_digits   s   


r5   c                 C   s.   t | ts	tdt| } t| } t| } | S )u  
    To normalize some text, all you need to do pass ``unicode`` text. It will return a ``str``
    with normalized characters both single and combined, proper spaces after digits and punctuations
    and diacritics removed.

    Args:
        text (str): ``Urdu`` text
    Returns:
        str: Normalized urdu text
    Raises:
        TypeError: If text param is not not str Type.
    Examples:
        >>> from urduhack import normalize
        >>> text = "اَباُوگل پاکستان ﻤﯿﮟ 20 سال ﺳﮯ ، وسائل کی کوئی کمی نہیں ﮨﮯ۔"
        >>> normalized_text = normalize(text)
        >>> # The text now contains proper spaces after digits and punctuations,
        >>> # normalized characters and no diacritics!
        >>> normalized_text
        اباوگل پاکستان ﻤﯿﮟ 20 سال ﺳﮯ ، وسائل کی کوئی کمی نہیں ﮨﮯ۔
    ztext must be str type.)
isinstancestr	TypeErrorr%   r   r!   r   r   r   r   	normalize   s   
r9   N)T)__doc__typingr   regexesr   r   r   r   __annotations__r   r   keyvalueupdatedictfromkeysmapordr7   r   r   r!   r$   r%   r0   r3   r1   r4   boolr5   r9   r   r   r   r   <module>   s<  	
 !"#$%&'()*+,-./0123A(
