import json


def get_cat_to_name_mapping(file):
    """
    Read the json file provided and return a dictionary containing the mapping between categories and label names

    :param file: path to JSON file containing mapping between categories and label names
    :return cat_to_name: dictionary containing mapping between categories and label names
    """
    try:
        with open(file, 'r') as f:
            # Get mapping between categories and labels as dictionary
            cat_to_name = json.load(f)
    except Exception as e:
        print("WARN: {} could no be loaded as dictionary. Will return empty dictionary. Exception: {}".format(file, e))
        # Create empty dictionary
        cat_to_name = {}

    return cat_to_name