(spans)
Join spans that match the ABBREVIATIONS pattern.
Join spans that match the ABBREVIATIONS pattern.
Join spans that match the ABBREVIATIONS pattern .
def _abbreviation_joiner(spans):
    """Join spans that match the ABBREVIATIONS pattern."""
    segment = None
    makeSentence = lambda start, end: ''.join(spans[start:end])
    total = len(spans)

    for pos in range(total):
        if pos and pos % 2:  # even => segment, uneven => (potential) terminal
            prev_s = spans[pos - 1]
            marker = spans[pos]
            next_s = spans[pos+1] if pos + 1 < total else None

            if prev_s[-1:].isspace():
                pass # join
            elif marker[0] == '.' and ABBREVIATIONS.search(prev_s):
                pass # join
            elif marker[0] == '.' and next_s and (
                    LONE_WORD.match(next_s) or
                    (ENDS_IN_DATE_DIGITS.search(prev_s) and MONTH.match(next_s)) or
                    (MIDDLE_INITIAL_END.search(prev_s) and UPPER_WORD_START.match(next_s))
                    ):
                pass # join
            else:
                yield makeSentence(segment, pos + 1)
                segment = None
        elif segment is None:
            segment = pos

    if segment is not None:
        yield makeSentence(segment, total)
def _abbreviation_joiner ( spans ) : segment = None makeSentence = lambda start , end : '' . join ( spans [ start : end ] ) total = len ( spans ) for pos in range ( total ) : if pos and pos % 2 : # even => segment, uneven => (potential) terminal prev_s = spans [ pos - 1 ] marker = spans [ pos ] next_s = spans [ pos + 1 ] if pos + 1 < total else None if prev_s [ - 1 : ] . isspace ( ) : pass # join elif marker [ 0 ] == '.' and ABBREVIATIONS . search ( prev_s ) : pass # join elif marker [ 0 ] == '.' and next_s and ( LONE_WORD . match ( next_s ) or ( ENDS_IN_DATE_DIGITS . search ( prev_s ) and MONTH . match ( next_s ) ) or ( MIDDLE_INITIAL_END . search ( prev_s ) and UPPER_WORD_START . match ( next_s ) ) ) : pass # join else : yield makeSentence ( segment , pos + 1 ) segment = None elif segment is None : segment = pos if segment is not None : yield makeSentence ( segment , total )