
'''simple docstring'''





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

def   A			(							A_				:       str							):

						def remove_articles(A_				:       Optional[Any]							):
												return re.sub(R'''\b(a|an|the)\b'''     ,				''' '''     ,				A_							)

						def white_space_fix(A_				:       Union[str, Any]							):
												return " ".join(text.split()							)

						def remove_punc(A_				:       Optional[Any]							):
												snake_case							:  Optional[Any]			=     set(string.punctuation							)
												return "".join(ch for ch in text if ch not in exclude							)

						def lower(A_				:       Tuple							):
												return text.lower()

						return white_space_fix(remove_articles(remove_punc(lower(A_							)							)							)							)

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

def   A			(							A_				:       List[Any]     ,				A_				:       List[str]							):
						return normalize_answer(A_							) == normalize_answer(A_							)

def   A			(							A_				:       str     ,				A_				:       List[str]     ,				A_				:       int							):
						snake_case							:  Tuple			=     []
						for ground_truth in ground_truths:
												snake_case							:  int			=     metric_fn(A_     ,				A_							)
												scores_for_ground_truths.append(A_							)
						return max(A_							)

def   A			(							A_				:       str     ,				A_				:       str							):
						snake_case							:  Union[str, Any]			=     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							:  Tuple			=     '''Unanswered question ''' + qa['''id'''] + ''' will receive score 0.'''
																														print(A_     ,				file=sys.stderr							)
																														continue
																								snake_case							:  Any			=     [x['''text'''] for x in qa['''answers''']]
																								snake_case							:  Dict			=     predictions[qa['''id''']]
																								exact_match += metric_max_over_ground_truths(A_     ,				A_     ,				A_							)
																								fa += metric_max_over_ground_truths(A_     ,				A_     ,				A_							)

						snake_case							:  List[Any]			=     100.0 * exact_match / total
						snake_case							:  List[str]			=     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'''





import math
from timeit import timeit

def   A			(							A_				:       int							):
						snake_case							:  List[str]			=     0
						snake_case							:  Any			=     abs(A_							)
						while True:
												snake_case							:  List[Any]			=     n // 10
												digits += 1
												if n == 0:
																		break
						return digits

def   A			(							A_				:       int							):
						return 1 if n == 0 else math.floor(math.log(abs(A_							)     ,				10							) + 1							)

def   A			(							A_				:       int							):
						return len(str(abs(A_							)							)							)

def   A			(							):
						from collections.abc import Callable

						def benchmark_a_function(A_				:       Callable     ,				A_				:       int							) -> None:
												snake_case							:  Optional[int]			=     F"""{func.__name__}({value})"""
												snake_case							:  Optional[int]			=     timeit(F"""__main__.{call}"""     ,				setup='''import __main__'''							)
												print(F"""{call}: {func(A_							)} -- {timing} seconds"""							)

						for value in (262144, 1125899906842624, 1267650600228229401496703205376):
												for func in (num_digits, num_digits_fast, num_digits_faster):
																		benchmark_a_function(A_     ,				A_							)
												print()


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						benchmark()

