From a1be01185cabdaf8f6858f629099190b3662b402 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 28 Feb 2018 12:27:09 +0100 Subject: [PATCH] Fix array out of bounds error in Span --- spacy/tokens/span.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index f794e1d3f..aa085b59f 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -294,6 +294,7 @@ cdef class Span: cdef int i if self.doc.is_parsed: root = &self.doc.c[self.start] + n = 0 while root.head != 0: root += root.head n += 1 @@ -307,8 +308,10 @@ cdef class Span: start += -1 # find end of the sentence end = self.end - while self.doc.c[end].sent_start != 1: + n = 0 + while end < self.doc.length and self.doc.c[end].sent_start != 1: end += 1 + n += 1 if n >= self.doc.length: break #