





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




def 			lowerCAmelCase_			(				UpperCamelCase_	)  ->		str:

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

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

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

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

       return white_space_fix(remove_articles(remove_punc(lower(UpperCamelCase_	)	)	)	)




def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_	)  ->		Any:
       UpperCamelCase_ 							=	normalize_answer(UpperCamelCase_	).split()
       UpperCamelCase_ 							=	normalize_answer(UpperCamelCase_	).split()
       UpperCamelCase_ 							=	Counter(UpperCamelCase_	) & Counter(UpperCamelCase_	)
       UpperCamelCase_ 							=	sum(common.values()	)
       if num_same == 0:
              return 0
       UpperCamelCase_ 							=	1.0 * num_same / len(UpperCamelCase_	)
       UpperCamelCase_ 							=	1.0 * num_same / len(UpperCamelCase_	)
       UpperCamelCase_ 							=	(2 * precision * recall) / (precision + recall)
       return fa




def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_	)  ->		Optional[Any]:
       return normalize_answer(UpperCamelCase_	) == normalize_answer(UpperCamelCase_	)




def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_       ,		UpperCamelCase_	)  ->		Tuple:
       UpperCamelCase_ 							=	[]
       for ground_truth in ground_truths:
              UpperCamelCase_ 							=	metric_fn(UpperCamelCase_       ,		UpperCamelCase_	)
              scores_for_ground_truths.append(UpperCamelCase_	)
       return max(UpperCamelCase_	)




def 			lowerCAmelCase_			(				UpperCamelCase_       ,		UpperCamelCase_	)  ->		str:
       UpperCamelCase_ 							=	UpperCamelCase_ 							=	UpperCamelCase_ 							=	0
       for article in dataset:
              for paragraph in article["paragraphs"]:
                     for qa in paragraph["qas"]:
                            total += 1
                            if qa["id"] not in predictions:
                                   UpperCamelCase_ 							=	"Unanswered question " + qa["id"] + " will receive score 0."
                                   print(UpperCamelCase_       ,		file=sys.stderr	)
                                   continue
                            UpperCamelCase_ 							=	[x["text"] for x in qa["answers"]]
                            UpperCamelCase_ 							=	predictions[qa["id"]]
                            exact_match += metric_max_over_ground_truths(UpperCamelCase_       ,		UpperCamelCase_       ,		UpperCamelCase_	)
                            fa += metric_max_over_ground_truths(UpperCamelCase_       ,		UpperCamelCase_       ,		UpperCamelCase_	)

       UpperCamelCase_ 							=	1_00.0 * exact_match / total
       UpperCamelCase_ 							=	1_00.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"""





_lowercase						   =     {0: [1, 2], 1: [0, 3], 2: [0], 3: [1], 4: [5, 6], 5: [4, 6], 6: [4, 5]}

_lowercase						   =     {0: [1, 2, 3], 1: [0, 3], 2: [0], 3: [0, 1], 4: [], 5: []}

def 		lowerCAmelCase				(			lowerCamelCase   ,      lowerCamelCase   ,      lowerCamelCase		):
						'''simple docstring'''


						snake_case__							:       Any				      =       True
						snake_case__							:       int				      =       []

						for neighbour in graph[vert]:
												if not visited[neighbour]:
																		connected_verts += dfs(lowerCamelCase   ,      lowerCamelCase   ,      lowerCamelCase		)

						return [vert, *connected_verts]

def 		lowerCAmelCase				(			lowerCamelCase		):
						'''simple docstring'''


						snake_case__							:       Optional[int]				      =       len(lowerCamelCase		)
						snake_case__							:       str				      =       graph_size * [False]
						snake_case__							:       List[str]				      =       []

						for i in range(lowerCamelCase		):
												if not visited[i]:
																		snake_case__							:       Dict				      =       dfs(lowerCamelCase   ,      lowerCamelCase   ,      lowerCamelCase		)
																		components_list.append(lowerCamelCase		)

						return components_list


if __name__ == "__main__":
							import doctest

							doctest.testmod()


