def _end_of_span(word):
    """Returns True if Word ends IOB2 or IOBES span, False otherwise."""
    if word.label == 'O':
        return False
    elif word.label[0] in 'ES':
        return True
    elif word.label[0] in 'BI':
        # Depends on the next word label for IOB2
        if word.next_word is None:
            return True
        elif word.next_word.label[0] in 'BSO':
            return True
        elif word.next_word.label[0] in 'IE':
            return False
        else:
            raise ValueError(word.next_word.label)
    else:
        raise ValueError(word.label)