





"""simple docstring"""






import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


A	     =					False
try:
  A	     =					_is_package_available('''google.colab''')
except ModuleNotFoundError:
  pass




@input.register
class 			__lowercase     :







     '''simple docstring'''




     def __init__(  self		,     _UpperCAmelCase = None		,     _UpperCAmelCase = []       ):
         __a	:  str         =					0
         __a	:  Any         =					choices
         __a	:  Tuple         =					prompt
         if sys.platform == "win32":
             __a	:  str         =					"*"
         else:
             __a	:  str         =					"➔ "







     def 	_lowerCamelCase						(  self		,     _UpperCAmelCase		,     _UpperCAmelCase = ""       ):




         if sys.platform != "win32":
             writeColor(self.choices[index]		,     32		,     _UpperCAmelCase       )
         else:
             forceWrite(self.choices[index]		,     _UpperCAmelCase       )







     def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):




         if index == self.position:
             forceWrite(f""" {self.arrow_char} """       )
             self.write_choice(_UpperCAmelCase       )
         else:
             forceWrite(f"""    {self.choices[index]}"""       )
         reset_cursor()







     def 	_lowerCamelCase						(  self		,     _UpperCAmelCase		,     _UpperCAmelCase = 1       ):
         __a	:  int         =					self.position
         if direction == Direction.DOWN:
             if self.position + 1 >= len(self.choices       ):
                 return
             self.position += num_spaces
         else:
             if self.position - 1 < 0:
                 return
             self.position -= num_spaces
         clear_line()
         self.print_choice(_UpperCAmelCase       )
         move_cursor(_UpperCAmelCase		,     direction.name       )
         self.print_choice(self.position       )







     @input.mark(KEYMAP['''up''']       )
     def 	_lowerCamelCase						(  self       ):
         self.move_direction(Direction.UP       )







     @input.mark(KEYMAP['''down''']       )
     def 	_lowerCamelCase						(  self       ):
         self.move_direction(Direction.DOWN       )







     @input.mark(KEYMAP['''newline''']       )
     def 	_lowerCamelCase						(  self       ):
         move_cursor(len(self.choices       ) - self.position		,     '''DOWN'''       )
         return self.position







     @input.mark(KEYMAP['''interrupt''']       )
     def 	_lowerCamelCase						(  self       ):
         move_cursor(len(self.choices       ) - self.position		,     '''DOWN'''       )
         raise KeyboardInterrupt







     @input.mark_multiple(*[KEYMAP[str(_UpperCAmelCase       )] for number in range(10       )]       )
     def 	_lowerCamelCase						(  self       ):
         __a	:  int         =					int(chr(self.current_selection       )       )
         __a	:  Tuple         =					index - self.position
         if index == self.position:
             return
         if index < len(self.choices       ):
             if self.position > index:
                 self.move_direction(Direction.UP		,     -movement       )
             elif self.position < index:
                 self.move_direction(Direction.DOWN		,     _UpperCAmelCase       )
             else:
                 return
         else:
             return







     def 	_lowerCamelCase						(  self		,     _UpperCAmelCase = 0       ):




         if self.prompt:
             linebreak()
             forceWrite(self.prompt		,     '''\n'''       )
             if in_colab:
                 forceWrite('''Please input a choice index (starting from 0), and press enter'''		,     '''\n'''       )
             else:
                 forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter'''		,     '''\n'''       )
         __a	:  int         =					default_choice
         for i in range(len(self.choices       )       ):
             self.print_choice(_UpperCAmelCase       )
             forceWrite('''\n'''       )
         move_cursor(len(self.choices       ) - self.position		,     '''UP'''       )
         with cursor.hide():
             while True:
                 if in_colab:
                     try:
                         __a	:  Tuple         =					int(builtins.input()       )
                     except ValueError:
                         __a	:  Dict         =					default_choice
                 else:
                     __a	:  Dict         =					self.handle_input()
                 if choice is not None:
                     reset_cursor()
                     for _ in range(len(self.choices       ) + 1       ):
                         move_cursor(1		,     '''UP'''       )
                         clear_line()
                     self.write_choice(_UpperCAmelCase		,     '''\n'''       )
                     return choice






"""simple docstring"""






import comet  # From: unbabel-comet
import torch

import datasets


A	     =					datasets.logging.get_logger(__name__)

A	     =					'''\
@inproceedings{rei-EtAl:2020:WMT,
   author    = {Rei, Ricardo  and  Stewart, Craig  and  Farinha, Ana C  and  Lavie, Alon},
   title     = {Unbabel\'s Participation in the WMT20 Metrics Shared Task},
   booktitle      = {Proceedings of the Fifth Conference on Machine Translation},
   month          = {November},
   year           = {2020},
   address        = {Online},
   publisher      = {Association for Computational Linguistics},
   pages     = {909--918},
}
@inproceedings{rei-etal-2020-comet,
   title = "{COMET}: A Neural Framework for {MT} Evaluation",
   author = "Rei, Ricardo  and
      Stewart, Craig  and
      Farinha, Ana C  and
      Lavie, Alon",
   booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
   month = nov,
   year = "2020",
   address = "Online",
   publisher = "Association for Computational Linguistics",
   url = "https://www.aclweb.org/anthology/2020.emnlp-main.213",
   pages = "2685--2702",
}
'''

A	     =					'''\
Crosslingual Optimized Metric for Evaluation of Translation (COMET) is an open-source framework used to train Machine Translation metrics that achieve high levels of correlation with different types of human judgments (HTER, DA\'s or MQM).
With the release of the framework the authors also released fully trained models that were used to compete in the WMT20 Metrics Shared Task achieving SOTA in that years competition.

See the [README.md] file at https://unbabel.github.io/COMET/html/models.html for more information.
'''

A	     =					'''
COMET score.

Args:

`sources` (list of str): Source sentences
`predictions` (list of str): candidate translations
`references` (list of str): reference translations
`cuda` (bool): If set to True, runs COMET using GPU
`show_progress` (bool): Shows progress
`model`: COMET model to be used. Will default to `wmt-large-da-estimator-1719` if None.

Returns:
    `samples`: List of dictionaries with `src`, `mt`, `ref` and `score`.
    `scores`: List of scores.

Examples:

    >>> comet_metric = datasets.load_metric(\'comet\')
    >>> # comet_metric = load_metric(\'comet\', \'wmt20-comet-da\')  # you can also choose which model to use
    >>> source = ["Dem Feuer konnte Einhalt geboten werden", "Schulen und Kindergärten wurden eröffnet."]
    >>> hypothesis = ["The fire could be stopped", "Schools and kindergartens were open"]
    >>> reference = ["They were able to control the fire.", "Schools and kindergartens opened"]
    >>> results = comet_metric.compute(predictions=hypothesis, references=reference, sources=source)
    >>> print([round(v, 2) for v in results["scores"]])
    [0.19, 0.92]
'''




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







					'''simple docstring'''




					def 	_lowerCamelCase						(  self       ):
									return datasets.MetricInfo(
									    description=_DESCRIPTION		,     citation=_CITATION		,     homepage='''https://unbabel.github.io/COMET/html/index.html'''		,     inputs_description=_KWARGS_DESCRIPTION		,     features=datasets.Features(
									        {
									            '''sources''': datasets.Value('''string'''		,     id='''sequence'''       ),
									            '''predictions''': datasets.Value('''string'''		,     id='''sequence'''       ),
									            '''references''': datasets.Value('''string'''		,     id='''sequence'''       ),
									        }       )		,     codebase_urls=['''https://github.com/Unbabel/COMET''']		,     reference_urls=[
									        '''https://github.com/Unbabel/COMET''',
									        '''https://www.aclweb.org/anthology/2020.emnlp-main.213/''',
									        '''http://www.statmt.org/wmt20/pdf/2020.wmt-1.101.pdf6''',
									    ]		,     )







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									if self.config_name == "default":
													__a	:  List[str]         =					comet.load_from_checkpoint(comet.download_model('''wmt20-comet-da'''       )       )
									else:
													__a	:  List[str]         =					comet.load_from_checkpoint(comet.download_model(self.config_name       )       )







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase		,     _UpperCAmelCase		,     _UpperCAmelCase		,     _UpperCAmelCase=None		,     _UpperCAmelCase=False       ):
									if gpus is None:
													__a	:  str         =					1 if torch.cuda.is_available() else 0
									__a	:  Optional[Any]         =					{'''src''': sources, '''mt''': predictions, '''ref''': references}
									__a	:  Dict         =					[dict(zip(_UpperCAmelCase		,     _UpperCAmelCase       )       ) for t in zip(*data.values()       )]
									__a    ,  __a	:  int         =					self.scorer.predict(_UpperCAmelCase		,     gpus=_UpperCAmelCase		,     progress_bar=_UpperCAmelCase       )
									return {"mean_score": mean_score, "scores": scores}