o
    
i                     @   sR   d dl mZ ddlmZmZ ddlmZ ddlZddlZddl	Z	G dd dZ
dS )   )pinyin_to_ipa    )lazy_pinyinStyle)TupleNc                   @   sp   e Zd ZdddZedd Zedd Zed	d
 Zedd Zede	fddZ
ddee	df fddZdS )ZHG2PN   ❓c                 C   sT   || _ d | _|| _|| _|dkr&ddlm} ||d| _|d u r(td d S d S d S )Nz1.1r   )
ZHFrontend)unkz7Warning: en_callable is None, so English may be removed)versionfrontenden_callabler
   zh_frontendr	   print)selfr   r
   r   r	    r   =/home/ubuntu/.local/lib/python3.10/site-packages/misaki/zh.py__init__	   s   zZHG2P.__init__c                 C   st   |  dd} |  dd} |  dd} |  dd} |  td	td
 d tdtd
 d} td
| vs8J | | S )Nu   ˧˩˧u   ↓u   ˧˥u   ↗u   ˥˩u   ↘u   ˥u   →i{  i)  u   ɨiy  )replacechr)pr   r   r   retone   s   ,zZHG2P.retonec                 C   s   d dd t| d D S )N c                 s       | ]}t |V  qd S N)r   r   ).0r   r   r   r   	<genexpr>        zZHG2P.py2ipa.<locals>.<genexpr>r   )joinr   )pyr   r   r   py2ipa   s   zZHG2P.py2ipac                 C   s$   t | tjdd}ddd |D S )NT)styleneutral_tone_with_fiver   c                 s   r   r   )r   r    )r   r   r   r   r   r   %   r   z!ZHG2P.word2ipa.<locals>.<genexpr>)r   r   TONE3r   )wpinyinsr   r   r   word2ipa"   s   zZHG2P.word2ipac                 C   s   |  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} |  S )Nu   、z, u   ，u   。z. u   ．u   ！z! u   ：z: u   ；z; u   ？z?    «u    “   »u   ” u   《u   》u   「u   」u   【u   】u   （z (u   ）z) )r   strip)textr   r   r   map_punctuation'   s   zZHG2P.map_punctuationreturnc                 C   sj   t d| d }d}t d| D ]}|r%tj|dd}ddd	 |D }||7 }| }q|td
dS )Nu	   [一-鿿]r   r   u   [一-鿿]+|[^一-鿿]+F)cut_all c                 s   r   r   )r   r&   )r   r$   r   r   r   r   =   r   z$ZHG2P.legacy_call.<locals>.<genexpr>i/  )rematchfindalljiebalcutr   r   r   )r*   is_zhresultsegmentwordsr   r   r   legacy_call6   s   zZHG2P.legacy_callc                 C   s   |  sdS t|d}t|}| jd u rt|d fS |d u r$| jn|}g }t	d|D ],\}}|  |  }}|rH|
| |d  q.|d u rS|
| j q.|
|| q.d|d fS )N)r   Nan2cnz1([A-Za-z \'-]*[A-Za-z][A-Za-z \'-]*)|([^A-Za-z]+)r   r.   )r)   cn2an	transformr   r+   r   r8   r   r/   r1   appendr
   r   )r   r*   r   segmentsenzhr   r   r   __call__B   s    

zZHG2P.__call__)Nr   Nr   )__name__
__module____qualname__r   staticmethodr   r    r&   r+   strr8   r   r@   r   r   r   r   r      s    

	


r   )transcriptionr   pypinyinr   r   typingr   r:   r2   r/   r   r   r   r   r   <module>   s    