def ProcessUtteranceForRepetitions(split_lines_of_utt):
    global non_scored_words, repetition_stats
    selected_line_indexes = []
    selected_edits = []
    selected_hyp_words = []
    for i in range(len(split_lines_of_utt)):
        split_line = split_lines_of_utt[i]
        hyp_word = split_line[4]
        ref_word = split_line[6]
        keep_this_line = True
        if (((hyp_word == '<eps>') or (hyp_word in non_scored_words)) and ((ref_word == '<eps>') or (ref_word in non_scored_words))):
            keep_this_line = False
        if keep_this_line:
            selected_line_indexes.append(i)
            edit_type = split_line[7]
            if ((edit_type == 'sub') and (ref_word in non_scored_words)):
                assert (not (hyp_word in non_scored_words))
                edit_type = 'ins'
            selected_edits.append(edit_type)
            selected_hyp_words.append(hyp_word)
    indexes_to_fix = []
    for i in range(0, (len(selected_line_indexes) - 3)):
        this_indexes = selected_line_indexes[i:(i + 4)]
        this_hyp_words = selected_hyp_words[i:(i + 4)]
        if ((this_hyp_words[0] == this_hyp_words[2]) and (this_hyp_words[1] == this_hyp_words[3]) and (this_hyp_words[0] != this_hyp_words[1])):
            this_edits = selected_edits[i:(i + 4)]
            if ((this_edits == ['cor', 'cor', 'ins', 'ins']) or (this_edits == ['ins', 'ins', 'cor', 'cor'])):
                if (this_edits[0] == 'cor'):
                    indexes_to_fix += [(i + 2), (i + 3)]
                else:
                    indexes_to_fix += [i, (i + 1)]
                selected_edits[i:(i + 4)] = [None, None, None, None]
                word_pair = ((this_hyp_words[0] + ' ') + this_hyp_words[1])
                repetition_stats[word_pair] += 2
                selected_edits[i:(i + 4)] = [None, None, None, None]
    for i in range(0, (len(selected_line_indexes) - 1)):
        this_indexes = selected_line_indexes[i:(i + 2)]
        this_hyp_words = selected_hyp_words[i:(i + 2)]
        if (this_hyp_words[0] == this_hyp_words[1]):
            this_edits = selected_edits[i:(i + 2)]
            if ((this_edits == ['cor', 'ins']) or (this_edits == ['ins', 'cor'])):
                if (this_edits[0] == 'cor'):
                    indexes_to_fix.append((i + 1))
                else:
                    indexes_to_fix.append(i)
                repetition_stats[this_hyp_words[0]] += 1
                selected_edits[i:(i + 2)] = [None, None]
    for i in indexes_to_fix:
        j = selected_line_indexes[i]
        split_line = split_lines_of_utt[j]
        ref_word = split_line[6]
        hyp_word = split_line[4]
        assert ((ref_word == '<eps>') or (ref_word in non_scored_words))
        split_line[6] = hyp_word
        split_line[7] = 'cor'
    return split_lines_of_utt
def ProcessUtteranceForRepetitions(split_lines_of_utt):
    global non_scored_words, repetition_stats
    selected_line_indexes = []
    selected_edits = []
    selected_hyp_words = []
    for i in range(len(split_lines_of_utt)):
        split_line = split_lines_of_utt[i]
        hyp_word = split_line[4]
        ref_word = split_line[6]
        keep_this_line = True
        if (((hyp_word == '<eps>') or (hyp_word in non_scored_words)) and ((ref_word == '<eps>') or (ref_word in non_scored_words))):
            keep_this_line = False
        if keep_this_line:
            selected_line_indexes.append(i)
            edit_type = split_line[7]
            if ((edit_type == 'sub') and (ref_word in non_scored_words)):
                assert (not (hyp_word in non_scored_words))
                edit_type = 'ins'
            selected_edits.append(edit_type)
            selected_hyp_words.append(hyp_word)
    indexes_to_fix = []
    for i in range(0, (len(selected_line_indexes) - 3)):
        this_indexes = selected_line_indexes[i:(i + 4)]
        this_hyp_words = selected_hyp_words[i:(i + 4)]
        if ((this_hyp_words[0] == this_hyp_words[2]) and (this_hyp_words[1] == this_hyp_words[3]) and (this_hyp_words[0] != this_hyp_words[1])):
            this_edits = selected_edits[i:(i + 4)]
            if ((this_edits == ['cor', 'cor', 'ins', 'ins']) or (this_edits == ['ins', 'ins', 'cor', 'cor'])):
                if (this_edits[0] == 'cor'):
                    indexes_to_fix += [(i + 2), (i + 3)]
                else:
                    indexes_to_fix += [i, (i + 1)]
                selected_edits[i:(i + 4)] = [None, None, None, None]
                word_pair = ((this_hyp_words[0] + ' ') + this_hyp_words[1])
                repetition_stats[word_pair] += 2
                selected_edits[i:(i + 4)] = [None, None, None, None]
    for i in range(0, (len(selected_line_indexes) - 1)):
        this_indexes = selected_line_indexes[i:(i + 2)]
        this_hyp_words = selected_hyp_words[i:(i + 2)]
        if (this_hyp_words[0] == this_hyp_words[1]):
            this_edits = selected_edits[i:(i + 2)]
            if ((this_edits == ['cor', 'ins']) or (this_edits == ['ins', 'cor'])):
                if (this_edits[0] == 'cor'):
                    indexes_to_fix.append((i + 1))
                else:
                    indexes_to_fix.append(i)
                repetition_stats[this_hyp_words[0]] += 1
                selected_edits[i:(i + 2)] = [None, None]
    for i in indexes_to_fix:
        j = selected_line_indexes[i]
        split_line = split_lines_of_utt[j]
        ref_word = split_line[6]
        hyp_word = split_line[4]
        assert ((ref_word == '<eps>') or (ref_word in non_scored_words))
        split_line[6] = hyp_word
        split_line[7] = 'cor'
    return split_lines_of_utt