a
     g                     @   s   d Z ddlmZ ddlmZmZ ddlmZ ddlmZ dZ	dZ
e Zejee	ddd	d
d ejee
ddd	d
d deeee dddZdeeedddZdee eee dddZdee ee dddZdS )z
symspellpy

symspellpy is a Python port of SymSpell v6.5.
We used unigram & bigram from Thai National Corpus (TNC).

:See Also:
    *         https://github.com/mammothb/symspellpy
    )List)SymSpell	Verbosity)get_corpus_path)path_pythainlp_corpusztnc_freq.txtZtnc_bigram_word_freqs   	z	utf-8-sig)	separatorencoding   )textmax_edit_distancereturnc                 C   s    dd t tj| tj|dD S )Nc                 S   s"   g | ]}t |jd ddd qS ),r   maxsplitr   strsplit.0i r   D/usr/local/lib/python3.9/dist-packages/pythainlp/spell/symspellpy.py
<listcomp>    s   zspell.<locals>.<listcomp>r   )list	sym_spelllookupr   ZCLOSESTr   r   r   r   r   spell   s    r    c                 C   s   t | |dd S )Nr   r   )r    r   r   r   r   correct*   s    r!   )
list_wordsr   r   c                 C   s@   dd t tjd| d|dD }g }|D ]}|| q,|S )Nc                 S   s(   g | ] }t |jd ddd dqS )r   r   r   r    r   r   r   r   r   r   /   s   zspell_sent.<locals>.<listcomp>r#   T)Zsplit_by_spacer   )r   r   Zlookup_compoundjoinappend)r"   r   _tempZlist_newr   r   r   r   
spell_sent.   s    
r'   )r"   r   c                 C   s   dd t | |dD S )Nc                 S   s   g | ]}|d  qS )r   r   r   r   r   r   r   A   s   z correct_sent.<locals>.<listcomp>r   )r'   )r"   r   r   r   r   correct_sent@   s    
r(   N)r   )r   )r   )r   )__doc__typingr   Z
symspellpyr   r   Zpythainlp.corpusr   r   Z_UNIGRAMZ_BIGRAMr   Zload_dictionaryZload_bigram_dictionaryr   intr    r!   r'   r(   r   r   r   r   <module>   s"   
