




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






def 				UpperCAmelCase__  (							_A			):






  """simple docstring"""


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

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

  def remove_punc(_A			):
    a_		    =  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(lowercase__			)			)			)			)






def 				UpperCAmelCase__  (							_A      ,      _A			):






  """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 				UpperCAmelCase__  (							_A      ,      _A			):






  """simple docstring"""


  return normalize_answer(lowercase__			) == normalize_answer(lowercase__			)






def 				UpperCAmelCase__  (							_A      ,      _A      ,      _A			):






  """simple docstring"""


  a_		    =  []
  for ground_truth in ground_truths:
    a_		    =  metric_fn(lowercase__      ,      lowercase__			)
    scores_for_ground_truths.append(lowercase__			)
  return max(lowercase__			)






def 				UpperCAmelCase__  (							_A      ,      _A			):






  """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_		    =  100.0 * exact_match / total
  a_		    =  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"""




__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()





