





import argparse
import json
import re
import string
import sys
from collections import Counter


def 			lowerCamelCase_		(					lowerCAmelCase:		List[str] )->						Optional[Any]:

  def remove_articles(lowerCAmelCase:		Dict ):
    return re.sub(R'\b(a|an|the)\b'			,							' '			,							lowerCAmelCase )

  def white_space_fix(lowerCAmelCase:		Any ):
    return " ".join(text.split() )

  def remove_punc(lowerCAmelCase:		List[Any] ):
    _snake_case      : List[str]														=		set(string.punctuation )
    return "".join(ch for ch in text if ch not in exclude )

  def lower(lowerCAmelCase:		Union[str, Any] ):
    return text.lower()

  return white_space_fix(remove_articles(remove_punc(lower(lowerCAmelCase ) ) ) )


def 			lowerCamelCase_		(					lowerCAmelCase:		int			,							lowerCAmelCase:		List[str] )->						Tuple:
  _snake_case      : Dict														=		normalize_answer(lowerCAmelCase ).split()
  _snake_case      : Optional[int]														=		normalize_answer(lowerCAmelCase ).split()
  _snake_case      : Optional[Any]														=		Counter(lowerCAmelCase ) & Counter(lowerCAmelCase )
  _snake_case      : Tuple														=		sum(common.values() )
  if num_same == 0:
    return 0
  _snake_case      : Dict														=		1.0 * num_same / len(lowerCAmelCase )
  _snake_case      : List[str]														=		1.0 * num_same / len(lowerCAmelCase )
  _snake_case      : List[Any]														=		(2 * precision * recall) / (precision + recall)
  return fa


def 			lowerCamelCase_		(					lowerCAmelCase:		Optional[int]			,							lowerCAmelCase:		List[str] )->						Tuple:
  return normalize_answer(lowerCAmelCase ) == normalize_answer(lowerCAmelCase )


def 			lowerCamelCase_		(					lowerCAmelCase:		int			,							lowerCAmelCase:		Union[str, Any]			,							lowerCAmelCase:		Optional[Any] )->						Dict:
  _snake_case      : Union[str, Any]														=		[]
  for ground_truth in ground_truths:
    _snake_case      : List[str]														=		metric_fn(lowerCAmelCase			,							lowerCAmelCase )
    scores_for_ground_truths.append(lowerCAmelCase )
  return max(lowerCAmelCase )


def 			lowerCamelCase_		(					lowerCAmelCase:		List[str]			,							lowerCAmelCase:		Tuple )->						Any:
  _snake_case      : Union[str, Any]														=		0
  for article in dataset:
    for paragraph in article["paragraphs"]:
      for qa in paragraph["qas"]:
        total += 1
        if qa["id"] not in predictions:
          _snake_case      : List[str]														=		'Unanswered question ' + qa['id'] + ' will receive score 0.'
          print(lowerCAmelCase			,							file=sys.stderr )
          continue
        _snake_case      : List[str]														=		[x['text'] for x in qa['answers']]
        _snake_case      : str														=		predictions[qa['id']]
        exact_match += metric_max_over_ground_truths(lowerCAmelCase			,							lowerCAmelCase			,							lowerCAmelCase )
        fa += metric_max_over_ground_truths(lowerCAmelCase			,							lowerCAmelCase			,							lowerCAmelCase )

  _snake_case      : List[Any]														=		1_0_0.0 * exact_match / total
  _snake_case      : Optional[Any]														=		1_0_0.0 * fa / total

  return {"exact_match": exact_match, "f1": fa}


if __name__ == "__main__":
      lowerCAmelCase_        =			"""1.1"""
      lowerCAmelCase_        =			argparse.ArgumentParser(description="""Evaluation for SQuAD """ + expected_version)
      parser.add_argument("""dataset_file""", help="""Dataset file""")
      parser.add_argument("""prediction_file""", help="""Prediction File""")
      lowerCAmelCase_        =			parser.parse_args()
      with open(args.dataset_file) as dataset_file:
            lowerCAmelCase_        =			json.load(dataset_file)
            if dataset_json["version"] != expected_version:
                  print(
                      """Evaluation expects v-""" + expected_version + """, but got dataset with v-""" + dataset_json["""version"""],
                      file=sys.stderr,
                  )
            lowerCAmelCase_        =			dataset_json["""data"""]
      with open(args.prediction_file) as prediction_file:
            lowerCAmelCase_        =			json.load(prediction_file)
      print(json.dumps(evaluate(dataset, predictions)))











def    _lowercase    (  _UpperCAmelCase = 99_80_01 )  ->     int:

				# fetches the next number
				for number in range(n - 1	,					99_99	,					-1 ):
								lowerCamelCase		       =str(_UpperCAmelCase )

								# checks whether 'str_number' is a palindrome.
								if str_number == str_number[::-1]:
												lowerCamelCase		       =9_99

												# if 'number' is a product of two 3-digit numbers
												# then number is the answer otherwise fetch next number.
												while divisor != 99:
																if (number % divisor == 0) and (len(str(number // divisor ) ) == 3.0):
																				return number
																divisor -= 1
				raise ValueError("""That number is larger than our acceptable range.""" )


if __name__ == "__main__":
							print(F"{solution() = }")





