



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





def 						a__     (						_UpperCamelCase     :	Tuple							):

   def remove_articles(_UpperCamelCase     :	List[str]							):
      return re.sub(R'''\b(a|an|the)\b'''	,''' '''	,_UpperCamelCase							)

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

   def remove_punc(_UpperCamelCase     :	Tuple							):
      __lowerCamelCase  							=      set(string.punctuation							)
      return "".join(ch for ch in text if ch not in exclude							)

   def lower(_UpperCamelCase     :	str							):
      return text.lower()

   return white_space_fix(remove_articles(remove_punc(lower(_UpperCamelCase							)							)							)							)





def 						a__     (						_UpperCamelCase     :	str	,_UpperCamelCase     :	Tuple							):
   __lowerCamelCase  							=      normalize_answer(_UpperCamelCase							).split()
   __lowerCamelCase  							=      normalize_answer(_UpperCamelCase							).split()
   __lowerCamelCase  							=      Counter(_UpperCamelCase							) & Counter(_UpperCamelCase							)
   __lowerCamelCase  							=      sum(common.values()							)
   if num_same == 0:
      return 0
   __lowerCamelCase  							=      1.0 * num_same / len(_UpperCamelCase							)
   __lowerCamelCase  							=      1.0 * num_same / len(_UpperCamelCase							)
   __lowerCamelCase  							=      (2 * precision * recall) / (precision + recall)
   return fa





def 						a__     (						_UpperCamelCase     :	Optional[int]	,_UpperCamelCase     :	Optional[Any]							):
   return normalize_answer(_UpperCamelCase							) == normalize_answer(_UpperCamelCase							)





def 						a__     (						_UpperCamelCase     :	int	,_UpperCamelCase     :	Tuple	,_UpperCamelCase     :	Dict							):
   __lowerCamelCase  							=      []
   for ground_truth in ground_truths:
      __lowerCamelCase  							=      metric_fn(_UpperCamelCase	,_UpperCamelCase							)
      scores_for_ground_truths.append(_UpperCamelCase							)
   return max(_UpperCamelCase							)





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

   __lowerCamelCase  							=      100.0 * exact_match / total
   __lowerCamelCase  							=      100.0 * fa / total

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


if __name__ == "__main__":
  a_								=   """1.1"""
  a_								=   argparse.ArgumentParser(description="""Evaluation for SQuAD """ + expected_version)
  parser.add_argument("""dataset_file""", help="""Dataset file""")
  parser.add_argument("""prediction_file""", help="""Prediction File""")
  a_								=   parser.parse_args()
  with open(args.dataset_file) as dataset_file:
    a_								=   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,
      )
    a_								=   dataset_json["""data"""]
  with open(args.prediction_file) as prediction_file:
    a_								=   json.load(prediction_file)
  print(json.dumps(evaluate(dataset, predictions)))











def 						a__     (						_UpperCamelCase     :	int							):
   if not isinstance(_UpperCamelCase	,_UpperCamelCase							):
      __lowerCamelCase  							=      (
          '''operation can not be conducted on a object of type '''
          F"""{type(_UpperCamelCase							).__name__}"""
      )
      raise TypeError(_UpperCamelCase							)
   __lowerCamelCase  							=      ''''''
   for _ in range(0	,32							):
      bit_string += str(number % 2							)
      __lowerCamelCase  							=      number >> 1
   return bit_string





def 						a__     (						_UpperCamelCase     :	int							):
   if number < 0:
      raise ValueError('''the value of input must be positive'''							)
   elif isinstance(_UpperCamelCase	,_UpperCamelCase							):
      raise TypeError('''Input value must be a \'int\' type'''							)
   elif isinstance(_UpperCamelCase	,_UpperCamelCase							):
      raise TypeError('''\'<\' not supported between instances of \'str\' and \'int\''''							)
   __lowerCamelCase  							=      0
   # iterator over [1 to 32],since we are dealing with 32 bit integer
   for _ in range(1	,33							):
      # left shift the bits by unity
      __lowerCamelCase  							=      result << 1
      # get the end bit
      __lowerCamelCase  							=      number % 2
      # right shift the bits by unity
      __lowerCamelCase  							=      number >> 1
      # add that bit to our ans
      __lowerCamelCase  							=      result | end_bit
   return get_reverse_bit_string(_UpperCamelCase							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()






