コード例 #1
0
def trim_sentence_with_skeleton(text, skeleton_counter=0):
    """
    Given a text removes leading and trailing spaces from the text.
    Adds them to the skeleton
    and returns the new text. Also returns the new text positions.
    """
    intervals, intervals_types = trim_text(text)
    skeleton = u''
    new_text = u""
    new_intervals = []
    for part, part_type in izip(intervals, intervals_types):
        part_text = text[part[0]:part[1]]
        if part_type == 1:
            new_text += part_text
            skeleton += u"{%i}" % skeleton_counter
            new_intervals.append(part)
        else:
            skeleton += part_text
    return new_text, skeleton, new_intervals