





"""simple docstring"""




_SCREAMING_SNAKE_CASE 		=						"""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"""


def 							SCREAMING_SNAKE_CASE__  (      __a				):
	# Make sure the supplied data is a bytes-like object
	if not isinstance(__a				,	__a				):
		snake_case_						:     Union[str, Any]     =		f"""a bytes-like object is required, not '{data.__class__.__name__}'"""
		raise TypeError(__a				)

	snake_case_						:     Dict     =		''.join(bin(__a				)[2:].zfill(8				) for byte in data				)

	snake_case_						:     List[Any]     =		len(__a				) % 6 != 0

	if padding_needed:
		# The padding that will be added later
		snake_case_						:     List[str]     =		b'=' * ((6 - len(__a				) % 6) // 2)

		# Append binary_stream with arbitrary binary digits (0's by default) to make its
		# length a multiple of 6.
		binary_stream += "0" * (6 - len(__a				) % 6)
	else:
		snake_case_						:     Any     =		b''

	# Encode every 6 binary digits to their corresponding Base64 character
	return (
	    "".join(
	        B64_CHARSET[int(binary_stream[index : index + 6]				,	2				)]
	        for index in range(0				,	len(__a				)				,	6				)				).encode()
	    + padding
	)


def 							SCREAMING_SNAKE_CASE__  (      __a				):
	# Make sure encoded_data is either a string or a bytes-like object
	if not isinstance(__a				,	__a				) and not isinstance(__a				,	__a				):
		snake_case_						:     Tuple     =		(
		    'argument should be a bytes-like object or ASCII string, '
		    f"""not '{encoded_data.__class__.__name__}'"""
		)
		raise TypeError(__a				)

	# In case encoded_data is a bytes-like object, make sure it contains only
	# ASCII characters so we convert it to a string object
	if isinstance(__a				,	__a				):
		try:
			snake_case_						:     Union[str, Any]     =		encoded_data.decode('utf-8'				)
		except UnicodeDecodeError:
			raise ValueError('base64 encoded data should only contain ASCII characters'				)

	snake_case_						:     Union[str, Any]     =		encoded_data.count('='				)

	# Check if the encoded string contains non base64 characters
	if padding:
		assert all(
		    char in B64_CHARSET for char in encoded_data[:-padding]				), "Invalid base64 character(s) found."
	else:
		assert all(
		    char in B64_CHARSET for char in encoded_data				), "Invalid base64 character(s) found."

	# Check the padding
	assert len(__a				) % 4 == 0 and padding < 3, "Incorrect padding"

	if padding:
		# Remove padding if there is one
		snake_case_						:     Optional[int]     =		encoded_data[:-padding]

		snake_case_						:     Tuple     =		''.join(
		    bin(B64_CHARSET.index(__a				)				)[2:].zfill(6				) for char in encoded_data				)[: -padding * 2]
	else:
		snake_case_						:     List[str]     =		''.join(
		    bin(B64_CHARSET.index(__a				)				)[2:].zfill(6				) for char in encoded_data				)

	snake_case_						:     int     =		[
	    int(binary_stream[index : index + 8]				,	2				)
	    for index in range(0				,	len(__a				)				,	8				)
	]

	return bytes(__a				)


if __name__ == "__main__":
						import doctest

						doctest.testmod()








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






						def UpperCAmelCase_			( self : Union[str, Any]		)							->      Optional[Any]:







							"""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[Any]						,				_A : Optional[Any]						,				_A : Optional[int]						,				_A : Optional[int]=None						,				_A : Dict=False						,				_A : Dict=False						,				_A : Optional[Any]=False						,				)							->      List[str]:







							"""simple docstring"""


							if regexes_to_ignore is not None:
								for s in regexes_to_ignore:
									snake_case_						:     List[str]     =		np.array([re.sub(_A						,				''						,				_A		) for x in predictions]		)
									snake_case_						:     int     =		np.array([re.sub(_A						,				''						,				_A		) for x in references]		)
							else:
								snake_case_						:     Optional[Any]     =		np.asarray(_A		)
								snake_case_						:     Optional[Any]     =		np.asarray(_A		)

							if ignore_case:
								snake_case_						:     int     =		np.char.lower(_A		)
								snake_case_						:     List[str]     =		np.char.lower(_A		)

							if ignore_punctuation:
								snake_case_						:     str     =		string.punctuation.maketrans(''						,				''						,				string.punctuation		)
								snake_case_						:     str     =		np.char.translate(_A						,				table=_A		)
								snake_case_						:     Any     =		np.char.translate(_A						,				table=_A		)

							if ignore_numbers:
								snake_case_						:     int     =		string.digits.maketrans(''						,				''						,				string.digits		)
								snake_case_						:     Tuple     =		np.char.translate(_A						,				table=_A		)
								snake_case_						:     Optional[Any]     =		np.char.translate(_A						,				table=_A		)

							snake_case_						:     Optional[Any]     =		predictions == references

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

