"""simple docstring"""





from typing import List

import jiwer
import jiwer.transforms as tr
from packaging import version

import datasets
from datasets.config import PY_VERSION


if PY_VERSION < version.parse('''3.8'''):
				import importlib_metadata
else:
				import importlib.metadata as importlib_metadata


__A  =				''''''


if version.parse(importlib_metadata.version('''jiwer''')) < version.parse('''2.3.0'''):
				class  _snake_case     (					tr.AbstractTransform		):






										def __init__(       self      :			Optional[Any]							,					UpperCAmelCase      :			str = " "    ):
																	__lowerCamelCase					:		List[str]		   =     sentence_delimiter






										def       lowerCamelCase__     (       self      :			Tuple							,					UpperCAmelCase      :			str    ):
																	return list(UpperCAmelCase    )







										def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			List[str]    ):
																	__lowerCamelCase					:		Any		   =     []
																	for sent_idx, sentence in enumerate(UpperCAmelCase    ):
																								chars.extend(self.process_string(UpperCAmelCase    )    )
																								if self.sentence_delimiter is not None and self.sentence_delimiter != "" and sent_idx < len(UpperCAmelCase    ) - 1:
																															chars.append(self.sentence_delimiter    )
																	return chars

				__A  =				tr.Compose(
				    [tr.RemoveMultipleSpaces(), tr.Strip(), SentencesToListOfCharacters(SENTENCE_DELIMITER)]
				)
else:
				__A  =				tr.Compose(
				    [
				        tr.RemoveMultipleSpaces(),
				        tr.Strip(),
				        tr.ReduceToSingleSentence(SENTENCE_DELIMITER),
				        tr.ReduceToListOfListOfChars(),
				    ]
				)


__A  =				'''\
@inproceedings{inproceedings,
    author = {Morris, Andrew and Maier, Viktoria and Green, Phil},
    year = {2004},
    month = {01},
    pages = {},
    title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.}
}
'''

__A  =				'''\
Character error rate (CER) is a common metric of the performance of an automatic speech recognition system.

CER is similar to Word Error Rate (WER), but operates on character instead of word. Please refer to docs of WER for further information.

Character error rate can be computed as:

CER = (S + D + I) / N = (S + D + I) / (S + D + C)

where

S is the number of substitutions,
D is the number of deletions,
I is the number of insertions,
C is the number of correct characters,
N is the number of characters in the reference (N=S+D+C).

CER\'s output is not always a number between 0 and 1, in particular when there is a high number of insertions. This value is often associated to the percentage of characters that were incorrectly predicted. The lower the value, the better the
performance of the ASR system with a CER of 0 being a perfect score.
'''

__A  =				'''
Computes CER score of transcribed segments against references.
Args:
    references: list of references for each speech input.
    predictions: list of transcribtions to score.
    concatenate_texts: Whether or not to concatenate sentences before evaluation, set to True for more accurate result.
Returns:
    (float): the character error rate

Examples:

    >>> predictions = ["this is the prediction", "there is an other sample"]
    >>> references = ["this is the reference", "there is another one"]
    >>> cer = datasets.load_metric("cer")
    >>> cer_score = cer.compute(predictions=predictions, references=references)
    >>> print(cer_score)
    0.34146341463414637
'''
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION				, _KWARGS_DESCRIPTION		)
class  _snake_case     (					datasets.Metric		):






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													return datasets.MetricInfo(
													    description=_DESCRIPTION							,					citation=_CITATION							,					inputs_description=_KWARGS_DESCRIPTION							,					features=datasets.Features(
													        {
													            "predictions": datasets.Value("string"							,					id="sequence"    ),
													            "references": datasets.Value("string"							,					id="sequence"    ),
													        }    )							,					codebase_urls=["https://github.com/jitsi/jiwer/"]							,					reference_urls=[
													        "https://en.wikipedia.org/wiki/Word_error_rate",
													        "https://sites.google.com/site/textdigitisation/qualitymeasures/computingerrorrates",
													    ]							,					)







						def       lowerCamelCase__     (       self      :			Optional[Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			List[str]=False    ):
													if concatenate_texts:
																				return jiwer.compute_measures(
																				    UpperCAmelCase							,					UpperCAmelCase							,					truth_transform=UpperCAmelCase							,					hypothesis_transform=UpperCAmelCase							,					)["wer"]

													__lowerCamelCase					:		Optional[int]		   =     0
													__lowerCamelCase					:		Optional[int]		   =     0
													for prediction, reference in zip(UpperCAmelCase							,					UpperCAmelCase    ):
																				__lowerCamelCase					:		Dict		   =     jiwer.compute_measures(
																				    UpperCAmelCase							,					UpperCAmelCase							,					truth_transform=UpperCAmelCase							,					hypothesis_transform=UpperCAmelCase							,					)
																				incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
																				total += measures["substitutions"] + measures["deletions"] + measures["hits"]

													return incorrect / total
"""simple docstring"""





# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import doctest
import sys
import warnings
from os.path import abspath, dirname, join

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
__A  =				abspath(join(dirname(__file__), '''src'''))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)


def    lowercase_   (   _lowerCamelCase:	List[Any]      ) ->      Union[str, Any]:



							'''simple docstring'''

							config.addinivalue_line(
							    "markers"						,   "is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested"      )
							config.addinivalue_line(
							    "markers"						,   "is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested"      )
							config.addinivalue_line("markers"						,   "is_pipeline_test: mark test to run only when pipelines are tested"      )
							config.addinivalue_line("markers"						,   "is_staging_test: mark test to run only in the staging environment"      )
							config.addinivalue_line("markers"						,   "accelerate_tests: mark test that require accelerate"      )
							config.addinivalue_line("markers"						,   "tool_tests: mark the tool tests that are run on their specific schedule"      )


def    lowercase_   (   _lowerCamelCase:	Union[str, Any]      ) ->      Any:



							'''simple docstring'''

							from transformers.testing_utils import pytest_addoption_shared

							pytest_addoption_shared(_lowerCamelCase      )


def    lowercase_   (   _lowerCamelCase:	Optional[int]      ) ->      Tuple:



							'''simple docstring'''

							from transformers.testing_utils import pytest_terminal_summary_main

							__lowerCamelCase					:		Any		   =     terminalreporter.config.getoption("--make-reports"      )
							if make_reports:
														pytest_terminal_summary_main(_lowerCamelCase						,   id=_lowerCamelCase      )


def    lowercase_   (   _lowerCamelCase:	Union[str, Any]						,   _lowerCamelCase:	Tuple      ) ->      Dict:



							'''simple docstring'''

							if exitstatus == 5:
														__lowerCamelCase					:		Optional[int]		   =     0


# Doctest custom flag to ignore output.
__A  =				doctest.register_optionflag('''IGNORE_RESULT''')

__A  =				doctest.OutputChecker
class  _snake_case     (					a__		):






						def       lowerCamelCase__     (       self      :			List[str]							,					UpperCAmelCase      :			int							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			int    ):
													if IGNORE_RESULT & optionflags:
																				return True
													return OutputChecker.check_output(self							,					UpperCAmelCase							,					UpperCAmelCase							,					UpperCAmelCase    )

__A  =				CustomOutputChecker
__A  =				HfDoctestModule







__A  =				HfDocTestParser