o
    !wi;                     @   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 g dZddeeddfdeeee f d	eeee f d
ee	je	jf dee	je	jf deeee f dee	je	jf defddZddeeddfdeeee f d	eeee f d
ee	je	jf dee	je	jf deeee f dee	je	jf defddZddeeddfdeeee f d	eeee f d
ee	je	jf dee	je	jf deeee f dee	je	jf defddZddeeddfdeeee f d	eeee f d
ee	je	jf dee	je	jf deeee f dee	je	jf defddZeefdeeee f d	eeee f dee	je	jf dee	je	jf deeef f
ddZddeedddfdeeee f d	eeee f d
ee	je	jf dee	je	jf dedeeee f dee	je	jf deeeeef f fddZdeeee f d	eeee f deeee f d
ee	je	jf dee	je	jf dee	je	jf f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   0   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   K/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/jiwer/measures.pyr   B   s"   $
r   c                 C   r   )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   "   $
r   c                 C   r   )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      r   r   c                 C   r   )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      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
insertionsopsr   r   )warningswarnDeprecationWarningr	   r   r   r   r   r    r!   r"   r#   
alignments
references
hypotheses)r   r   r   r   r   r   r   r   r     s.   r   Freturn_dictc                 C   s\   t | |||||d\} }}}t| |||}|r+ttd |j|j|j|j|j	dS |j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#   )
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   c                 C   sh   |d urt td | d urtd|} |d ur"t td |}| d u s*|d u 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'   
ValueError)r   r   r   r   r   r   r   r   r   r     s*   r   )__doc__r%   typingr   r   r   r   jiwerr   trjiwer.transformationsr   r   jiwer.processr	   r
   __all__strComposeAbstractTransformfloatr   r   r   r   r   boolr   r   r   r   r   r   <module>   s  
4
5
5
;

8
I