o
    
i                     @   s  d Z ddlZddlZddlZddlmZ ddlmZ zej	d W n e
y0   ed Y nw ddlmZmZmZmZmZmZmZmZmZmZmZmZ dd	lmZmZmZmZ dd
lmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' G dd de(Z)e*dkre) Z+e+d dS dS )z"
https://github.com/kyubyong/g2pK
    N)h2j)cmudictzcorpora/cmudict.zipr      )jyeoyeconsonant_uijosa_uivowel_uijamorieulgiyeok
rieulbieub
verb_nieunbalb
palatalizemodifying_rieul)link1link2link3link4)annotatecomposegroupglossparse_tableget_rule_id2text)convert_eng)convert_numc                   @   s0   e Zd Zdd Zdd ZdddZdd	d
ZdS )G2pc                 C   sH   |   | _t | _t | _t | _t	j
t	j
t	j
td| _d S )Nz
idioms.txt)	get_mecabmecabr   tabler   dictcmur   	rule2textospathjoindirnameabspath__file__idioms_path)self r,   E/home/ubuntu/.local/lib/python3.10/site-packages/misaki/g2pkc/g2pk.py__init__   s
   

$zG2p.__init__c                 C   s8   t jdkrdd l}| S t jdkrdd l}| S d S )Nntr   posix)r$   nameMeCabTaggerr   )r+   r2   r   r,   r,   r-   r   "   s   

zG2p.get_mecabFc           	      C   sZ   d}|}t | jdddD ]}|dd d}d|v r*|d\}}t|||}q|S )	ua  Process each line in `idioms.txt`
        Each line is delimited by "===",
        and the left string is replaced by the right one.
        inp: input string.
        descriptive: not used.
        verbose: boolean.

        >>> idioms("지금 mp3 파일을 다운받고 있어요")
        지금 엠피쓰리 파일을 다운받고 있어요
        zfrom idioms.txtrutf8)encoding#r   
z===)openr*   splitrstripresub)	r+   stringdescriptiveverboseruleoutlinestr1str2r,   r,   r-   idioms*   s   z
G2p.idiomsTc                 C   s   |  |||}t|| j}|rt|| j}t|}t|}ttt	t
ttttttttfD ]}||||}q+tdd|}| jD ]\}	}
}|}t|	|
|}q>tttfD ]}||||}qR|rat|}|rgt|}|dd}|S )u_  Main function
        string: input string
        descriptive: boolean.
        verbose: boolean
        group_vowels: boolean. If True, the vowels of the identical sound are normalized.
        to_syl: boolean. If True, hangul letters or jamo are assembled to form syllables.

        For example, given an input string "나의 친구가 mp3 file 3개를 다운받고 있다",
        STEP 1. idioms
        -> 나의 친구가 엠피쓰리 file 3개를 다운받고 있다

        STEP 2. English to Hangul
        -> 나의 친구가 엠피쓰리 파일 3개를 다운받고 있다

        STEP 3. annotate
        -> 나의/J 친구가 엠피쓰리 파일 3개/B를 다운받고 있다

        STEP 4. Spell out arabic numbers
        -> 나의/J 친구가 엠피쓰리 파일 세개/B를 다운받고 있다

        STEP 5. decompose
        -> 나의/J 친구가 엠피쓰리 파일 세개/B를 다운받고 있다

        STEP 6-9. Hangul
        -> 나의 친구가 엠피쓰리 파일 세개를 다운받꼬 읻따
        z/[PJEB] ^)rF   r   r"   r   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r<   r=   r    r   r   r   r   r   replace)r+   r>   r?   r@   group_vowelsto_syluse_dictinpfuncrD   rE   rule_ids_inpr,   r,   r-   __call__A   s.   
	zG2p.__call__N)FF)FFFFT)__name__
__module____qualname__r.   r   rF   rQ   r,   r,   r,   r-   r      s
    	
r   __main__u5   나의 친구가 mp3 file 3개를 다운받고 있다),__doc__r$   r<   nltkr
   r   nltk.corpusr   datafindLookupErrordownloadspecialr   r   r   r   r	   r   r   r   r   r   r   regularr   r   r   r   utilsr   r   r   r   r   r   englishr   numeralsr   objectr   rR   g2pr,   r,   r,   r-   <module>   s(   8 t