Test and fix Issue #411: IndexError when .sents property is used on empty string.

This commit is contained in:
Matthew Honnibal 2016-09-27 18:49:14 +02:00
parent 3d370b7d45
commit fc4a7ad794
2 changed files with 8 additions and 2 deletions

View File

@ -164,6 +164,12 @@ def test_merge_hang():
doc.merge(8, 32, '', '', 'ORG')
def test_sents_empty_string(EN):
doc = EN(u'')
sents = list(doc.sents)
assert len(sents) == 0
@pytest.mark.models
def test_runtime_error(EN):
# Example that caused run-time error while parsing Reddit
@ -199,4 +205,3 @@ def test_right_edge(EN):
def test_has_vector(EN):
doc = EN(u'''apple orange pear''')
assert doc.has_vector

View File

@ -299,6 +299,7 @@ cdef class Doc:
if self.c[i].sent_start:
yield Span(self, start, i)
start = i
if start != self.length:
yield Span(self, start, self.length)
cdef int push_back(self, LexemeOrToken lex_or_tok, bint has_space) except -1: