



import sacrebleu as scb
from packaging import version
from sacrebleu import TER

import datasets


UpperCAmelCase_									=							"\\n@inproceedings{snover-etal-2006-study,\n    title = \"A Study of Translation Edit Rate with Targeted Human Annotation\",\n    author = \"Snover, Matthew  and\n      Dorr, Bonnie  and\n      Schwartz, Rich  and\n      Micciulla, Linnea  and\n      Makhoul, John\",\n    booktitle = \"Proceedings of the 7th Conference of the Association for Machine Translation in the Americas: Technical Papers\",\n    month = aug # \" 8-12\",\n    year = \"2006\",\n    address = \"Cambridge, Massachusetts, USA\",\n    publisher = \"Association for Machine Translation in the Americas\",\n    url = \"https://aclanthology.org/2006.amta-papers.25\",\n    pages = \"223--231\",\n}\n@inproceedings{post-2018-call,\n    title = \"A Call for Clarity in Reporting {BLEU} Scores\",\n    author = \"Post, Matt\",\n    booktitle = \"Proceedings of the Third Conference on Machine Translation: Research Papers\",\n    month = oct,\n    year = \"2018\",\n    address = \"Belgium, Brussels\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://www.aclweb.org/anthology/W18-6319\",\n    pages = \"186--191\",\n}\n"

UpperCAmelCase_									=							"\\nTER (Translation Edit Rate, also called Translation Error Rate) is a metric to quantify the edit operations that a\nhypothesis requires to match a reference translation. We use the implementation that is already present in sacrebleu\n(https://github.com/mjpost/sacreBLEU#ter), which in turn is inspired by the TERCOM implementation, which can be found\nhere: https://github.com/jhclark/tercom.\n\nThe implementation here is slightly different from sacrebleu in terms of the required input format. The length of\nthe references and hypotheses lists need to be the same, so you may need to transpose your references compared to\nsacrebleu's required input format. See https://github.com/huggingface/datasets/issues/3154#issuecomment-950746534\n\nSee the README.md file at https://github.com/mjpost/sacreBLEU#ter for more information.\n"

UpperCAmelCase_									=							"\nProduces TER scores alongside the number of edits and reference length.\n\nArgs:\n    predictions (list of str): The system stream (a sequence of segments).\n    references (list of list of str): A list of one or more reference streams (each a sequence of segments).\n    normalized (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.\n    ignore_punct (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.\n    support_zh_ja_chars (boolean): If `True`, tokenization/normalization supports processing of Chinese characters,\n                                    as well as Japanese Kanji, Hiragana, Katakana, and Phonetic Extensions of Katakana.\n                                    Only applies if `normalized = True`. Defaults to `False`.\n    case_sensitive (boolean): If `False`, makes all predictions and references lowercase to ignore differences in case. Defaults to `False`.\n\nReturns:\n    'score' (float): TER score (num_edits / sum_ref_lengths * 100)\n    'num_edits' (int): The cumulative number of edits\n    'ref_length' (float): The cumulative average reference length\n\nExamples:\n    Example 1:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\",\n        ...                     \"What did the TER metric user say to the developer?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"],\n        ...             [\"Your jokes are...\", \"...TERrible\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {'score': 150.0, 'num_edits': 15, 'ref_length': 10.0}\n\n    Example 2:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {'score': 62.5, 'num_edits': 5, 'ref_length': 8.0}\n\n    Example 3:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         normalized=True,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {'score': 57.14285714285714, 'num_edits': 6, 'ref_length': 10.5}\n\n    Example 4:\n        >>> predictions = [\"does this sentence match??\",\n        ...                     \"what about this sentence?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         ignore_punct=True,\n        ...                         case_sensitive=False)\n        >>> print(results)\n        {'score': 0.0, 'num_edits': 0, 'ref_length': 8.0}\n\n    Example 5:\n        >>> predictions = [\"does this sentence match??\",\n        ...                    \"what about this sentence?\",\n        ...                    \"What did the TER metric user say to the developer?\"]\n        >>> references = [[\"does this sentence match\", \"does this sentence match!?!\"],\n        ...             [\"wHaT aBoUt ThIs SeNtEnCe?\", \"wHaT aBoUt ThIs SeNtEnCe?\"],\n        ...             [\"Your jokes are...\", \"...TERrible\"]]\n        >>> ter = datasets.load_metric(\"ter\")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         ignore_punct=True,\n        ...                         case_sensitive=False)\n        >>> print(results)\n        {'score': 100.0, 'num_edits': 10, 'ref_length': 10.0}\n"





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,_KWARGS_DESCRIPTION				)
class 		UpperCAmelCase						(						datasets.Metric				):





   def 	__lowerCAmelCase							(	self			):
         if version.parse(scb.__version__			) < version.parse('''1.4.12'''			):
               raise ImportWarning(
                   '''To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn\'t match this condition.\n'''
                   '''You can install it with `pip install "sacrebleu>=1.4.12"`.'''			)
         return datasets.MetricInfo(
             description=_DESCRIPTION       ,     citation=_CITATION       ,     homepage='''http://www.cs.umd.edu/~snover/tercom/'''       ,     inputs_description=_KWARGS_DESCRIPTION       ,     features=datasets.Features(
                 {
                     '''predictions''': datasets.Value('''string'''       ,     id='''sequence'''			),
                     '''references''': datasets.Sequence(datasets.Value('''string'''       ,     id='''sequence'''			)       ,     id='''references'''			),
                 }			)       ,     codebase_urls=['''https://github.com/mjpost/sacreBLEU#ter''']       ,     reference_urls=[
                 '''https://github.com/jhclark/tercom''',
             ]       ,     )





   def 	__lowerCAmelCase							(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = False       ,     ):
         _lowerCAmelCase 			=  len(references[0]			)
         if any(len(_lowerCAmelCase			) != references_per_prediction for refs in references			):
               raise ValueError('''Sacrebleu requires the same number of references for each prediction'''			)
         _lowerCAmelCase 			=  [[refs[i] for refs in references] for i in range(_lowerCAmelCase			)]

         _lowerCAmelCase 			=  TER(
             normalized=_lowerCAmelCase       ,     no_punct=_lowerCAmelCase       ,     asian_support=_lowerCAmelCase       ,     case_sensitive=_lowerCAmelCase       ,     )
         _lowerCAmelCase 			=  sb_ter.corpus_score(_lowerCAmelCase       ,     _lowerCAmelCase			)

         return {"score": output.score, "num_edits": output.num_edits, "ref_length": output.ref_length}




import re
import string
from collections import Counter

import sacrebleu
import sacremoses
from packaging import version

import datasets


UpperCAmelCase_									=							"\n@inproceedings{xu-etal-2016-optimizing,\n    title = {Optimizing Statistical Machine Translation for Text Simplification},\n    authors={Xu, Wei and Napoles, Courtney and Pavlick, Ellie and Chen, Quanze and Callison-Burch, Chris},\n    journal = {Transactions of the Association for Computational Linguistics},\n    volume = {4},\n    year={2016},\n    url = {https://www.aclweb.org/anthology/Q16-1029},\n    pages = {401--415\n},\n@inproceedings{post-2018-call,\n    title = \"A Call for Clarity in Reporting {BLEU} Scores\",\n    author = \"Post, Matt\",\n    booktitle = \"Proceedings of the Third Conference on Machine Translation: Research Papers\",\n    month = oct,\n    year = \"2018\",\n    address = \"Belgium, Brussels\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://www.aclweb.org/anthology/W18-6319\",\n    pages = \"186--191\",\n}\n"

UpperCAmelCase_									=							"\\nWIKI_SPLIT is the combination of three metrics SARI, EXACT and SACREBLEU\nIt can be used to evaluate the quality of machine-generated texts.\n"


UpperCAmelCase_									=							"\nCalculates sari score (between 0 and 100) given a list of source and predicted\nsentences, and a list of lists of reference sentences. It also computes the BLEU score as well as the exact match score.\nArgs:\n    sources: list of source sentences where each sentence should be a string.\n    predictions: list of predicted sentences where each sentence should be a string.\n    references: list of lists of reference sentences where each sentence should be a string.\nReturns:\n    sari: sari score\n    sacrebleu: sacrebleu score\n    exact: exact score\n\nExamples:\n    >>> sources=[\"About 95 species are currently accepted .\"]\n    >>> predictions=[\"About 95 you now get in .\"]\n    >>> references=[[\"About 95 species are currently known .\"]]\n    >>> wiki_split = datasets.load_metric(\"wiki_split\")\n    >>> results = wiki_split.compute(sources=sources, predictions=predictions, references=references)\n    >>> print(results)\n    {'sari': 21.805555555555557, 'sacrebleu': 14.535768424205482, 'exact': 0.0}\n"
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	List[Any]				)->Optional[Any]:

      def remove_articles(_SCREAMING_SNAKE_CASE   :	List[str]				):
            _lowerCAmelCase 			=  re.compile(r'''\b(a|an|the)\b'''     ,				re.UNICODE				)
            return re.sub(_SCREAMING_SNAKE_CASE     ,				''' '''     ,				_SCREAMING_SNAKE_CASE				)

      def white_space_fix(_SCREAMING_SNAKE_CASE   :	List[Any]				):
            return " ".join(text.split()				)

      def remove_punc(_SCREAMING_SNAKE_CASE   :	Optional[Any]				):
            _lowerCAmelCase 			=  set(string.punctuation				)
            return "".join(ch for ch in text if ch not in exclude				)

      def lower(_SCREAMING_SNAKE_CASE   :	Optional[int]				):
            return text.lower()

      return white_space_fix(remove_articles(remove_punc(lower(_SCREAMING_SNAKE_CASE				)				)				)				)
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Optional[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[Any]				)->Any:
      return int(normalize_answer(_SCREAMING_SNAKE_CASE				) == normalize_answer(_SCREAMING_SNAKE_CASE				)				)
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Union[str, Any]     ,				_SCREAMING_SNAKE_CASE   :	str				)->int:
      _lowerCAmelCase 			=  [any(compute_exact(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				) for ref in refs				) for pred, refs in zip(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)]
      return (sum(_SCREAMING_SNAKE_CASE				) / len(_SCREAMING_SNAKE_CASE				)) * 1_0_0
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	List[str]     ,				_SCREAMING_SNAKE_CASE   :	Union[str, Any]     ,				_SCREAMING_SNAKE_CASE   :	Union[str, Any]     ,				_SCREAMING_SNAKE_CASE   :	List[str]				)->Optional[int]:
      _lowerCAmelCase 			=  [rgram for rgrams in rgramslist for rgram in rgrams]
      _lowerCAmelCase 			=  Counter(_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  Counter(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  Counter()
      for sgram, scount in sgramcounter.items():
            _lowerCAmelCase 			=  scount * numref

      _lowerCAmelCase 			=  Counter(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  Counter()
      for cgram, ccount in cgramcounter.items():
            _lowerCAmelCase 			=  ccount * numref

      # KEEP
      _lowerCAmelCase 			=  sgramcounter_rep & cgramcounter_rep
      _lowerCAmelCase 			=  keepgramcounter_rep & rgramcounter
      _lowerCAmelCase 			=  sgramcounter_rep & rgramcounter

      _lowerCAmelCase 			=  0
      _lowerCAmelCase 			=  0
      for keepgram in keepgramcountergood_rep:
            keeptmpscorea += keepgramcountergood_rep[keepgram] / keepgramcounter_rep[keepgram]
            # Fix an alleged bug [2] in the keep score computation.
            # keeptmpscore2 += keepgramcountergood_rep[keepgram] / keepgramcounterall_rep[keepgram]
            keeptmpscorea += keepgramcountergood_rep[keepgram]
      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      #      a target exactly.
      _lowerCAmelCase 			=  1
      _lowerCAmelCase 			=  1
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  keeptmpscorea / len(_SCREAMING_SNAKE_CASE				)
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            # Fix an alleged bug [2] in the keep score computation.
            # keepscore_recall = keeptmpscore2 / len(keepgramcounterall_rep)
            _lowerCAmelCase 			=  keeptmpscorea / sum(keepgramcounterall_rep.values()				)
      _lowerCAmelCase 			=  0
      if keepscore_precision > 0 or keepscore_recall > 0:
            _lowerCAmelCase 			=  2 * keepscore_precision * keepscore_recall / (keepscore_precision + keepscore_recall)

      # DELETION
      _lowerCAmelCase 			=  sgramcounter_rep - cgramcounter_rep
      _lowerCAmelCase 			=  delgramcounter_rep - rgramcounter
      _lowerCAmelCase 			=  sgramcounter_rep - rgramcounter
      _lowerCAmelCase 			=  0
      _lowerCAmelCase 			=  0
      for delgram in delgramcountergood_rep:
            deltmpscorea += delgramcountergood_rep[delgram] / delgramcounter_rep[delgram]
            deltmpscorea += delgramcountergood_rep[delgram] / delgramcounterall_rep[delgram]
      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      # a target exactly.
      _lowerCAmelCase 			=  1
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  deltmpscorea / len(_SCREAMING_SNAKE_CASE				)

      # ADDITION
      _lowerCAmelCase 			=  set(_SCREAMING_SNAKE_CASE				) - set(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  set(_SCREAMING_SNAKE_CASE				) & set(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  set(_SCREAMING_SNAKE_CASE				) - set(_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  0
      for addgram in addgramcountergood:
            addtmpscore += 1

      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      # a target exactly.
      _lowerCAmelCase 			=  1
      _lowerCAmelCase 			=  1
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  addtmpscore / len(_SCREAMING_SNAKE_CASE				)
      if len(_SCREAMING_SNAKE_CASE				) > 0:
            _lowerCAmelCase 			=  addtmpscore / len(_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  0
      if addscore_precision > 0 or addscore_recall > 0:
            _lowerCAmelCase 			=  2 * addscore_precision * addscore_recall / (addscore_precision + addscore_recall)

      return (keepscore, delscore_precision, addscore)
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Any     ,				_SCREAMING_SNAKE_CASE   :	int     ,				_SCREAMING_SNAKE_CASE   :	str				)->List[Any]:
      _lowerCAmelCase 			=  len(_SCREAMING_SNAKE_CASE				)

      _lowerCAmelCase 			=  ssent.split(''' '''				)
      _lowerCAmelCase 			=  csent.split(''' '''				)
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []

      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      _lowerCAmelCase 			=  []
      for rsent in rsents:
            _lowerCAmelCase 			=  rsent.split(''' '''				)
            _lowerCAmelCase 			=  []
            _lowerCAmelCase 			=  []
            _lowerCAmelCase 			=  []
            ragramslist.append(_SCREAMING_SNAKE_CASE				)
            for i in range(0     ,				len(_SCREAMING_SNAKE_CASE				) - 1				):
                  if i < len(_SCREAMING_SNAKE_CASE				) - 1:
                        _lowerCAmelCase 			=  ragrams[i] + ''' ''' + ragrams[i + 1]
                        ragrams.append(_SCREAMING_SNAKE_CASE				)
                  if i < len(_SCREAMING_SNAKE_CASE				) - 2:
                        _lowerCAmelCase 			=  ragrams[i] + ''' ''' + ragrams[i + 1] + ''' ''' + ragrams[i + 2]
                        ragrams.append(_SCREAMING_SNAKE_CASE				)
                  if i < len(_SCREAMING_SNAKE_CASE				) - 3:
                        _lowerCAmelCase 			=  ragrams[i] + ''' ''' + ragrams[i + 1] + ''' ''' + ragrams[i + 2] + ''' ''' + ragrams[i + 3]
                        ragrams.append(_SCREAMING_SNAKE_CASE				)
            ragramslist.append(_SCREAMING_SNAKE_CASE				)
            ragramslist.append(_SCREAMING_SNAKE_CASE				)
            ragramslist.append(_SCREAMING_SNAKE_CASE				)

      for i in range(0     ,				len(_SCREAMING_SNAKE_CASE				) - 1				):
            if i < len(_SCREAMING_SNAKE_CASE				) - 1:
                  _lowerCAmelCase 			=  sagrams[i] + ''' ''' + sagrams[i + 1]
                  sagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 2:
                  _lowerCAmelCase 			=  sagrams[i] + ''' ''' + sagrams[i + 1] + ''' ''' + sagrams[i + 2]
                  sagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 3:
                  _lowerCAmelCase 			=  sagrams[i] + ''' ''' + sagrams[i + 1] + ''' ''' + sagrams[i + 2] + ''' ''' + sagrams[i + 3]
                  sagrams.append(_SCREAMING_SNAKE_CASE				)

      for i in range(0     ,				len(_SCREAMING_SNAKE_CASE				) - 1				):
            if i < len(_SCREAMING_SNAKE_CASE				) - 1:
                  _lowerCAmelCase 			=  cagrams[i] + ''' ''' + cagrams[i + 1]
                  cagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 2:
                  _lowerCAmelCase 			=  cagrams[i] + ''' ''' + cagrams[i + 1] + ''' ''' + cagrams[i + 2]
                  cagrams.append(_SCREAMING_SNAKE_CASE				)
            if i < len(_SCREAMING_SNAKE_CASE				) - 3:
                  _lowerCAmelCase 			=  cagrams[i] + ''' ''' + cagrams[i + 1] + ''' ''' + cagrams[i + 2] + ''' ''' + cagrams[i + 3]
                  cagrams.append(_SCREAMING_SNAKE_CASE				)

      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      ((_lowerCAmelCase)			,   (_lowerCAmelCase)			,   (_lowerCAmelCase)) 			=  SARIngram(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)
      _lowerCAmelCase 			=  sum([keepascore, keepascore, keepascore, keepascore]				) / 4
      _lowerCAmelCase 			=  sum([delascore, delascore, delascore, delascore]				) / 4
      _lowerCAmelCase 			=  sum([addascore, addascore, addascore, addascore]				) / 4
      _lowerCAmelCase 			=  (avgkeepscore + avgdelscore + avgaddscore) / 3
      return finalscore
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	int     ,				_SCREAMING_SNAKE_CASE   :	bool = True     ,				_SCREAMING_SNAKE_CASE   :	str = "13a"     ,				_SCREAMING_SNAKE_CASE   :	bool = True				)->int:
      # Normalization is requried for the ASSET dataset (one of the primary
      # datasets in sentence simplification) to allow using space
      # to split the sentence. Even though Wiki-Auto and TURK datasets,
      # do not require normalization, we do it for consistency.
      # Code adapted from the EASSE library [1] written by the authors of the ASSET dataset.
      # [1] https://github.com/feralvam/easse/blob/580bba7e1378fc8289c663f864e0487188fe8067/easse/utils/preprocessing.py#L7

      if lowercase:
            _lowerCAmelCase 			=  sentence.lower()

      if tokenizer in ["13a", "intl"]:
            if version.parse(sacrebleu.__version__				).major >= 2:
                  _lowerCAmelCase 			=  sacrebleu.metrics.bleu._get_tokenizer(_SCREAMING_SNAKE_CASE				)()(_SCREAMING_SNAKE_CASE				)
            else:
                  _lowerCAmelCase 			=  sacrebleu.TOKENIZERS[tokenizer]()(_SCREAMING_SNAKE_CASE				)
      elif tokenizer == "moses":
            _lowerCAmelCase 			=  sacremoses.MosesTokenizer().tokenize(_SCREAMING_SNAKE_CASE     ,				return_str=_SCREAMING_SNAKE_CASE     ,				escape=_SCREAMING_SNAKE_CASE				)
      elif tokenizer == "penn":
            _lowerCAmelCase 			=  sacremoses.MosesTokenizer().penn_tokenize(_SCREAMING_SNAKE_CASE     ,				return_str=_SCREAMING_SNAKE_CASE				)
      else:
            _lowerCAmelCase 			=  sentence

      if not return_str:
            _lowerCAmelCase 			=  normalized_sent.split()

      return normalized_sent
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	int     ,				_SCREAMING_SNAKE_CASE   :	List[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[str]				)->str:
      if not (len(_SCREAMING_SNAKE_CASE				) == len(_SCREAMING_SNAKE_CASE				) == len(_SCREAMING_SNAKE_CASE				)):
            raise ValueError('''Sources length must match predictions and references lengths.'''				)
      _lowerCAmelCase 			=  0
      for src, pred, refs in zip(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				):
            sari_score += SARIsent(normalize(_SCREAMING_SNAKE_CASE				)     ,				normalize(_SCREAMING_SNAKE_CASE				)     ,				[normalize(_SCREAMING_SNAKE_CASE				) for sent in refs]				)
      _lowerCAmelCase 			=  sari_score / len(_SCREAMING_SNAKE_CASE				)
      return 1_0_0 * sari_score
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	str     ,				_SCREAMING_SNAKE_CASE   :	List[str]     ,				_SCREAMING_SNAKE_CASE   :	Optional[Any]="exp"     ,				_SCREAMING_SNAKE_CASE   :	Optional[int]=None     ,				_SCREAMING_SNAKE_CASE   :	Optional[int]=False     ,				_SCREAMING_SNAKE_CASE   :	str=False     ,				_SCREAMING_SNAKE_CASE   :	int=False     ,				)->str:
      _lowerCAmelCase 			=  len(references[0]				)
      if any(len(_SCREAMING_SNAKE_CASE				) != references_per_prediction for refs in references				):
            raise ValueError('''Sacrebleu requires the same number of references for each prediction'''				)
      _lowerCAmelCase 			=  [[refs[i] for refs in references] for i in range(_SCREAMING_SNAKE_CASE				)]
      _lowerCAmelCase 			=  sacrebleu.corpus_bleu(
          _SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				smooth_method=_SCREAMING_SNAKE_CASE     ,				smooth_value=_SCREAMING_SNAKE_CASE     ,				force=_SCREAMING_SNAKE_CASE     ,				lowercase=_SCREAMING_SNAKE_CASE     ,				use_effective_order=_SCREAMING_SNAKE_CASE     ,				)
      return output.score





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,_KWARGS_DESCRIPTION				)
class 		UpperCAmelCase						(						datasets.Metric				):





   def 	__lowerCAmelCase							(	self			):
         return datasets.MetricInfo(
             description=_DESCRIPTION       ,     citation=_CITATION       ,     inputs_description=_KWARGS_DESCRIPTION       ,     features=datasets.Features(
                 {
                     '''predictions''': datasets.Value('''string'''       ,     id='''sequence'''			),
                     '''references''': datasets.Sequence(datasets.Value('''string'''       ,     id='''sequence'''			)       ,     id='''references'''			),
                 }			)       ,     codebase_urls=[
                 '''https://github.com/huggingface/transformers/blob/master/src/transformers/data/metrics/squad_metrics.py''',
                 '''https://github.com/cocoxu/simplification/blob/master/SARI.py''',
                 '''https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/utils/sari_hook.py''',
                 '''https://github.com/mjpost/sacreBLEU''',
             ]       ,     reference_urls=[
                 '''https://www.aclweb.org/anthology/Q16-1029.pdf''',
                 '''https://github.com/mjpost/sacreBLEU''',
                 '''https://en.wikipedia.org/wiki/BLEU''',
                 '''https://towardsdatascience.com/evaluating-text-output-in-nlp-bleu-at-your-own-risk-e8609665a213''',
             ]       ,     )





   def 	__lowerCAmelCase							(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase			):
         _lowerCAmelCase 			=  {}
         result.update({'''sari''': compute_sari(sources=_lowerCAmelCase       ,     predictions=_lowerCAmelCase       ,     references=_lowerCAmelCase			)}			)
         result.update({'''sacrebleu''': compute_sacrebleu(predictions=_lowerCAmelCase       ,     references=_lowerCAmelCase			)}			)
         result.update({'''exact''': compute_em(predictions=_lowerCAmelCase       ,     references=_lowerCAmelCase			)}			)
         return result