






import argparse
import json
import re
import string
import sys
from collections import Counter
def      lowerCamelCase					(						a_	)	->			Any:

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

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

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

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

							return white_space_fix(remove_articles(remove_punc(lower(a_	)	)	)	)
def      lowerCamelCase					(						a_ ,						a_	)	->			int:
							lowerCAmelCase_										=     normalize_answer(a_	).split()
							lowerCAmelCase_										=     normalize_answer(a_	).split()
							lowerCAmelCase_										=     Counter(a_	) & Counter(a_	)
							lowerCAmelCase_										=     sum(common.values()	)
							if num_same == 0:
														return 0
							lowerCAmelCase_										=     1.0 * num_same / len(a_	)
							lowerCAmelCase_										=     1.0 * num_same / len(a_	)
							lowerCAmelCase_										=     (2 * precision * recall) / (precision + recall)
							return fa
def      lowerCamelCase					(						a_ ,						a_	)	->			List[str]:
							return normalize_answer(a_	) == normalize_answer(a_	)
def      lowerCamelCase					(						a_ ,						a_ ,						a_	)	->			Optional[int]:
							lowerCAmelCase_										=     []
							for ground_truth in ground_truths:
														lowerCAmelCase_										=     metric_fn(a_ ,						a_	)
														scores_for_ground_truths.append(a_	)
							return max(a_	)
def      lowerCamelCase					(						a_ ,						a_	)	->			List[Any]:
							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(a_ ,						file=sys.stderr	)
																																			continue
																												lowerCAmelCase_										=     [x['text'] for x in qa['answers']]
																												lowerCAmelCase_										=     predictions[qa['id']]
																												exact_match += metric_max_over_ground_truths(a_ ,						a_ ,						a_	)
																												fa += metric_max_over_ground_truths(a_ ,						a_ ,						a_	)

							lowerCAmelCase_										=     100.0 * exact_match / total
							lowerCAmelCase_										=     100.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)))











from doctest import testmod
from math import sqrt
def      lowerCamelCase					(						a_	)	->			list:
							lowerCAmelCase_										=     []
							if num < 1:
														return facs
							facs.append(1	)
							if num == 1:
														return facs
							facs.append(a_	)
							for i in range(2 ,						int(sqrt(a_	)	) + 1	):
														if num % i == 0:  # If i is a factor of num
																					facs.append(a_	)
																					lowerCAmelCase_										=     num // i  # num//i is the other factor of num
																					if d != i:  # If d and i are distinct
																												facs.append(a_	)  # we have found another factor
							facs.sort()
							return facs


if __name__ == "__main__":
		testmod(name="""factors_of_a_number""", verbose=True)



