


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



def 				lowerCAmelCase__	(       UpperCAmelCase     ):






       """simple docstring"""





       def remove_articles(UpperCAmelCase     ):
              return re.sub(R"""\b(a|an|the)\b"""    ,       """ """    ,       UpperCAmelCase     )

       def white_space_fix(UpperCAmelCase     ):
              return " ".join(text.split()     )

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

       def lower(UpperCAmelCase     ):
              return text.lower()

       return white_space_fix(remove_articles(remove_punc(lower(UpperCAmelCase     )     )     )     )



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       snake_case__					:	List[str]          =					normalize_answer(UpperCAmelCase     ).split()
       snake_case__					:	str          =					normalize_answer(UpperCAmelCase     ).split()
       snake_case__					:	int          =					Counter(UpperCAmelCase     ) & Counter(UpperCAmelCase     )
       snake_case__					:	Any          =					sum(common.values()     )
       if num_same == 0:
              return 0
       snake_case__					:	Optional[Any]          =					1.0 * num_same / len(UpperCAmelCase     )
       snake_case__					:	int          =					1.0 * num_same / len(UpperCAmelCase     )
       snake_case__					:	Tuple          =					(2 * precision * recall) / (precision + recall)
       return fa



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       return normalize_answer(UpperCAmelCase     ) == normalize_answer(UpperCAmelCase     )



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       snake_case__					:	Any          =					[]
       for ground_truth in ground_truths:
              snake_case__					:	int          =					metric_fn(UpperCAmelCase    ,       UpperCAmelCase     )
              scores_for_ground_truths.append(UpperCAmelCase     )
       return max(UpperCAmelCase     )



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       snake_case__					:	Dict          =					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__					:	Dict          =					"""Unanswered question """ + qa["""id"""] + """ will receive score 0."""
                                   print(UpperCAmelCase    ,       file=sys.stderr     )
                                   continue
                            snake_case__					:	Optional[int]          =					[x["""text"""] for x in qa["""answers"""]]
                            snake_case__					:	Union[str, Any]          =					predictions[qa["""id"""]]
                            exact_match += metric_max_over_ground_truths(UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase     )
                            fa += metric_max_over_ground_truths(UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase     )

       snake_case__					:	Union[str, Any]          =					1_0_0.0 * exact_match / total
       snake_case__					:	Tuple          =					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)))








'''simple docstring'''
import unittest
from timeit import timeit



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       snake_case__					:	Any          =					first_num if first_num >= second_num else second_num
       snake_case__					:	Optional[Any]          =					max_num
       while (common_mult % first_num > 0) or (common_mult % second_num > 0):
              common_mult += max_num
       return common_mult



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       return b if a == 0 else greatest_common_divisor(b % a    ,       UpperCAmelCase     )



def 				lowerCAmelCase__	(       UpperCAmelCase    ,       UpperCAmelCase     ):






       """simple docstring"""





       return first_num // greatest_common_divisor(UpperCAmelCase    ,       UpperCAmelCase     ) * second_num



def 				lowerCAmelCase__	(       ):






       """simple docstring"""





       snake_case__					:	Tuple          =					(
           """from __main__ import least_common_multiple_slow, least_common_multiple_fast"""
       )
       print(
           """least_common_multiple_slow():"""    ,       timeit("""least_common_multiple_slow(1000, 999)"""    ,       setup=UpperCAmelCase     )    ,       )
       print(
           """least_common_multiple_fast():"""    ,       timeit("""least_common_multiple_fast(1000, 999)"""    ,       setup=UpperCAmelCase     )    ,       )







class 					_A						(						unittest.TestCase							):



   '''simple docstring'''






   _lowercase    						= (
       (10, 20),
       (13, 15),
       (4, 31),
       (10, 42),
       (43, 34),
       (5, 12),
       (12, 25),
       (10, 25),
       (6, 9),
   )
   _lowercase    						= (20, 195, 124, 210, 1462, 60, 300, 50, 18)




   def   __lowerCAmelCase						(	self	:					Optional[int]						)->	Optional[Any]:
          for i, (first_num, second_num) in enumerate(self.test_inputs						):
                 snake_case__					:	List[Any]          =					least_common_multiple_slow(lowerCamelCase					, lowerCamelCase						)
                 snake_case__					:	Optional[Any]          =					least_common_multiple_fast(lowerCamelCase					, lowerCamelCase						)
                 with self.subTest(i=lowerCamelCase						):
                        self.assertEqual(lowerCamelCase					, self.expected_results[i]						)
                        self.assertEqual(lowerCamelCase					, self.expected_results[i]						)


if __name__ == "__main__":
     benchmark()
     unittest.main()




