

"""simple docstring"""




import argparse
import json
import re
import string
import sys
from collections import Counter
def   __SCREAMING_SNAKE_CASE		(		lowercase__ ):
					"""simple docstring"""

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

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

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

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

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

					A     =   1_00.0 * exact_match / total
					A     =   1_00.0 * fa / total

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


if __name__ == "__main__":
	__A	:       Union[str, Any]        =						'1.1'
	__A	:       List[str]        =						argparse.ArgumentParser(description='Evaluation for SQuAD ' + expected_version)
	parser.add_argument('dataset_file', help='Dataset file')
	parser.add_argument('prediction_file', help='Prediction File')
	__A	:       int        =						parser.parse_args()
	with open(args.dataset_file) as dataset_file:
		__A	:       Optional[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,
			)
		__A	:       int        =						dataset_json['data']
	with open(args.prediction_file) as prediction_file:
		__A	:       Union[str, Any]        =						json.load(prediction_file)
	print(json.dumps(evaluate(dataset, predictions)))








"""simple docstring"""




__A	:       dict[str, float]        =						{
    "kilogram": 1,
    "gram": pow(10, 3),
    "milligram": pow(10, 6),
    "metric-ton": pow(10, -3),
    "long-ton": 0.00_09_84_20_73,
    "short-ton": 0.00_11_02_31_22,
    "pound": 2.20_46_24_42_02,
    "stone": 0.15_74_73_17_28,
    "ounce": 35.2_73_99_07_23,
    "carrat": 50_00,
    "atomic-mass-unit": 6.0_2213_6652E26,
}

__A	:       dict[str, float]        =						{
    "kilogram": 1,
    "gram": pow(10, -3),
    "milligram": pow(10, -6),
    "metric-ton": pow(10, 3),
    "long-ton": 10_16.0_46_08,
    "short-ton": 9_07.1_84,
    "pound": 0.45_35_92,
    "stone": 6.3_50_29,
    "ounce": 0.0_28_34_95,
    "carrat": 0.00_02,
    "atomic-mass-unit": 1.6_6054_0199E-27,
}
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					if to_type not in KILOGRAM_CHART or from_type not in WEIGHT_TYPE_CHART:
										A     =   (
										    F"""Invalid 'from_type' or 'to_type' value: {from_type!r}, {to_type!r}\n"""
										    F"""Supported values are: {", ".join(lowercase__ )}"""
										)
										raise ValueError(lowercase__ )
					return value * KILOGRAM_CHART[to_type] * WEIGHT_TYPE_CHART[from_type]


if __name__ == "__main__":
	import doctest

	doctest.testmod()





