a
     g"                  ]   @   sZ  d Z ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]\Zd^d_ e D ZeeZeeZg d`g dag dbg dcgZg ddg deg dfg dggZ	eedhdidjZ
eedhdkdlZdreeeedndodpZdqS )sz'
Functions related to keyboard layout.
(   ผ)   ป   ฉ   แ   ฮ   อ   ฺ   ิ   ์   ื?   ท   ฒ   ม   ฬ   ใ   ฦ   ฝ   ฤ   ฟ   ฆ   ห   ฏ   ก   โ   ด   ฌ   เ   ็   ้   ๋   ่   ษ   า   ศ   ส   ซ   ว.   ง   ๐   ๆ"   ไ   ฎ   ำ   ฑ   พ   ธ   ะ   ํ   ั   ๊   ี   ณ   ร   ฯ   น   ญ   ย   ฐ   บ,   ล   ฅ   ฃ%_   ๑/   ๒-   ๓   ภ   ๔   ถ   ู   ุ   ฿   ึ   ๕   ค   ๖   ต   ๗   จ   ๘   ข   ๙   ช)\ZzXxCcVvBbNnMm<rA   >r)   r   rH   AaSsDdFfGgHhJjKkLl:;r-   'QqWwEeRrTtYyUuIiOoPp{[}]|\~`@2#3$4rE   5^6&7*8r   9r   0rF   rJ   +=c                 C   s   i | ]\}}||qS  r   ).0r|   rd   r   r   A/usr/local/lib/python3.9/dist-packages/pythainlp/util/keyboard.py
<dictcomp>g       r   )rJ   u   ๅrH    rF   rL   rN   rP   rR   rT   rV   rX   rZ   r\   )r,   r.   r0   r2   r4   r6   r8   r:   r<   r>   r@   rB   rD   )r   r   r   r   r   r    r"   r$   r&   r(   r*   )
r   r   r   r   r
   r   r   r   r   r   )rE   r   rG   rI   rK   rM   rO   rQ   rS   rU   rW   rY   r[   )r+   r-   r/   r1   r3   r5   r7   r9   r;   r=   r?   rA   rC   )r   r   r   r   r   r   r!   r#   r%   r'   r)   )
r   r   r   r   r	   r   r   r   r   r   )textreturnc                 C   s
   |  tS )u  
    Corrects the given text that was incorrectly typed using English-US
    Qwerty keyboard layout to the originally intended keyboard layout
    that is the Thai Kedmanee keyboard.

    :param str text: incorrect text input (Thai typed using English keyboard)
    :return: Thai text with typing using
             incorrect keyboard layout is corrected
    :rtype: str

    :Example:

    Intentionally type "ธนาคารแห่งประเทศไทย", but got "Tok8kicsj'xitgmLwmp"::

        from pythainlp.util import eng_to_thai

        eng_to_thai("Tok8kicsj'xitgmLwmp")
        # output: ธนาคารแห่งประเทศไทย
    )	translateEN_TH_TRANSLATE_TABLEr   r   r   r   eng_to_thaiz   s    r   c                 C   s
   |  tS )u  
    Corrects the given text that was incorrectly typed using Thai Kedmanee
    keyboard layout to the originally intended keyboard layout
    that is the English-US Qwerty keyboard.

    :param str text: incorrect text input (English typed using Thai keyboard)
    :return: English text with typing with
             incorrect keyboard layout is corrected
    :rtype: str

    :Example:

    Intentionally type "Bank of Thailand", but got "ฺฟืา นด ธ้ฟรสฟืก"::

        from pythainlp.util import eng_to_thai

        thai_to_eng("ฺฟืา นด ธ้ฟรสฟืก")
        # output: 'Bank of Thailand'
    )r   TH_EN_TRANSLATE_TABLEr   r   r   r   thai_to_eng   s    r           )c1c2
shift_distr   c                 C   sj   t tgftddd}|| }||}|d |d  d |d |d  d  d }|dkrf| |krf|S |S )u  
    Calculate Euclidean distance between two Thai characters
    according to their location on a Thai keyboard layout.

    A modified TIS 820-2531 standard keyboard layout, which is developed
    from Kedmanee layout and is the most commonly used Thai keyboard layout,
    is used in distance calculation.

    The modified TIS 820-2531 is TIS 820-2531 with few key extensions
    proposed in TIS 820-2536 draft. See Figure 4, notice grey keys, in
    https://www.nectec.or.th/it-standards/keyboard_layout/thai-key.html

    Noted that the latest TIS 820-2538 has slight changes in layout from
    TIS 820-2531. See Figure 2, notice the Thai Baht sign and ฅ-ฃ pair, in
    https://www.nectec.or.th/it-standards/std820/std820.html
    Since TIS 820-2538 is not widely adopted by keyboard manufacturer,
    this function uses the de facto standard modified TIS 820-2531 instead.

    :param str c1: first character
    :param str c2: second character
    :param str shift_dist: return value if they're shifted
    :return: Euclidean distance between two characters
    :rtype: float

    :Example:

        from pythainlp.util import thai_keyboard_dist
        thai_keyboard_dist("ด", "ะ")
        # output: 1.4142135623730951
        thai_keyboard_dist("ฟ", "ฤ")
        # output: 0.0
        thai_keyboard_dist("ฟ", "ห")
        # output: 1.0
        thai_keyboard_dist("ฟ", "ก")
        # output: 2.0
        thai_keyboard_dist("ฟ", "ฤ", 0.5)
        # output: 0.5
    )chc                 S   sP   |D ]:}|D ]0}| |v r| |}| | }||f    S qqt| d d S )Nz# not found in given keyboard layout)index
ValueError)r   ZlayoutsZlayoutrowr   rb   r   r   r   get_char_coord   s    

z*thai_keyboard_dist.<locals>.get_char_coord          g      ?)TIS_820_2531_MODTIS_820_2531_MOD_SHIFTstr)r   r   r   r   Zcoord1Zcoord2Zdistancer   r   r   thai_keyboard_dist   s    )&r   N)r   )__doc__ZEN_TH_KEYB_PAIRSitemsZTH_EN_KEYB_PAIRSr   	maketransr   r   r   r   r   r   floatr   r   r   r   r   <module>   s   _

