o
    !wi"                     @   s   d Z ddlZddlZddlZe ejdddejdddejd	d
dejdddejdddddddejdddddddejddddddddejdejdededef
ddZe	dkree  dS dS )zU
Provide a simple CLI wrapper for JiWER. The CLI does not support custom transforms.
    Nz-rz--referencereference_fileTz<Path to new-line delimited text file of reference sentences.)typerequiredhelpz-hz--hypothesishypothesis_filez=Path to new-line delimited text file of hypothesis sentences.z--cerz-ccompute_cerFzCompute CER instead of WER.)is_flagdefaultr   z--alignz-ashow_alignmentz!Print alignment of each sentence.z--globalz-gglobal_alignmentzeApply a global minimal alignment between reference and hypothesis sentences before computing the WER.c           	   
   C   sJ  |  d}dd | D }W d   n1 sw   Y  | d}dd | D }W d   n1 s7w   Y  |s[t|t|kr[tdt| d|  dt| d| d		|rr|rktj||tjtjd
}nt||}n|rtj||tjtjd
}nt||}|rt	tj
|dddd dS |rt	|j dS t	|j dS )a  
    JiWER is a python tool for computing the word-error-rate of ASR systems. To use
    this CLI, store the reference and hypothesis sentences in a text file, where
    each sentence is delimited by a new-line character.
    The text files are expected to have an equal number of lines, unless the `-g` flag
    is used. The `-g` flag joins computation of the WER by doing a global minimal
    alignment.

    rc                 S   $   g | ]}t | d kr| qS    lenstrip.0ln r   F/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/jiwer/cli.py
<listcomp>X       zcli.<locals>.<listcomp>Nc                 S   r   r   r   r   r   r   r   r   ]   r   zNumber of reference sentences (z in 'z') and hypothesis sentences (z') do not match! Use the `--global` flag to compute the measures over a global alignment of the reference and hypothesis sentences.)reference_transformhypothesis_transformT)show_measures )end)open	readlinesr   
ValueErrorjiwerprocess_characterscer_contiguousprocess_wordswer_contiguousprintvisualize_alignmentcerwer)	r   r   r   r
   r   freference_sentenceshypothesis_sentencesoutr   r   r   cli   s^   :
r/   __main__)
__doc__clickpathlibr"   commandoptionPathboolr/   __name__r   r   r   r   <module>   sv   	F
