




import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Any	      =					""
				SCREAMING_SNAKE_CASE__					:							str	      =					(
				    None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
				)
				SCREAMING_SNAKE_CASE__					:							str	      =					None  # compression type in fsspec. ex: "gzip"
				SCREAMING_SNAKE_CASE__					:							str	      =					None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz


				def __init__(							self:   List[str]		,					_lowerCamelCase:   str = ""		,					_lowerCamelCase:   Optional[str] = None		,					_lowerCamelCase:   Optional[dict] = None		,					**_lowerCamelCase:   List[Any]		):
											super().__init__(self		,					**_lowerCamelCase		)
											# always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
											SCREAMING_SNAKE_CASE_   	=    fsspec.open(
											    _lowerCamelCase		,					mode='''rb'''		,					protocol=_lowerCamelCase		,					compression=self.compression		,					client_kwargs={
											        '''requote_redirect_url''': False,  # see https://github.com/huggingface/datasets/pull/5459
											        '''trust_env''': True,  # Enable reading proxy env variables.
											        **(target_options or {}).pop('''client_kwargs'''		,					{}		),  # To avoid issues if it was already passed.
											    }		,					**(target_options or {})		,					)
											SCREAMING_SNAKE_CASE_   	=    os.path.basename(self.file.path.split('''::'''		)[0]		)
											SCREAMING_SNAKE_CASE_   	=    (
											    self.compressed_name[: self.compressed_name.rindex('''.'''		)]
											    if '''.''' in self.compressed_name
											    else self.compressed_name
											)
											SCREAMING_SNAKE_CASE_   	=    None


				@classmethod
				def     _A							(							cls:   List[Any]		,					_lowerCamelCase:   Tuple		):
											# compressed file paths are always relative to the archive root
											return super()._strip_protocol(_lowerCamelCase		).lstrip('''/'''		)


				def     _A							(							self:   Any		):
											if self.dir_cache is None:
																		SCREAMING_SNAKE_CASE_   	=    {**self.file.fs.info(self.file.path		), '''name''': self.uncompressed_name}
																		SCREAMING_SNAKE_CASE_   	=    {f['''name''']: f}


				def     _A							(							self:   str		,					_lowerCamelCase:   str		):
											return self.file.open().read()





				def     _A							(							self:   Tuple		,					_lowerCamelCase:   str		,					_lowerCamelCase:   str = "rb"		,					_lowerCamelCase:   Dict=None		,					_lowerCamelCase:   Union[str, Any]=True		,					_lowerCamelCase:   Optional[Any]=None		,					**_lowerCamelCase:   Optional[int]		,					):
											SCREAMING_SNAKE_CASE_   	=    self._strip_protocol(_lowerCamelCase		)
											if mode != "rb":
																		raise ValueError(f"Tried to read with mode {mode} on file {self.file.path} opened with mode 'rb'"		)
											return self.file.open()






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							str	      =					"bz2"
				SCREAMING_SNAKE_CASE__					:							Dict	      =					"bz2"
				SCREAMING_SNAKE_CASE__					:							Any	      =					".bz2"






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							List[Any]	      =					"gzip"
				SCREAMING_SNAKE_CASE__					:							Any	      =					"gzip"
				SCREAMING_SNAKE_CASE__					:							List[Any]	      =					".gz"






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							str	      =					"lz4"
				SCREAMING_SNAKE_CASE__					:							Any	      =					"lz4"
				SCREAMING_SNAKE_CASE__					:							Tuple	      =					".lz4"






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Optional[Any]	      =					"xz"
				SCREAMING_SNAKE_CASE__					:							int	      =					"xz"
				SCREAMING_SNAKE_CASE__					:							Union[str, Any]	      =					".xz"






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Any	      =					"zstd"
				SCREAMING_SNAKE_CASE__					:							Dict	      =					"zstd"
				SCREAMING_SNAKE_CASE__					:							Tuple	      =					".zst"


				def __init__(							self:   Tuple		,					_lowerCamelCase:   str		,					_lowerCamelCase:   str = "rb"		,					_lowerCamelCase:   Optional[str] = None		,					_lowerCamelCase:   Optional[dict] = None		,					_lowerCamelCase:   int = DEFAULT_BLOCK_SIZE		,					**_lowerCamelCase:   int		,					):
											super().__init__(
											    fo=_lowerCamelCase		,					mode=_lowerCamelCase		,					target_protocol=_lowerCamelCase		,					target_options=_lowerCamelCase		,					block_size=_lowerCamelCase		,					**_lowerCamelCase		,					)
											# We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
											#
											# File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
											#     out.close = close
											# AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
											#
											# see https://github.com/intake/filesystem_spec/issues/725
											SCREAMING_SNAKE_CASE_   	=    self.file.__enter__






											class  __magic_name__						:
															'''simple docstring'''







															def __init__(							self:   str		,					_lowerCamelCase:   List[Any]		):
																						SCREAMING_SNAKE_CASE_   	=    file_


															def __enter__(							self:   Tuple		):
																						self._file.__enter__()
																						return self


															def __exit__(							self:   int		,					*_lowerCamelCase:   Tuple		,					**_lowerCamelCase:   int		):
																						self._file.__exit__(*_lowerCamelCase		,					**_lowerCamelCase		)


															def __iter__(							self:   Optional[int]		):
																						return iter(self._file		)


															def     _A							(							self:   str		):
																						return next(self._file		)





															def __getattr__(							self:   Union[str, Any]		,					_lowerCamelCase:   Optional[Any]		):
																						return getattr(self._file		,					_lowerCamelCase		)

											def fixed_enter(*_lowerCamelCase:   Dict		,					**_lowerCamelCase:   Any		):
																		return WrappedFile(_enter(*_lowerCamelCase		,					**_lowerCamelCase		)		)

											SCREAMING_SNAKE_CASE_   	=    fixed_enter








import re
import string

import numpy as np

import datasets


__SCREAMING_SNAKE_CASE 						="""
Returns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.
"""

__SCREAMING_SNAKE_CASE 						="""
Args:
    predictions: List of predicted texts.
    references: List of reference texts.
    regexes_to_ignore: List, defaults to None. Regex expressions of characters to
        ignore when calculating the exact matches. Note: these regexes are removed
        from the input data before the changes based on the options below (e.g. ignore_case,
        ignore_punctuation, ignore_numbers) are applied.
    ignore_case: Boolean, defaults to False. If true, turns everything
        to lowercase so that capitalization differences are ignored.
    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
Returns:
    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.
Examples:
    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    25.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    50.0


    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    75.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)
    >>> print(round(results[\"exact_match\"], 1))
    100.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"The cat sat on the mat.\", \"Theaters are great.\", \"It's like comparing oranges and apples.\"]
    >>> preds = [\"The cat sat on the mat?\", \"Theaters are great.\", \"It's like comparing apples and oranges.\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    33.3

"""

__SCREAMING_SNAKE_CASE 						="""
"""






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,  _KWARGS_DESCRIPTION)
class  __magic_name__						(  datasets.Metric):
				'''simple docstring'''







				def     _A							(							self:   Optional[int]		):
											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     _A							(							self:   Tuple		,					_lowerCamelCase:   int		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Tuple=None		,					_lowerCamelCase:   str=False		,					_lowerCamelCase:   List[str]=False		,					_lowerCamelCase:   List[str]=False		,					):
											if regexes_to_ignore is not None:
																		for s in regexes_to_ignore:
																									SCREAMING_SNAKE_CASE_   	=    np.array([re.sub(_lowerCamelCase		,					''''''		,					_lowerCamelCase		) for x in predictions]		)
																									SCREAMING_SNAKE_CASE_   	=    np.array([re.sub(_lowerCamelCase		,					''''''		,					_lowerCamelCase		) for x in references]		)
											else:
																		SCREAMING_SNAKE_CASE_   	=    np.asarray(_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.asarray(_lowerCamelCase		)

											if ignore_case:
																		SCREAMING_SNAKE_CASE_   	=    np.char.lower(_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.lower(_lowerCamelCase		)

											if ignore_punctuation:
																		SCREAMING_SNAKE_CASE_   	=    string.punctuation.maketrans(''''''		,					''''''		,					string.punctuation		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)

											if ignore_numbers:
																		SCREAMING_SNAKE_CASE_   	=    string.digits.maketrans(''''''		,					''''''		,					string.digits		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    predictions == references

											return {"exact_match": np.mean(_lowerCamelCase		) * 1_00}


