"""simple docstring"""







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




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				Tuple						)    ->     int:







     '''simple docstring'''


     def remove_articles(_SCREAMING_SNAKE_CASE				:				List[Any]						):
          return re.sub(r'\b(a|an|the)\b'  ,       ' '  ,       _SCREAMING_SNAKE_CASE						)

     def white_space_fix(_SCREAMING_SNAKE_CASE				:				Dict						):
          return " ".join(text.split()						)

     def remove_punc(_SCREAMING_SNAKE_CASE				:				int						):
          __A					:					Dict								=		set(string.punctuation						)
          return "".join(ch for ch in text if ch not in exclude						)

     def lower(_SCREAMING_SNAKE_CASE				:				Optional[int]						):
          return text.lower()

     return white_space_fix(remove_articles(remove_punc(lower(_SCREAMING_SNAKE_CASE						)						)						)						)




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				Tuple  ,       _SCREAMING_SNAKE_CASE				:				List[Any]						)    ->     List[str]:







     '''simple docstring'''


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




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				Tuple  ,       _SCREAMING_SNAKE_CASE				:				Tuple						)    ->     Optional[Any]:







     '''simple docstring'''


     return normalize_answer(_SCREAMING_SNAKE_CASE						) == normalize_answer(_SCREAMING_SNAKE_CASE						)




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				List[str]  ,       _SCREAMING_SNAKE_CASE				:				Any  ,       _SCREAMING_SNAKE_CASE				:				Union[str, Any]						)    ->     Dict:







     '''simple docstring'''


     __A					:					str								=		[]
     for ground_truth in ground_truths:
          __A					:					List[str]								=		metric_fn(_SCREAMING_SNAKE_CASE  ,       _SCREAMING_SNAKE_CASE						)
          scores_for_ground_truths.append(_SCREAMING_SNAKE_CASE						)
     return max(_SCREAMING_SNAKE_CASE						)




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				int  ,       _SCREAMING_SNAKE_CASE				:				Dict						)    ->     Dict:







     '''simple docstring'''


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

     __A					:					Dict								=		1_00.0 * exact_match / total
     __A					:					int								=		1_00.0 * fa / total

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


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




"""simple docstring"""







from __future__ import annotations

import random
from collections.abc import Iterable
from typing import Any, Generic, TypeVar

lowerCamelCase      : List[str]       =TypeVar('''T''', bound=bool)






class 							__snake_case(					Generic[T]	):


    '''simple docstring'''





    def __init__(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					T								=		value
         __A					:					RandomizedHeapNode[T] | None								=		None
         __A					:					RandomizedHeapNode[T] | None								=		None
    @property
    def 						_a							(  self	):




         '''simple docstring'''



         return self._value

    @staticmethod
    def 						_a							(  __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         if not roota:
              return roota

         if not roota:
              return roota

         if roota.value > roota.value:
              __A						,		__A					:					List[str]								=		roota, roota

         if random.choice([True, False]	):
              __A						,		__A					:					Dict								=		roota.right, roota.left

         __A					:					Dict								=		RandomizedHeapNode.merge(roota.left					,       __lowerCamelCase	)

         return roota







class 							__snake_case(					Generic[T]	):


    '''simple docstring'''





    def __init__(  self					,       __lowerCamelCase = ()	):




         '''simple docstring'''



         __A					:					RandomizedHeapNode[T] | None								=		None

         if data:
              for item in data:
                   self.insert(__lowerCamelCase	)
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					List[str]								=		RandomizedHeapNode.merge(self._root					,       RandomizedHeapNode(__lowerCamelCase	)	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					int								=		self.top()

         if self._root is None:
              return None

         __A					:					Dict								=		RandomizedHeapNode.merge(self._root.left					,       self._root.right	)

         return result
    def 						_a							(  self	):




         '''simple docstring'''



         if not self._root:
              raise IndexError('Can\'t get top element for the empty heap.'	)
         return self._root.value
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Dict								=		None
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Tuple								=		[]
         while self:
              result.append(self.pop()	)

         return result

    def __bool__(  self	):




         '''simple docstring'''



         return self._root is not None


if __name__ == "__main__":
       import doctest

       doctest.testmod()



