import string


def merge_human_captions(data_split):
    """
    Merges all Human captions together, let the CATR caption separate.
    :param data_split:
    :return:
    """

    data_split_copy = data_split.copy()
    one_key = list(data_split_copy.keys())[0]
    num_captions = len(data_split_copy[one_key]["caption"])
    generated_caption_idx = num_captions - 1

    for path in data_split_copy.keys():
        human_captions = data_split_copy[path]["caption"][:generated_caption_idx]
        catr_caption = data_split_copy[path]["caption"][generated_caption_idx]
        glue = ". "
        if human_captions[0][-1] in string.punctuation:
            glue = " "
        human_captions = glue.join(human_captions)

        data_split_copy[path]["caption"] = [human_captions, catr_caption]

    return data_split_copy