


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







def 			a_							(  UpperCamelCase_   ):

							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_   ):
														A_ 						=		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 			a_							(  UpperCamelCase_	,     UpperCamelCase_   ):
							A_ 						=		normalize_answer(UpperCamelCase_   ).split()
							A_ 						=		normalize_answer(UpperCamelCase_   ).split()
							A_ 						=		Counter(UpperCamelCase_   ) & Counter(UpperCamelCase_   )
							A_ 						=		sum(common.values()   )
							if num_same == 0:
														return 0
							A_ 						=		1.0 * num_same / len(UpperCamelCase_   )
							A_ 						=		1.0 * num_same / len(UpperCamelCase_   )
							A_ 						=		(2 * precision * recall) / (precision + recall)
							return fa







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







def 			a_							(  UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_   ):
							A_ 						=		[]
							for ground_truth in ground_truths:
														A_ 						=		metric_fn(UpperCamelCase_	,     UpperCamelCase_   )
														scores_for_ground_truths.append(UpperCamelCase_   )
							return max(UpperCamelCase_   )







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

							A_ 						=		100.0 * exact_match / total
							A_ 						=		100.0 * fa / total

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


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









'''simple docstring'''
def 			a_							(  UpperCamelCase_   ):
							if not isinstance(UpperCamelCase_	,     UpperCamelCase_   ):
														A_ 						=		f"Input value of [number={number}] must be an integer"
														raise TypeError(UpperCamelCase_   )
							if number < 0 or number % 2 == 1:
														return False
							A_ 						=		int(number**0.5   )
							return number == number_sqrt * (number_sqrt + 1)


if __name__ == "__main__":
							import doctest

							doctest.testmod()





