def ne_results_2_labels(ne_results):
    """
    helper function to transform a list of substrings and labels
    into a list of labels for every (white space separated) token
    """
    l_list = []
    last_l = ''
    for i, (substr, l) in enumerate(ne_results):
        if substr == ' ':
            continue
        if not l or l == 'O':
            l_out = 'O'
        elif l == last_l:
            l_out = "B-" + l
        else:
            l_out = "I-" + l
        last_l = l
        if (not i) or (substr.startswith(' ') or ne_results[i - 1][0].endswith(' ')):
            l_list.append(l_out)
        # if there is no space between the previous and last substring, first token gets label
        # of longer subsubstr (i.e. either previous or current)
        elif i and len(ne_results[i - 1][0].split()[-1]) < len(substr.split()[0]):
            l_list.pop()
            l_list.append(l_out)
        l_list.extend([l_out for n in range(len(substr.split()) - 1)])
    return l_list