import json


def _load_annotations(annotations_jsonpath):
    """Build an index out of FOIL annotations, mapping each image ID with its corresponding captions."""

    annotations_json = json.load(open(annotations_jsonpath))

    # Build an index which maps image id with a list of caption annotations.
    entries = []

    for annotation in annotations_json["annotations"]:
        entries.append(
            {
                "caption": annotation["caption"].lower(),
                "foil": annotation["foil"],
                "image_id": annotation["image_id"],
            }
        )

    return entries