U
    -e;                     @   s\  d Z ddlZddlmZmZmZmZ ddlmZ	 ddl
mZmZ ddlmZmZ ddd	d
ddgZddeeddfeeee f eeee f ee	je	jf ee	je	jf eeee f ee	je	jf edddZddeeddfeeee f eeee f ee	je	jf ee	je	jf eeee f ee	je	jf edddZddeeddfeeee f eeee f ee	je	jf ee	je	jf eeee f ee	je	jf eddd
Zddeeddfeeee f eeee f ee	je	jf ee	je	jf eeee f ee	je	jf eddd	Zeefeeee f eeee f ee	je	jf ee	je	jf eeef dddZddeedddfeeee f eeee f ee	je	jf ee	je	jf eeeee f ee	je	jf eeeeef f dddZeeee f eeee f eeee f ee	je	jf ee	je	jf ee	je	jf dddZdS )a  
Convenience methods for calculating a number of similarity error
measures between a reference and hypothesis sentence.
These measures are
commonly used to measure the performance for an automatic speech recognition
(ASR) system.

The following measures are implemented:

- Word Error Rate (WER), which is where this library got its name from. This
  has long been (and arguably still is) the de facto standard for computing
  ASR performance.
- Match Error Rate (MER)
- Word Information Lost (WIL)
- Word Information Preserved (WIP)
- Character Error Rate (CER)

Note that these functions merely call
[jiwer.process_words][process.process_words] and
[jiwer.process_characters][process.process_characters].
It is more efficient to call `process_words` or `process_characters` and access the
results from the
[jiwer.WordOutput][process.WordOutput] and
[jiwer.CharacterOutput][process.CharacterOutput]
classes.
    N)ListUnionDictAny)
transforms)wer_defaultcer_default)process_wordsprocess_characterswermerwilwipcercompute_measures)	reference
hypothesisreference_transformhypothesis_transformtruthtruth_transformreturnc                 C   s0   t | |||||d\} }}}t| |||}|jS )a  
    Calculate the word error rate (WER) between one or more reference and
    hypothesis sentences.

    Args:
        reference: The reference sentence(s)
        hypothesis: The hypothesis sentence(s)
        reference_transform: The transformation(s) to apply to the reference string(s)
        hypothesis_transform: The transformation(s) to apply to the hypothesis string(s)
        truth: Deprecated, renamed to `reference`
        truth_transform: Deprecated, renamed to `reference_transform`

    Deprecated:
        Arguments `truth` and `truth_transform` have been renamed to respectively
        `reference` and `reference_transform`. Therefore, the keyword arguments
         `truth` and `truth_transform` will be removed in the next release.
         At the same time, `reference` and `reference_transform` will lose their
         default value.

    Returns:
        (float): The word error rate of the given reference and
                 hypothesis sentence(s).
    r   r   r   r   r   r   )_deprecate_truthr	   r   r   r   r   r   r   r   output r   O/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/jiwer/measures.pyr   B   s(    $
   c                 C   s0   t | |||||d\} }}}t| |||}|jS )a  
    Calculate the match error rate (MER) between one or more reference and
    hypothesis sentences.

    Args:
        reference: The reference sentence(s)
        hypothesis: The hypothesis sentence(s)
        reference_transform: The transformation(s) to apply to the reference string(s)
        hypothesis_transform: The transformation(s) to apply to the hypothesis string(s)
        truth: Deprecated, renamed to `reference`
        truth_transform: Deprecated, renamed to `reference_transform`

    Deprecated:
        Arguments `truth` and `truth_transform` have been renamed to respectively
        `reference` and `reference_transform`. Therefore, the keyword arguments
         `truth` and `truth_transform` will be removed in the next release.
         At the same time, `reference` and `reference_transform` will lose their
         default value.

    Returns:
        (float): The match error rate of the given reference and
                 hypothesis sentence(s).
    r   )r   r	   r   r   r   r   r   r   u   s(    $
   c                 C   s0   t | |||||d\} }}}t| |||}|jS )a  
    Calculate the word information preserved (WIP) between one or more reference and
    hypothesis sentences.

    Args:
        reference: The reference sentence(s)
        hypothesis: The hypothesis sentence(s)
        reference_transform: The transformation(s) to apply to the reference string(s)
        hypothesis_transform: The transformation(s) to apply to the hypothesis string(s)
        truth: Deprecated, renamed to `reference`
        truth_transform: Deprecated, renamed to `reference_transform`

    Deprecated:
        Arguments `truth` and `truth_transform` have been renamed to respectively
        `reference` and `reference_transform`. Therefore, the keyword arguments
         `truth` and `truth_transform` will be removed in the next release.
         At the same time, `reference` and `reference_transform` will lose their
         default value.

    Returns:
        (float): The word information preserved of the given reference and
                 hypothesis sentence(s).
    r   )r   r	   r   r   r   r   r   r      s(    $
   c                 C   s0   t | |||||d\} }}}t| |||}|jS )a  
    Calculate the word information lost (WIL) between one or more reference and
    hypothesis sentences.

    Args:
        reference: The reference sentence(s)
        hypothesis: The hypothesis sentence(s)
        reference_transform: The transformation(s) to apply to the reference string(s)
        hypothesis_transform: The transformation(s) to apply to the hypothesis string(s)
        truth: Deprecated, renamed to `reference`
        truth_transform: Deprecated, renamed to `reference_transform`

    Deprecated:
        Arguments `truth` and `truth_transform` have been renamed to respectively
        `reference` and `reference_transform`. Therefore, the keyword arguments
        `truth` and `truth_transform` will be removed in the next release.
         At the same time, `reference` and `reference_transform` will lose their
         default value.

    Returns:
        (float): The word information lost of the given reference and
                 hypothesis sentence(s).
    r   )r   r	   r   r   r   r   r   r      s(    $
   )r   r   r   r   r   c                 C   sP   t td t| |||d}|j|j|j|j|j|j	|j
|j|j|j|jdS )aN  
    Efficiently computes all measures using only one function call.

    Deprecated:
        Deprecated method. Superseded by [jiwer.process_words][process.process_words].
        This method will be removed on next release.

    Args:
        truth: The reference sentence(s)
        hypothesis: The hypothesis sentence(s)
        truth_transform: The transformation(s) to apply to the reference string(s)
        hypothesis_transform: The transformation(s) to apply to the hypothesis string(s)

    Returns:
        (dict): A dictionary containing key-value pairs for all measures.

    zIjiwer.compute_measures() is deprecated. Please use jiwer.process_words().)r   r   r   r   )r   r   r   r   hitssubstitutions	deletions
insertionsZopsr   r   )warningswarnDeprecationWarningr	   r   r   r   r   r   r   r    r!   Z
alignmentsZ
referencesZ
hypotheses)r   r   r   r   r   r   r   r   r     s.    F)r   r   r   r   return_dictr   r   r   c                 C   s`   t | |||||d\} }}}t| |||}|rVttd |j|j|j|j|j	dS |jS dS )a  
    Calculate the character error rate (CER) between one or more reference and
    hypothesis sentences.

    Args:
        reference: The reference sentence(s)
        hypothesis: The hypothesis sentence(s)
        reference_transform: The transformation(s) to apply to the reference string(s)
        hypothesis_transform: The transformation(s) to apply to the hypothesis string(s)
        return_dict: Deprecated option to return the more results in a dict instead of
                     returning only the cer as a single float value
        truth: Deprecated, renamed to `reference`
        truth_transform: Deprecated, renamed to `reference_transform`

    Deprecated:
        Argument `return_dict` will be deprecated. Please use
        [jiwer.process_characters][process.process_characters] instead.

        Arguments `truth` and `truth_transform` have been renamed to respectively
        `reference` and `reference_transform`. Therefore, the keyword arguments
         `truth` and `truth_transform` will be removed in the next release.
         At the same time, `reference` and `reference_transform` will lose their
         default value.

    Returns:
        (float): The character error rate of the given reference and hypothesis
                 sentence(s).
    r   zK`return_dict` is deprecated, please use jiwer.process_characters() instead.)r   r   r   r    r!   N)
r   r
   r"   r#   r$   r   r   r   r    r!   )r   r   r   r   r%   r   r   r   r   r   r   r   L  s@    *
   r   r   r   r   r   r   c                 C   sh   |d k	r*t td | d k	r&td|} |d k	rDt td |}| d ksT|d kr\td| |||fS )Nz?keyword argument `truth` is deprecated, please use `reference`.z#cannot give `reference` and `truth`zSkeyword argument `truth_transform` is deprecated, please use `reference_transform`.zndetected default values for reference or hypothesis arguments, please provide actual string or list of strings)r"   r#   r$   
ValueErrorr&   r   r   r   r     s*    r   )__doc__r"   typingr   r   r   r   Zjiwerr   trZjiwer.transformationsr   r   Zjiwer.processr	   r
   __all__strZComposeZAbstractTransformfloatr   r   r   r   r   boolr   r   r   r   r   r   <module>   s   455;
8J