* Check valency in L and R feature methods, to make feaure calculation faster

This commit is contained in:
Matthew Honnibal 2015-06-29 00:17:29 +02:00
parent f4986d5d3c
commit 5d870720bc
1 changed files with 5 additions and 1 deletions

View File

@ -52,6 +52,8 @@ cdef class StateClass:
if i < 0 or i >= self.length:
return -1
cdef const TokenC* target = &self._sent[i]
if target.l_kids < idx:
return -1
cdef const TokenC* ptr = self._sent
while ptr < target:
@ -75,8 +77,10 @@ cdef class StateClass:
return -1
if i < 0 or i >= self.length:
return -1
cdef const TokenC* ptr = self._sent + (self.length - 1)
cdef const TokenC* target = &self._sent[i]
if target.r_kids < idx:
return -1
cdef const TokenC* ptr = self._sent + (self.length - 1)
while ptr > target:
# If this head is still to the right of us, we can skip to it
# No token that's between this token and this head could be our