



import re
import string

import numpy as np

import datasets


snake_case    :						Any  =						'\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

snake_case    :						int  =						'\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results["exact_match"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]\n    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    33.3\n\n'

snake_case    :						Union[str, Any]  =						'\n'




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







     def  _lowercase			(       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"),
                   })			,		reference_urls=[]			,		)







     def  _lowercase			(       self      :     Union[str, Any]			,		_A      :     Union[str, Any]			,		_A      :     List[str]			,		_A      :     Dict=None			,		_A      :     List[str]=False			,		_A      :     Dict=False			,		_A      :     List[Any]=False			,		):
           if regexes_to_ignore is not None:
                 for s in regexes_to_ignore:
                       A__	:							Optional[Any]						    = np.array([re.sub(_A			,		""			,		_A) for x in predictions])
                       A__	:							Optional[Any]						    = np.array([re.sub(_A			,		""			,		_A) for x in references])
           else:
                 A__	:							str						    = np.asarray(_A)
                 A__	:							str						    = np.asarray(_A)

           if ignore_case:
                 A__	:							List[str]						    = np.char.lower(_A)
                 A__	:							List[Any]						    = np.char.lower(_A)

           if ignore_punctuation:
                 A__	:							List[str]						    = string.punctuation.maketrans(""			,		""			,		string.punctuation)
                 A__	:							List[Any]						    = np.char.translate(_A			,		table=_A)
                 A__	:							Optional[Any]						    = np.char.translate(_A			,		table=_A)

           if ignore_numbers:
                 A__	:							str						    = string.digits.maketrans(""			,		""			,		string.digits)
                 A__	:							Optional[int]						    = np.char.translate(_A			,		table=_A)
                 A__	:							str						    = np.char.translate(_A			,		table=_A)

           A__	:							int						    = predictions == references

           return {"exact_match": np.mean(_A) * 100}




from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset




class 							lowerCAmelCase__  (	UpperCamelCase						):







					def  _lowercase			(       self      :     List[Any]):
											return [
											    {"col_1": 3, "col_2": "a"},
											    {"col_1": 2, "col_2": "b"},
											    {"col_1": 1, "col_2": "c"},
											    {"col_1": 0, "col_2": "d"},
											]







					def  _lowercase			(       self      :     Tuple):
											A__	:							Any						    = {"col_1": [3, 2, 1, 0], "col_2": ["a", "b", "c", "d"]}
											return Dataset.from_dict(_A)







					def  _lowercase			(       self      :     Union[str, Any]):
											A__	:							str						    = self._create_example_records()
											A__	:							Dict						    = Dataset.from_list(_A)
											self.assertListEqual(dset.column_names			,		["col_1", "col_2"])
											for i, r in enumerate(_A):
																	self.assertDictEqual(_A			,		example_records[i])







					def  _lowercase			(       self      :     List[str]):
											A__	:							List[str]						    = self._create_example_records()
											A__	:							Any						    = Dataset.from_list(_A)
											A__	:							Optional[int]						    = Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]})
											self.assertEqual(dset.info			,		dset_from_dict.info)







					def  _lowercase			(       self      :     Any):  # checks what happens with missing columns
											A__	:							Dict						    = [{"col_1": 1}, {"col_2": "x"}]
											A__	:							Any						    = Dataset.from_list(_A)
											self.assertDictEqual(dset[0]			,		{"col_1": 1})
											self.assertDictEqual(dset[1]			,		{"col_1": None})  # NB: first record is used for columns







					def  _lowercase			(       self      :     str):  # checks if the type can be inferred from the second record
											A__	:							Dict						    = [{"col_1": []}, {"col_1": [1, 2]}]
											A__	:							Dict						    = Dataset.from_list(_A)
											self.assertEqual(dset.info.features["col_1"]			,		Sequence(Value("int64")))







					def  _lowercase			(       self      :     Union[str, Any]):
											A__	:							Dict						    = Dataset.from_list([])
											self.assertEqual(len(_A)			,		0)
											self.assertListEqual(dset.column_names			,		[])