
import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


lowerCamelCase__     :		Any        = get_logger(__name__)



class    _snake_case (						enum.Enum				):
 __lowerCAmelCase	:  Optional[Any]	   =      'all_checks'
 __lowerCAmelCase	:  int	   =      'basic_checks'
 __lowerCAmelCase	:  str	   =      'no_checks'



class    _snake_case (						UpperCAmelCase_				):
 pass



class    _snake_case (						UpperCAmelCase_				):
 pass



class    _snake_case (						UpperCAmelCase_				):
 pass



class    _snake_case (						UpperCAmelCase_				):
 pass

def 		UpperCamelCase						(   lowercase_			,			lowercase_			,			lowercase_=None )		->						List[str]:


  '''simple docstring'''






  if expected_checksums is None:
    logger.info("""Unable to verify checksums.""" )
    return
  if len(set(lowercase_ ) - set(lowercase_ ) ) > 0:
    raise ExpectedMoreDownloadedFiles(str(set(lowercase_ ) - set(lowercase_ ) ) )
  if len(set(lowercase_ ) - set(lowercase_ ) ) > 0:
    raise UnexpectedDownloadedFile(str(set(lowercase_ ) - set(lowercase_ ) ) )
  lowercase__	: Union[str, Any]     		=   [url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
  lowercase__	: Dict     		=   """ for """ + verification_name if verification_name is not None else """"""
  if len(lowercase_ ) > 0:
    raise NonMatchingChecksumError(
        F'Checksums didn\'t match{for_verification_name}:\n'
        F'{bad_urls}\n'
        """Set `verification_mode='no_checks'` to skip checksums verification and ignore this error""" )
  logger.info("""All the checksums matched successfully""" + for_verification_name )



class    _snake_case (						UpperCAmelCase_				):
 pass



class    _snake_case (						UpperCAmelCase_				):
 pass



class    _snake_case (						UpperCAmelCase_				):
 pass



class    _snake_case (						UpperCAmelCase_				):
 pass

def 		UpperCamelCase						(   lowercase_			,			lowercase_ )		->						Union[str, Any]:


  '''simple docstring'''






  if expected_splits is None:
    logger.info("""Unable to verify splits sizes.""" )
    return
  if len(set(lowercase_ ) - set(lowercase_ ) ) > 0:
    raise ExpectedMoreSplits(str(set(lowercase_ ) - set(lowercase_ ) ) )
  if len(set(lowercase_ ) - set(lowercase_ ) ) > 0:
    raise UnexpectedSplits(str(set(lowercase_ ) - set(lowercase_ ) ) )
  lowercase__	: List[str]     		=   [
      {"""expected""": expected_splits[name], """recorded""": recorded_splits[name]}
      for name in expected_splits
      if expected_splits[name].num_examples != recorded_splits[name].num_examples
  ]
  if len(lowercase_ ) > 0:
    raise NonMatchingSplitsSizesError(str(lowercase_ ) )
  logger.info("""All the splits matched successfully.""" )

def 		UpperCamelCase						(   lowercase_			,			lowercase_ = True )		->						dict:


  '''simple docstring'''






  if record_checksum:
    lowercase__	: Dict     		=   shaaaa()
    with open(lowercase_			,			"""rb""" ) as f:
      for chunk in iter(lambda: f.read(1 << 20 )			,			B"""""" ):
        m.update(lowercase_ )
      lowercase__	: Dict     		=   m.hexdigest()
  else:
    lowercase__	: Optional[Any]     		=   None
  return {"num_bytes": os.path.getsize(lowercase_ ), "checksum": checksum}



def 		UpperCamelCase						(   lowercase_ )		->						int:


  '''simple docstring'''






  if dataset_size and config.IN_MEMORY_MAX_SIZE:
    return dataset_size < config.IN_MEMORY_MAX_SIZE
  else:
    return False












'''simple docstring'''







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 	_snake_case(			datasets.Metric      ):






 def 						_UpperCamelCase (self       :  Optional[Any]    )       ->   Dict:






    """simple docstring"""


    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 						_UpperCamelCase (self       :  List[str]    ,		a       :  str    ,		a       :  Tuple    ,		a       :  Tuple=None    ,		a       :  Dict=False    ,		a       :  Dict=False    ,		a       :  List[str]=False    ,		)       ->   int:






    """simple docstring"""


    if regexes_to_ignore is not None:
       for s in regexes_to_ignore:
          A__       =     np.array([re.sub(a    ,		''    ,		a    ) for x in predictions]    )
          A__       =     np.array([re.sub(a    ,		''    ,		a    ) for x in references]    )
    else:
       A__       =     np.asarray(a    )
       A__       =     np.asarray(a    )

    if ignore_case:
       A__       =     np.char.lower(a    )
       A__       =     np.char.lower(a    )

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

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

    A__       =     predictions == references

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


