




'''simple docstring'''


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



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				Dict							):




     """simple docstring"""


     def remove_articles(UpperCamelCase__						:				Optional[Any]							):
          return re.sub(R"""\b(a|an|the)\b"""   ,						""" """   ,						UpperCamelCase__							)

     def white_space_fix(UpperCamelCase__						:				List[str]							):
          return " ".join(text.split()							)

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

     def lower(UpperCamelCase__						:				Optional[Any]							):
          return text.lower()

     return white_space_fix(remove_articles(remove_punc(lower(UpperCamelCase__							)							)							)							)



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				int   ,						UpperCamelCase__						:				Any							):




     """simple docstring"""


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



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				List[str]   ,						UpperCamelCase__						:				List[Any]							):




     """simple docstring"""


     return normalize_answer(UpperCamelCase__							) == normalize_answer(UpperCamelCase__							)



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				Dict   ,						UpperCamelCase__						:				Tuple   ,						UpperCamelCase__						:				str							):




     """simple docstring"""


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



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				Optional[int]   ,						UpperCamelCase__						:				Optional[int]							):




     """simple docstring"""


     a_    :       str    	=     0
     a_    :       str    	=     []
     for passage in dataset:
          for qa in passage["qas"]:
               total += 1
               if qa["id"] not in predictions:
                    a_    :       Dict    	=     F"Unanswered question {qa['id']} will receive score 0."
                    print(UpperCamelCase__   ,						file=sys.stderr							)
                    continue

               a_    :       Optional[Any]    	=     [x["""text"""] for x in qa["""answers"""]]
               a_    :       int    	=     predictions[qa["""id"""]]

               a_    :       str    	=     metric_max_over_ground_truths(UpperCamelCase__   ,						UpperCamelCase__   ,						UpperCamelCase__							)
               if int(_exact_match							) == 1:
                    correct_ids.append(qa["""id"""]							)
               exact_match += _exact_match

               fa += metric_max_over_ground_truths(UpperCamelCase__   ,						UpperCamelCase__   ,						UpperCamelCase__							)

     a_    :       Any    	=     exact_match / total
     a_    :       List[str]    	=     fa / total

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


if __name__ == "__main__":
 lowerCAmelCase_			:     str							    =     '1.0'
 lowerCAmelCase_			:     str							    =     argparse.ArgumentParser('Official evaluation script for ReCoRD v1.0.')
 parser.add_argument('data_file', help='The dataset file in JSON format.')
 parser.add_argument('pred_file', help='The model prediction file in JSON format.')
 parser.add_argument('--output_correct_ids', action='store_true', help='Output the correctly answered query IDs.')
 lowerCAmelCase_			:     List[Any]							    =     parser.parse_args()

 with open(args.data_file) as data_file:
  lowerCAmelCase_			:     Dict							    =     json.load(data_file)
  if dataset_json["version"] != expected_version:
   print(
       f"Evaluation expects v-{expected_version}, but got dataset with v-{dataset_json['version']}",
       file=sys.stderr,
   )
  lowerCAmelCase_			:     List[str]							    =     dataset_json['data']

 with open(args.pred_file) as pred_file:
  lowerCAmelCase_			:     Tuple							    =     json.load(pred_file)

 lowerCAmelCase_    ,      lowerCAmelCase_			:     Optional[int]							    =     evaluate(dataset, predictions)

 if args.output_correct_ids:
  print(f"Output {len(correct_ids)} correctly answered question IDs.")
  with open('correct_ids.json', 'w') as f:
   json.dump(correct_ids, f)






'''simple docstring'''


import shutil

import requests



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				str   ,						UpperCamelCase__						:				bool = False   ,						UpperCamelCase__						:				str = "."							):




     """simple docstring"""


     a_    :       Any    	=     """https://api.nasa.gov/planetary/apod"""
     return requests.get(UpperCamelCase__   ,						params={"""api_key""": api_key}							).json()



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				str   ,						UpperCamelCase__						:				str = "."							):




     """simple docstring"""


     a_    :       Tuple    	=     get_apod_data(UpperCamelCase__							)
     a_    :       Tuple    	=     apod_data["""url"""]
     a_    :       Any    	=     img_url.split("""/"""							)[-1]
     a_    :       Tuple    	=     requests.get(UpperCamelCase__   ,						stream=UpperCamelCase__							)

     with open(F"{path}/{img_name}"   ,						"""wb+"""							) as img_file:
          shutil.copyfileobj(response.raw   ,						UpperCamelCase__							)
     del response
     return apod_data



def    _SCREAMING_SNAKE_CASE    (			UpperCamelCase__						:				str							):




     """simple docstring"""


     a_    :       str    	=     """https://images-api.nasa.gov/search"""
     return requests.get(UpperCamelCase__   ,						params={"""q""": query}							).json()


if __name__ == "__main__":
 print(save_apod('YOUR API KEY'))
 lowerCAmelCase_			:     int							    =     get_archive_data('apollo 2011')['collection']['items']
 print(apollo_aaaa_items[0]['data'][0]['description'])
