U
    -e                     @   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ejejeeedddZe	dkre  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.)Z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.)r   r   r   r	   r
   c           	   
   C   s  |  d}dd | D }W 5 Q R X | d}dd | D }W 5 Q R X |st|t|krtd|  dt| d| dt| d	|r|rtd|rt||}n(|rtj||tjtjd	}nt||}|rttj	|d
d n|rt|j
 n
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   s$   g | ]}t | d kr| qS    lenstrip.0ln r   J/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/jiwer/cli.py
<listcomp>X   s     zcli.<locals>.<listcomp>c                 S   s$   g | ]}t | d kr| qS r   r   r   r   r   r   r   ]   s     z$Number of sentences does not match. z
 contains z lines.z*--global and --cer are mutually exclusive.)Zreference_transformZhypothesis_transformT)Zshow_measuresN)open	readlinesr   
ValueErrorjiwerZprocess_charactersZprocess_wordsZwer_contiguousprintZvisualize_alignmentZcerZwer)	r   r   r   r	   r
   fZreference_sentencesZhypothesis_sentencesoutr   r   r   cli   s@    :$r   __main__)
__doc__Zclickpathlibr   commandoptionPathboolr   __name__r   r   r   r   <module>   sh   
=