






"""simple docstring"""



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


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      Tuple							)->						Union[str, Any]:






     '''simple docstring'''



     def remove_articles(snake_case    :      List[Any]							):
          return re.sub(r"\b(a|an|the)\b"       , " "       , snake_case							)

     def white_space_fix(snake_case    :      int							):
          return " ".join(text.split()							)

     def remove_punc(snake_case    :      Any							):
          UpperCAmelCase__		:  Optional[int]				=				set(string.punctuation							)
          return "".join(ch for ch in text if ch not in exclude							)

     def lower(snake_case    :      Any							):
          return text.lower()

     return white_space_fix(remove_articles(remove_punc(lower(snake_case							)							)							)							)


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      Dict       , snake_case    :      List[str]							)->						List[str]:






     '''simple docstring'''



     UpperCAmelCase__		:  List[Any]				=				normalize_answer(snake_case							).split()
     UpperCAmelCase__		:  List[Any]				=				normalize_answer(snake_case							).split()
     UpperCAmelCase__		:  Union[str, Any]				=				Counter(snake_case							) & Counter(snake_case							)
     UpperCAmelCase__		:  Dict				=				sum(common.values()							)
     if num_same == 0:
          return 0
     UpperCAmelCase__		:  List[Any]				=				1.0 * num_same / len(snake_case							)
     UpperCAmelCase__		:  Dict				=				1.0 * num_same / len(snake_case							)
     UpperCAmelCase__		:  Dict				=				(2 * precision * recall) / (precision + recall)
     return fa


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      Tuple       , snake_case    :      Tuple							)->						str:






     '''simple docstring'''



     return normalize_answer(snake_case							) == normalize_answer(snake_case							)


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      int       , snake_case    :      Union[str, Any]       , snake_case    :      Dict							)->						Optional[int]:






     '''simple docstring'''



     UpperCAmelCase__		:  List[Any]				=				[]
     for ground_truth in ground_truths:
          UpperCAmelCase__		:  Optional[int]				=				metric_fn(snake_case       , snake_case							)
          scores_for_ground_truths.append(snake_case							)
     return max(snake_case							)


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      str       , snake_case    :      int							)->						str:






     '''simple docstring'''



     UpperCAmelCase__		:  Dict				=				0
     for article in dataset:
          for paragraph in article["paragraphs"]:
               for qa in paragraph["qas"]:
                    total += 1
                    if qa["id"] not in predictions:
                         UpperCAmelCase__		:  List[Any]				=				"Unanswered question " + qa["id"] + " will receive score 0."
                         print(snake_case       , file=sys.stderr							)
                         continue
                    UpperCAmelCase__		:  Dict				=				[x["text"] for x in qa["answers"]]
                    UpperCAmelCase__		:  int				=				predictions[qa["id"]]
                    exact_match += metric_max_over_ground_truths(snake_case       , snake_case       , snake_case							)
                    fa += metric_max_over_ground_truths(snake_case       , snake_case       , snake_case							)

     UpperCAmelCase__		:  Any				=				100.0 * exact_match / total
     UpperCAmelCase__		:  Optional[Any]				=				100.0 * fa / total

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


if __name__ == "__main__":
 _lowerCAmelCase     :     Any            =	"""1.1"""
 _lowerCAmelCase     :     Optional[Any]            =	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     :     List[Any]            =	parser.parse_args()
 with open(args.dataset_file) as dataset_file:
  _lowerCAmelCase     :     Any            =	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     :     Tuple            =	dataset_json["""data"""]
 with open(args.prediction_file) as prediction_file:
  _lowerCAmelCase     :     List[str]            =	json.load(prediction_file)
 print(json.dumps(evaluate(dataset, predictions)))










"""simple docstring"""



from doctest import testmod
from math import sqrt


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      int							)->						list:






     '''simple docstring'''



     UpperCAmelCase__		:  list[int]				=				[]
     if num < 1:
          return facs
     facs.append(1							)
     if num == 1:
          return facs
     facs.append(snake_case							)
     for i in range(2       , int(sqrt(snake_case							)							) + 1							):
          if num % i == 0:  # If i is a factor of num
               facs.append(snake_case							)
               UpperCAmelCase__		:  Any				=				num // i  # num//i is the other factor of num
               if d != i:  # If d and i are distinct
                    facs.append(snake_case							)  # we have found another factor
     facs.sort()
     return facs


if __name__ == "__main__":
 testmod(name="""factors_of_a_number""", verbose=True)


