



import re
import string

import numpy as np

import datasets


_lowerCamelCase						    =  """
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.
"""

_lowerCamelCase						    =  """
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

"""

_lowerCamelCase						    =  """
"""

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





     def 	__snake_case    (       self :							List[Any]				)->Optional[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 	__snake_case    (       self :							List[Any]     ,  UpperCamelCase :							Any     ,  UpperCamelCase :							List[str]     ,  UpperCamelCase :							Union[str, Any]=None     ,  UpperCamelCase :							List[str]=False     ,  UpperCamelCase :							Optional[int]=False     ,  UpperCamelCase :							Optional[Any]=False     ,  )->Optional[int]:
      if regexes_to_ignore is not None:
       for s in regexes_to_ignore:
        __SCREAMING_SNAKE_CASE       :    Any       =	np.array([re.sub(UpperCamelCase     ,  ""     ,  UpperCamelCase				) for x in predictions]				)
        __SCREAMING_SNAKE_CASE       :    Any       =	np.array([re.sub(UpperCamelCase     ,  ""     ,  UpperCamelCase				) for x in references]				)
      else:
       __SCREAMING_SNAKE_CASE       :    Optional[int]       =	np.asarray(UpperCamelCase				)
       __SCREAMING_SNAKE_CASE       :    Any       =	np.asarray(UpperCamelCase				)

      if ignore_case:
       __SCREAMING_SNAKE_CASE       :    Any       =	np.char.lower(UpperCamelCase				)
       __SCREAMING_SNAKE_CASE       :    Dict       =	np.char.lower(UpperCamelCase				)

      if ignore_punctuation:
       __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	string.punctuation.maketrans(""     ,  ""     ,  string.punctuation				)
       __SCREAMING_SNAKE_CASE       :    List[str]       =	np.char.translate(UpperCamelCase     ,  table=UpperCamelCase				)
       __SCREAMING_SNAKE_CASE       :    Any       =	np.char.translate(UpperCamelCase     ,  table=UpperCamelCase				)

      if ignore_numbers:
       __SCREAMING_SNAKE_CASE       :    Optional[int]       =	string.digits.maketrans(""     ,  ""     ,  string.digits				)
       __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	np.char.translate(UpperCamelCase     ,  table=UpperCamelCase				)
       __SCREAMING_SNAKE_CASE       :    List[Any]       =	np.char.translate(UpperCamelCase     ,  table=UpperCamelCase				)

      __SCREAMING_SNAKE_CASE       :    List[Any]       =	predictions == references

      return {"exact_match": np.mean(UpperCamelCase				) * 1_0_0}











from abc import ABC, abstractmethod
from typing import Optional, Union

from .. import Dataset, DatasetDict, Features, IterableDataset, IterableDatasetDict, NamedSplit
from ..utils.typing import NestedDataStructureLike, PathLike

class       _SCREAMING_SNAKE_CASE	(UpperCamelCase ):





     def __init__(       self :							List[str]     ,  UpperCamelCase :							Optional[NestedDataStructureLike[PathLike]] = None     ,  UpperCamelCase :							Optional[NamedSplit] = None     ,  UpperCamelCase :							Optional[Features] = None     ,  UpperCamelCase :							str = None     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							Optional[int] = None     ,  **UpperCamelCase :							Dict     ,  )->int:
      __SCREAMING_SNAKE_CASE       :    List[str]       =	path_or_paths
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	split if split or isinstance(UpperCamelCase     ,  UpperCamelCase				) else "train"
      __SCREAMING_SNAKE_CASE       :    Dict       =	features
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	cache_dir
      __SCREAMING_SNAKE_CASE       :    Tuple       =	keep_in_memory
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	streaming
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	num_proc
      __SCREAMING_SNAKE_CASE       :    int       =	kwargs






     @abstractmethod
     def 	__snake_case    (       self :							Optional[int]				)->Union[Dataset, DatasetDict, IterableDataset, IterableDatasetDict]:
      pass






class       _SCREAMING_SNAKE_CASE	(UpperCamelCase ):





     def __init__(       self :							Optional[Any]     ,  UpperCamelCase :							Optional[Features] = None     ,  UpperCamelCase :							str = None     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							Optional[int] = None     ,  **UpperCamelCase :							Dict     ,  )->Optional[int]:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	features
      __SCREAMING_SNAKE_CASE       :    str       =	cache_dir
      __SCREAMING_SNAKE_CASE       :    Any       =	keep_in_memory
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	streaming
      __SCREAMING_SNAKE_CASE       :    int       =	num_proc
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	kwargs






     @abstractmethod
     def 	__snake_case    (       self :							str				)->Union[Dataset, IterableDataset]:
      pass






