From ee3e56f27b157af4a5281a4ea0d91ff92aa847e7 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 23 Jun 2015 04:35:08 +0200 Subject: [PATCH] * Fix bounds checking on entities --- spacy/syntax/stateclass.pyx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spacy/syntax/stateclass.pyx b/spacy/syntax/stateclass.pyx index f143ca087..cbcebac11 100644 --- a/spacy/syntax/stateclass.pyx +++ b/spacy/syntax/stateclass.pyx @@ -35,9 +35,9 @@ cdef class StateClass: cdef int E(self, int i) nogil: if self._e_i <= 0 or self._e_i >= self.length: - return -1 - if i <= 0 or i >= self.length: - return -1 + return 0 + if i < 0 or i >= self.length: + return 0 return self._ents[self._e_i-1].start cdef int L(self, int i, int idx) nogil: @@ -203,11 +203,10 @@ cdef class StateClass: self._sent[head].l_kids -= 1 cdef void open_ent(self, int label) nogil: - if 0 <= self._e_i < self.length: - self._ents[self._e_i].start = self.B(0) - self._ents[self._e_i].label = label - self._ents[self._e_i].end = -1 - self._e_i += 1 + self._ents[self._e_i].start = self.B(0) + self._ents[self._e_i].label = label + self._ents[self._e_i].end = -1 + self._e_i += 1 cdef void close_ent(self) nogil: self._ents[self._e_i-1].end = self.B(0)+1