def load_item_file()

in eval/ABX_src/abx_iterators.py [0:0]


def load_item_file(path_item_file):
    r""" Load a .item file indicating the triplets for the ABX score. The
    input file must have the following fomat:
    line 0 : whatever (not read)
    line > 0: #file_ID onset offset #phone prev-phone next-phone speaker
    onset : begining of the triplet (in s)
    onset : end of the triplet (in s)
    """
    with open(path_item_file, 'r') as file:
        data = file.readlines()[1:]

    data = [x.replace('\n', '') for x in data]

    out = {}

    phone_match = {}
    speaker_match = {}
    context_match = {}

    for line in data:
        items = line.split()
        assert(len(items) == 7)
        fileID = items[0]
        if fileID not in out:
            out[fileID] = []

        onset, offset = float(items[1]), float(items[2])
        context = '+'.join([items[4], items[5]])
        phone = items[3]
        speaker = items[6]

        if phone not in phone_match:
            s = len(phone_match)
            phone_match[phone] = s
        phone_id = phone_match[phone]

        if context not in context_match:
            s = len(context_match)
            context_match[context] = s
        context_id = context_match[context]

        if speaker not in speaker_match:
            s = len(speaker_match)
            speaker_match[speaker] = s
        speaker_id = speaker_match[speaker]

        out[fileID].append([onset, offset, context_id, phone_id, speaker_id])

    return out, context_match, phone_match, speaker_match