o
    ¡¿¯i
  ã                   @   s    d Z ddlZdd„ Zdd„ ZdS )z0Utility functions for the text translation task.é    Nc                    st   t tt| d dd… ƒƒ}‡ fdd„|D ƒ}t| d ƒ}d dd„ |D ƒ¡}d |¡}d	 |¡ d
d¡}||||fS )zäParse hypothesis.

    :param list hyp: recognition hypothesis
    :param list char_list: list of characters
    :return: recognition text string
    :return: recognition token string
    :return: recognition tokenid string
    Úyseqé   Nc                    s   g | ]}ˆ | ‘qS © r   ©Ú.0Úidx©Ú	char_listr   úF/home/ubuntu/.local/lib/python3.10/site-packages/espnet/mt/mt_utils.pyÚ
<listcomp>   ó    z$parse_hypothesis.<locals>.<listcomp>Úscoreú c                 S   s   g | ]}t |ƒ‘qS r   )Ústrr   r   r   r
   r      r   Ú z<space>)ÚlistÚmapÚintÚfloatÚjoinÚreplace)Úhypr	   Útokenid_as_listÚtoken_as_listr   ÚtokenidÚtokenÚtextr   r   r
   Úparse_hypothesis   s   

r   c                 C   sF  t ƒ }d|  ¡ v r| d |d< g |d< t|dƒD ]ˆ\}}t||ƒ\}}}}	t| d ƒdkr8t | d d  ¡ ƒ}
nddi}
|
d  d| 7  < ||
d< ||
d	< ||
d
< |	|
d< | d d d |
d< | d d d |
d< | d d d |
d< |d  |
¡ |dkr d|
 ¡ v rŽt d|
d  ¡ t d|
d  ¡ t d|
d  ¡ q|S )zÞAdd N-best results to json.

    :param dict js: groundtruth utterance dict
    :param list nbest_hyps: list of hypothesis
    :param list char_list: list of characters
    :return: N-best results added utterance dict
    Úutt2spkÚoutputr   r   Únamer   z[%d]Úrec_textÚ	rec_tokenÚrec_tokenidr   r   Útext_srcr   Ú	token_srcr   Útokenid_srczgroundtruth: %szprediction : %szsource : %s)	ÚdictÚkeysÚ	enumerater   ÚlenÚitemsÚappendÚloggingÚinfo)ÚjsÚ
nbest_hypsr	   Únew_jsÚnr   r!   r"   r#   r   Úout_dicr   r   r
   Úadd_results_to_json#   s2   	€r4   )Ú__doc__r-   r   r4   r   r   r   r
   Ú<module>   s   