def GetSegmentsForUtterance(split_lines_of_utt):
    global num_utterances, num_utterances_without_segments, total_length_of_utterances
    num_utterances += 1
    segment_ranges = ComputeSegmentCores(split_lines_of_utt)
    utterance_end_time = (float(split_lines_of_utt[(- 1)][2]) + float(split_lines_of_utt[(- 1)][3]))
    total_length_of_utterances += utterance_end_time
    segments = [Segment(split_lines_of_utt, x[0], x[1]) for x in segment_ranges]
    AccumulateSegmentStats(segments, 'stage  0 [segment cores]')
    for segment in segments:
        segment.PossiblyAddTaintedLines()
    AccumulateSegmentStats(segments, 'stage  1 [add tainted lines]')
    new_segments = []
    for s in segments:
        new_segments += s.PossiblySplitSegment()
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage  2 [split segments]')
    for s in segments:
        s.PossiblyTruncateBoundaries()
    AccumulateSegmentStats(segments, 'stage  3 [truncate boundaries]')
    for s in segments:
        s.RelaxBoundaryTruncation()
    AccumulateSegmentStats(segments, 'stage  4 [relax boundary truncation]')
    for s in segments:
        s.PossiblyAddUnkPadding()
    AccumulateSegmentStats(segments, 'stage  5 [unk-padding]')
    deleted_segments = []
    new_segments = []
    for s in segments:
        if ((not s.IsWholeUtterance()) and (s.Length() < (0.999 * args.min_new_segment_length))):
            s.debug_str += '[deleted-because-of--min-new-segment-length]'
            deleted_segments.append(s)
        else:
            new_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage  6 [remove new segments under --min-new-segment-length')
    new_segments = []
    for s in segments:
        if (s.Length() < (0.999 * args.min_segment_length)):
            s.debug_str += '[deleted-because-of--min-segment-length]'
            deleted_segments.append(s)
        else:
            new_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage  7 [remove segments under --min-segment-length')
    for s in segments:
        s.PossiblyTruncateStartForJunkProportion()
    AccumulateSegmentStats(segments, 'stage  8 [truncate segment-starts for --max-junk-proportion')
    for s in segments:
        s.PossiblyTruncateEndForJunkProportion()
    AccumulateSegmentStats(segments, 'stage  9 [truncate segment-ends for --max-junk-proportion')
    new_segments = []
    for s in segments:
        if s.ContainsAtLeastOneScoredNonOovWord():
            new_segments.append(s)
        else:
            s.debug_str += '[deleted-because-no-scored-non-oov-words]'
            deleted_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage 10 [remove segments without scored,non-OOV words]')
    new_segments = []
    for s in segments:
        j = s.JunkProportion()
        if (j <= args.max_junk_proportion):
            new_segments.append(s)
        else:
            s.debug_str += '[deleted-because-junk-proportion={0}]'.format(j)
            deleted_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage 11 [remove segments with junk exceeding --max-junk-proportion]')
    new_segments = []
    if (len(segments) > 0):
        new_segments.append(segments[0])
        for i in range(1, len(segments)):
            if (new_segments[(- 1)].EndTime() >= segments[i].StartTime()):
                new_segments[(- 1)].MergeWithSegment(segments[i])
            else:
                new_segments.append(segments[i])
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage 12 [merge overlapping or touching segments]')
    for i in range((len(segments) - 1)):
        if (segments[i].EndTime() > segments[(i + 1)].StartTime()):
            segments[(i + 1)].debug_str += ',overlaps-previous-segment'
    if (len(segments) == 0):
        num_utterances_without_segments += 1
    return (segments, deleted_segments)
def GetSegmentsForUtterance(split_lines_of_utt):
    global num_utterances, num_utterances_without_segments, total_length_of_utterances
    num_utterances += 1
    segment_ranges = ComputeSegmentCores(split_lines_of_utt)
    utterance_end_time = (float(split_lines_of_utt[(- 1)][2]) + float(split_lines_of_utt[(- 1)][3]))
    total_length_of_utterances += utterance_end_time
    segments = [Segment(split_lines_of_utt, x[0], x[1]) for x in segment_ranges]
    AccumulateSegmentStats(segments, 'stage  0 [segment cores]')
    for segment in segments:
        segment.PossiblyAddTaintedLines()
    AccumulateSegmentStats(segments, 'stage  1 [add tainted lines]')
    new_segments = []
    for s in segments:
        new_segments += s.PossiblySplitSegment()
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage  2 [split segments]')
    for s in segments:
        s.PossiblyTruncateBoundaries()
    AccumulateSegmentStats(segments, 'stage  3 [truncate boundaries]')
    for s in segments:
        s.RelaxBoundaryTruncation()
    AccumulateSegmentStats(segments, 'stage  4 [relax boundary truncation]')
    for s in segments:
        s.PossiblyAddUnkPadding()
    AccumulateSegmentStats(segments, 'stage  5 [unk-padding]')
    deleted_segments = []
    new_segments = []
    for s in segments:
        if ((not s.IsWholeUtterance()) and (s.Length() < (0.999 * args.min_new_segment_length))):
            s.debug_str += '[deleted-because-of--min-new-segment-length]'
            deleted_segments.append(s)
        else:
            new_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage  6 [remove new segments under --min-new-segment-length')
    new_segments = []
    for s in segments:
        if (s.Length() < (0.999 * args.min_segment_length)):
            s.debug_str += '[deleted-because-of--min-segment-length]'
            deleted_segments.append(s)
        else:
            new_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage  7 [remove segments under --min-segment-length')
    for s in segments:
        s.PossiblyTruncateStartForJunkProportion()
    AccumulateSegmentStats(segments, 'stage  8 [truncate segment-starts for --max-junk-proportion')
    for s in segments:
        s.PossiblyTruncateEndForJunkProportion()
    AccumulateSegmentStats(segments, 'stage  9 [truncate segment-ends for --max-junk-proportion')
    new_segments = []
    for s in segments:
        if s.ContainsAtLeastOneScoredNonOovWord():
            new_segments.append(s)
        else:
            s.debug_str += '[deleted-because-no-scored-non-oov-words]'
            deleted_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage 10 [remove segments without scored,non-OOV words]')
    new_segments = []
    for s in segments:
        j = s.JunkProportion()
        if (j <= args.max_junk_proportion):
            new_segments.append(s)
        else:
            s.debug_str += '[deleted-because-junk-proportion={0}]'.format(j)
            deleted_segments.append(s)
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage 11 [remove segments with junk exceeding --max-junk-proportion]')
    new_segments = []
    if (len(segments) > 0):
        new_segments.append(segments[0])
        for i in range(1, len(segments)):
            if (new_segments[(- 1)].EndTime() >= segments[i].StartTime()):
                new_segments[(- 1)].MergeWithSegment(segments[i])
            else:
                new_segments.append(segments[i])
    segments = new_segments
    AccumulateSegmentStats(segments, 'stage 12 [merge overlapping or touching segments]')
    for i in range((len(segments) - 1)):
        if (segments[i].EndTime() > segments[(i + 1)].StartTime()):
            segments[(i + 1)].debug_str += ',overlaps-previous-segment'
    if (len(segments) == 0):
        num_utterances_without_segments += 1
    return (segments, deleted_segments)