





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





def  a_       (							_lowercase     ):







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

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

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

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

						return white_space_fix(remove_articles(remove_punc(lower(_lowercase     )     )     )     )





def  a_       (							_lowercase ,		_lowercase     ):
						_UpperCamelCase    :      Optional[Any]						     =					normalize_answer(_lowercase     ).split()
						_UpperCamelCase    :      int						     =					normalize_answer(_lowercase     ).split()
						_UpperCamelCase    :      int						     =					Counter(_lowercase     ) & Counter(_lowercase     )
						_UpperCamelCase    :      List[Any]						     =					sum(common.values()     )
						if num_same == 0:
												return 0
						_UpperCamelCase    :      List[Any]						     =					1.0 * num_same / len(_lowercase     )
						_UpperCamelCase    :      Optional[int]						     =					1.0 * num_same / len(_lowercase     )
						_UpperCamelCase    :      Union[str, Any]						     =					(2 * precision * recall) / (precision + recall)
						return fa





def  a_       (							_lowercase ,		_lowercase     ):
						return normalize_answer(_lowercase     ) == normalize_answer(_lowercase     )





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





def  a_       (							_lowercase ,		_lowercase     ):
						_UpperCamelCase    :      List[str]						     =					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[str]						     =					'''Unanswered question ''' + qa['''id'''] + ''' will receive score 0.'''
																														print(_lowercase ,		file=sys.stderr     )
																														continue
																								_UpperCamelCase    :      int						     =					[x['''text'''] for x in qa['''answers''']]
																								_UpperCamelCase    :      Optional[int]						     =					predictions[qa['''id''']]
																								exact_match += metric_max_over_ground_truths(_lowercase ,		_lowercase ,		_lowercase     )
																								fa += metric_max_over_ground_truths(_lowercase ,		_lowercase ,		_lowercase     )

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

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


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










"""simple docstring"""




UpperCamelCase_     =1_000





def  a_       (							_lowercase     ):
						return x * x





def  a_       (							_lowercase ,		_lowercase ,		_lowercase ,		_lowercase = 4     ):
						assert callable(
						    _lowercase     ), F"""the function(object) passed should be callable your input : {function}"""
						assert isinstance(_lowercase ,		(float, int)     ), F"""a should be float or integer your input : {a}"""
						assert isinstance(function(_lowercase     ) ,		(float, int)     ), (
						    "the function should return integer or float return type of your function, "
						    F"""{type(_lowercase     )}"""
						)
						assert isinstance(_lowercase ,		(float, int)     ), F"""b should be float or integer your input : {b}"""
						assert (
						    isinstance(_lowercase ,		_lowercase     ) and precision > 0
						), F"""precision should be positive integer your input : {precision}"""

						# just applying the formula of simpson for approximate integration written in
						# mentioned article in first comment of this file and above this function

						_UpperCamelCase    :      str						     =					(b - a) / N_STEPS
						_UpperCamelCase    :      Dict						     =					function(_lowercase     ) + function(_lowercase     )

						for i in range(1 ,		_lowercase     ):
												_UpperCamelCase    :      List[Any]						     =					a + h * i
												result += function(_lowercase     ) * (4 if i % 2 else 2)

						result *= h / 3
						return round(_lowercase ,		_lowercase     )


if __name__ == "__main__":
						import doctest

						doctest.testmod()



