a
     g%                  	   @   s  d Z ddlZddlmZmZ edededededed	ed
eddZeeZed ed	dd e
 D Zdd eD ZdZedejZedejZg ZdD ]Zeee  qed ed  ed  ZedZedZedZedZedZedZee e eee dZi Ze D ]\ZZ e D ]Zeee< qBq6e!e!d d!d"Z"e!e!d d#d$Z#e!e!d d%d&Z$e!e!d d'd(Z%e!e&d d)d*Z'e!e!d d+d,Z(dS )-z
Syllable tools
    N)thai_consonantsthai_tonemarksu   งu   มu   ยu   วu   นญณรลฬu   กขคฆu0   ดจชซฎฏฐฑฒตถทธศษสu   บปภพฟ)   กง   กม	   เกย   เกอว   กน   กก   กด   กบ   อ c                 C   s   g | ]}d  |qS )r   )join).0v r   A/usr/local/lib/python3.9/dist-packages/pythainlp/util/syllable.py
<listcomp>       r   c                 C   s   g | ]}|t vr|qS r   )_temp)r   jr   r   r   r      r   u   ะัิึุu<   เ(.*)ะ|แ(.*)ะ|เ(.*)อะ|โ(.*)ะ|เ(.*)าะu
   เ(.*)า)r   r   r   r   r   r	   r   r
   u   งนมยรลวu   คชซทพฟฮu   ฆญณธภฅฌฑฒฬu   กจดตบปอฎฏu   ขฉถผฝสหu   ศษฃฐ)lowmidhigh)syllablereturnc                 C   s  dd | D }|d }t | dk r&dS |tv rptdd | D du rptd	d | D du rptt| d
urpdS tdd | D  r|tv rtt| d
urdS || d krtt| d
urdS |tv rdS tt|  stdd | D  rdS dS tdd | D rdS tt| r(dS |tv rltt| sVtdd | D rht |dk rhdS dS tt| stdd | D rdS dS dS )u  
    Sound syllable classification

    This function is sound syllable classification.
    The syllable is a live syllable or dead syllable.

    :param str syllable: Thai syllable
    :return: syllable's type (live or dead)
    :rtype: str

    :Example:
    ::

        from pythainlp.util import sound_syllable

        print(sound_syllable("มา"))
        # output: live

        print(sound_syllable("เลข"))
        # output: dead
    c                 S   s   g | ]}|t tv r|qS r   )listthai_consonants_allr   ir   r   r   r   S   r   z"sound_syllable.<locals>.<listcomp>   deadc                 s   s   | ]}|t d v V  qdS )u   าีืแูาเโNsetr   cr   r   r   	<genexpr>Z   r   z!sound_syllable.<locals>.<genexpr>Fc                 s   s   | ]}|t d v V  qdS u	   ำใไNr#   r%   r   r   r   r'   [   r   Tc                 s   s   | ]}|t d v V  qdS )u   าีืแูาโNr#   r%   r   r   r   r'   _   r   livec                 s   s   | ]}|t tv V  qd S Nr$   shortr%   r   r   r   r'   l   s   c                 s   s   | ]}|t d v V  qdS r(   r#   r%   r   r   r   r'   q   r   c                 s   s   | ]}|t tv V  qd S r*   r+   r%   r   r   r   r'   x   r   c                 s   s   | ]}|t tv V  qd S r*   r+   r%   r   r   r   r'   ~   s   N)len_check_2anyboolpatternsearch_check_1re_short)r   
consonantsZspelling_consonantr   r   r   sound_syllable<   sh    



r6   c                 C   s>   dd | D }t |dk rdS t |dkr:|d dkr:dS dS )u  
    Open/close Thai syllables detector

    This function is used for finding Thai syllables that are open or closed sound.

    :param str syllable: Thai syllable
    :return: open / close
    :rtype: str

    :Example:
    ::

        from pythainlp.util import syllable_open_close_detector

        print(syllable_open_close_detector("มาก"))
        # output: close

        print(syllable_open_close_detector("คะ"))
        # output: open
    c                 S   s   g | ]}|t tv r|qS r   r   r   r   r   r   r   r      r   z0syllable_open_close_detector.<locals>.<listcomp>r!   openr    r   close)r-   r   r5   r   r   r   syllable_open_close_detector   s    r;   c                 C   sJ   dd | D }t |dk r0tdd | D r0dS tt| rBdS dS dS )	u  
    Thai syllable length

    This function is used for finding syllable's length. (long or short)

    :param str syllable: Thai syllable
    :return: syllable's length (long or short)
    :rtype: str

    :Example:
    ::

        from pythainlp.util import syllable_length

        print(syllable_length("มาก"))
        # output: long

        print(syllable_length("คะ"))
        # output: short
    c                 S   s   g | ]}|t tv r|qS r   r7   r   r   r   r   r      r   z#syllable_length.<locals>.<listcomp>   c                 s   s   | ]}|t tv V  qd S r*   r+   r%   r   r   r   r'      r   z"syllable_length.<locals>.<genexpr>r,   longN)r-   r/   r0   r4   r2   r:   r   r   r   syllable_length   s    r>   c                 C   s&   dd | D }|g krdS |d S d S )Nc                 S   s   g | ]}|t tv r|qS r   )r   r   r   r   r   r   r      r   z'_tone_mark_detector.<locals>.<listcomp>r   r   r   )r   	tone_markr   r   r   _tone_mark_detector   s    r@   c                 C   sH   dd | D }dd | D }|d |d kr0dS |d |d krDdS dS )Nc                 S   s   g | ]}|t v r|qS r   )thai_low_sonorantsr   r   r   r   r      r   z,_check_sonorant_syllable.<locals>.<listcomp>c                 S   s   g | ]}|t tv r|qS r   r7   r   r   r   r   r      r   r    TFr   )r   Z	_sonorantr5   r   r   r   _check_sonorant_syllable   s    rC   c           
      C   s  t | }dd | D }|d }t| }t| }t| }t| }d}t|dkr|dv rt| }	|dkr|	r|dkr|d	krd
}n|dkr|	r|dkrd
}n||dkr|	r|dkr|d	krd
}nZ|dkr|	r|dkr|dkrd}n8|dkr|	r|dkrd
}n|dkr|	r|dkrd}n|dkrN|dkrN|dkrN|dkrNd}n|dkr~|dkr~|dkr~|dkr~d}n|dkr|dkr|dkrd}nj|dkr|dkr|d	krd
}nD|dkr|dkr|d	krd
}n|dkr|dkrd}n|dkr&|dkr&d}n|dkr@|dkr@d}n|dkrZ|d	krZd}n|dkrt|dkrtd}n|dkr|dkrd}n|dkr|dkrd
}nf|dkr|dkrd
}nL|dkr|dkrd}n2|dkr|dkrd}n|dkr|dkrd}|S )ut  
    Thai tone detector for syllables

    :param str syllable: Thai syllable
    :return: syllable's tone (l, m, h, r, f or empty if it cannot be detected)
    :rtype: str

    :Example:
    ::

        from pythainlp.util import tone_detector

        print(tone_detector("มา"))
        # output: m

        print(tone_detector("ไม้"))
        # output: h
    c                 S   s   g | ]}|t tv r|qS r   r7   r   r   r   r   r      r   z!tone_detector.<locals>.<listcomp>r   r      )r      หr   r)   u   ่lr"   rE   u   ้frr   r,   r9   hr=   r8   r   r   u   ๋u   ๊m)r6   r@   r;   r>   thai_initial_consonant_to_typer-   rC   )
r   sr5   Zinitial_consonantr?   Zsyllable_checkZsyllable_check_lengthZinitial_consonant_typerH   Zconsonant_endingr   r   r   tone_detector   s    rM   ))__doc__reZ	pythainlpr   r   r   Zspelling_classr   remover   valuesr   Znot_spelling_classr,   compileUr4   r1   r3   r   extendr.   rA   Zthai_low_aspiratesZthai_low_irregularZthai_mid_plainsZthai_high_aspiratesZthai_high_irregularZthai_initial_consonant_typerK   itemskr   strr6   r;   r>   r@   r0   rC   rM   r   r   r   r   <module>   sX   

J
