import json


def get_counts_from_json(year):
    """ Reads a json file containing total phrase and doc freqs for each year and returns the total
    no. of phrases in the year in the arguments, and the total no. of documents in the year.""" 
    # Read the Json file which has the monthly total phrases and documents -- 2 Json objects in a 
    # json array. Assign each object to a dictionary.
    with open('phrase_urls_and_docs_yearly.json', 'r') as file:
        json_array = json.load(file)
    # json_array is a list of 2 dicts (1st -> phrase freq, 2nd -> doc_freq).
    yearly_phrases_total = json_array[0]
    yearly_docs_total = json_array[1]
    # Get the 2 frequencies for the current year from the 2 dictionaries.
    current_year_phrases_freq = yearly_phrases_total.get(year)
    current_year_docs_freq = yearly_docs_total.get(year)
    return current_year_phrases_freq, current_year_docs_freq