





"""simple docstring"""
import argparse
import json
import re
import string
import sys
from collections import Counter



def   __lowerCamelCase     (							a_  :	List[Any]							)    ->   Any:

      def remove_articles(a_  :	Tuple							):
            return re.sub(r'''\b(a|an|the)\b'''				,     ''' '''				,     a_							)

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

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

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

      return white_space_fix(remove_articles(remove_punc(lower(a_							)							)							)							)



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



def   __lowerCamelCase     (							a_  :	str				,     a_  :	str							)    ->   Union[str, Any]:
      return normalize_answer(a_							) == normalize_answer(a_							)



def   __lowerCamelCase     (							a_  :	Dict				,     a_  :	Dict				,     a_  :	List[Any]							)    ->   str:
      __SCREAMING_SNAKE_CASE     :Dict	       =						[]
      for ground_truth in ground_truths:
            __SCREAMING_SNAKE_CASE     :int	       =						metric_fn(a_				,     a_							)
            scores_for_ground_truths.append(a_							)
      return max(a_							)



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

      __SCREAMING_SNAKE_CASE     :Optional[int]	       =						100.0 * exact_match / total
      __SCREAMING_SNAKE_CASE     :Dict	       =						100.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)))






"""simple docstring"""
def   __lowerCamelCase     (							a_  :	str							)    ->   int:
      __SCREAMING_SNAKE_CASE     :List[Any]	       =						0
      for plain_chr in plain_text:
            __SCREAMING_SNAKE_CASE     :List[str]	       =						(
                ord(a_							) + (hash_value << 6) + (hash_value << 16) - hash_value
            )
      return hash_value