
"""simple docstring"""




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

def lowercase_  (       _snake_case						):

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

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

							def remove_punc(_snake_case						):
														SCREAMING_SNAKE_CASE__						:	Union[str, Any]									=       set(string.punctuation						)
														return "".join(ch for ch in text if ch not in exclude						)

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

							return white_space_fix(remove_articles(remove_punc(lower(_snake_case						)						)						)						)

def lowercase_  (       _snake_case       ,_snake_case						):
							SCREAMING_SNAKE_CASE__						:	Tuple									=       normalize_answer(_snake_case						).split()
							SCREAMING_SNAKE_CASE__						:	List[str]									=       normalize_answer(_snake_case						).split()
							SCREAMING_SNAKE_CASE__						:	Union[str, Any]									=       Counter(_snake_case						) & Counter(_snake_case						)
							SCREAMING_SNAKE_CASE__						:	List[str]									=       sum(common.values()						)
							if num_same == 0:
														return 0
							SCREAMING_SNAKE_CASE__						:	Dict									=       1.0 * num_same / len(_snake_case						)
							SCREAMING_SNAKE_CASE__						:	List[str]									=       1.0 * num_same / len(_snake_case						)
							SCREAMING_SNAKE_CASE__						:	str									=       (2 * precision * recall) / (precision + recall)
							return fa

def lowercase_  (       _snake_case       ,_snake_case						):
							return normalize_answer(_snake_case						) == normalize_answer(_snake_case						)

def lowercase_  (       _snake_case       ,_snake_case       ,_snake_case						):
							SCREAMING_SNAKE_CASE__						:	Tuple									=       []
							for ground_truth in ground_truths:
														SCREAMING_SNAKE_CASE__						:	Optional[Any]									=       metric_fn(_snake_case       ,_snake_case						)
														scores_for_ground_truths.append(_snake_case						)
							return max(_snake_case						)

def lowercase_  (       _snake_case       ,_snake_case						):
							SCREAMING_SNAKE_CASE__						:	int									=       0
							for article in dataset:
														for paragraph in article["paragraphs"]:
																					for qa in paragraph["qas"]:
																												total += 1
																												if qa["id"] not in predictions:
																																			SCREAMING_SNAKE_CASE__						:	int									=       """Unanswered question """ + qa["""id"""] + """ will receive score 0."""
																																			print(_snake_case       ,file=sys.stderr						)
																																			continue
																												SCREAMING_SNAKE_CASE__						:	List[Any]									=       [x["""text"""] for x in qa["""answers"""]]
																												SCREAMING_SNAKE_CASE__						:	Union[str, Any]									=       predictions[qa["""id"""]]
																												exact_match += metric_max_over_ground_truths(_snake_case       ,_snake_case       ,_snake_case						)
																												fa += metric_max_over_ground_truths(_snake_case       ,_snake_case       ,_snake_case						)

							SCREAMING_SNAKE_CASE__						:	str									=       100.0 * exact_match / total
							SCREAMING_SNAKE_CASE__						:	List[str]									=       100.0 * fa / total

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


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






"""simple docstring"""




import re

def lowercase_  (       _snake_case						):
							def docstring_decorator(_snake_case						):
														SCREAMING_SNAKE_CASE__						:	Any									=       fn.__doc__
														SCREAMING_SNAKE_CASE__						:	Dict									=       func_doc.split("""\n"""						)
														SCREAMING_SNAKE_CASE__						:	Any									=       0
														while i < len(_snake_case						) and re.search(R"""^\s*Examples?:\s*$"""       ,lines[i]						) is None:
																					i += 1
														if i < len(_snake_case						):
																					SCREAMING_SNAKE_CASE__						:	List[str]									=       example_docstring
																					SCREAMING_SNAKE_CASE__						:	List[Any]									=       """\n""".join(_snake_case						)
														else:
																					raise ValueError(
																					    f'''The function {fn} should have an empty \'Examples:\' in its docstring as placeholder, '''
																					    f'''current docstring is:\n{func_doc}'''						)
														SCREAMING_SNAKE_CASE__						:	int									=       func_doc
														return fn

							return docstring_decorator




