a
     gl                     @   s\   d Z ddlZddlmZmZ edZedZeedddZ	dee
ee d
ddZdS )zl
Thai collation (sorted according to Thai dictionary order)
Simple implementation using regular expressions
    N)IterableListu	   [็-์]u   ([เ-ไ])([ก-ฮ]))wordreturnc                 C   s,   t d| }td|}t d| }|| S )N z\2\1 )_RE_TONEsub_RE_LV_C)r   ZcvZtone r   @/usr/local/lib/python3.9/dist-packages/pythainlp/util/collate.py_thkey   s    r   F)datareverser   c                 C   s   t | t|dS )u  
    This function sorts strings (almost) according to Thai dictionary.

    Important notes: this implementation ignores tone marks and symbols

    :param data: a list of words to be sorted
    :type data: Iterable
    :param reverse: If `reverse` is set to **True** the result will be
                         sorted in descending order. Otherwise, the result
                         will be sorted in ascending order, defaults to False
    :type reverse: bool, optional

    :return: a list of strings, sorted alphabetically, (almost) according to
             Thai dictionary
    :rtype: List[str]

    :Example:
    ::

        from pythainlp.util import collate

        collate(['ไก่', 'เกิด', 'กาล', 'เป็ด', 'หมู', 'วัว', 'วันที่'])
        # output: ['กาล', 'เกิด', 'ไก่', 'เป็ด', 'วันที่', 'วัว', 'หมู']

        collate(['ไก่', 'เกิด', 'กาล', 'เป็ด', 'หมู', 'วัว', 'วันที่'], \
            reverse=True)
        # output: ['หมู', 'วัว', 'วันที่', 'เป็ด', 'ไก่', 'เกิด', 'กาล']
    )keyr   )sortedr   )r   r   r   r   r   collate   s    r   )F)__doc__retypingr   r   compiler   r
   strr   boolr   r   r   r   r   <module>   s   

