import re


def stringify_segments(sent_dict_list, segment_type):
    """
    Converts a list of sentences (Doc objects) into strings based on their segment number, to pass to a model.
    :param sent_dict_list: The dictionary list containing the list of sentences.
    :param segment_type: The type of segment to convert (temporal_segment or non_temporal_segment)
    :return: A list of strings: one string per segment.
    """
    max_segment = max(item[segment_type] for item in sent_dict_list)
    segments = []
    for counter in range(max_segment + 1):
        sentence_list = [item['original_sentence'].text for item in sent_dict_list
                         if item[segment_type] == counter]
        segment = '. '.join(sentence_list)
        re.sub('\\s\\s+?', ' ', segment)
        if len(segment) != 0:
            segments.append(segment)
    return segments