

'''simple docstring'''



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

def   lowerCamelCase__       (      a__)		->    Union[str, Any]:



				"""simple docstring"""







				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__):
								_snake_case : List[str]												=		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__)		->    Dict:



				"""simple docstring"""







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

def   lowerCamelCase__       (      a__			,      a__)		->    Tuple:



				"""simple docstring"""







				return normalize_answer(a__) == normalize_answer(a__)

def   lowerCamelCase__       (      a__			,      a__			,      a__)		->    List[str]:



				"""simple docstring"""







				_snake_case : Optional[int]												=		[]
				for ground_truth in ground_truths:
								_snake_case : Tuple												=		metric_fn(a__			,      a__)
								scores_for_ground_truths.append(a__)
				return max(a__)

def   lowerCamelCase__       (      a__			,      a__)		->    str:



				"""simple docstring"""







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

				_snake_case : Optional[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__":
			SCREAMING_SNAKE_CASE_    =   "1.1"
			SCREAMING_SNAKE_CASE_    =   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_    =   parser.parse_args()
			with open(args.dataset_file) as dataset_file:
						SCREAMING_SNAKE_CASE_    =   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_    =   dataset_json["data"]
			with open(args.prediction_file) as prediction_file:
						SCREAMING_SNAKE_CASE_    =   json.load(prediction_file)
			print(json.dumps(evaluate(dataset, predictions)))






'''simple docstring'''



def   lowerCamelCase__       (      a__			,      a__)		->    int:



    """simple docstring"""







    _snake_case : Tuple												=		0
    for ele in arr:
        total_sum += product_sum(a__			,      depth + 1) if isinstance(a__			,      a__) else ele
    return total_sum * depth

def   lowerCamelCase__       (      a__)		->    int:



    """simple docstring"""







    return product_sum(a__			,      1)


if __name__ == "__main__":
   import doctest

   doctest.testmod()



