From 5d870720bcb8fddda4153e8c27cce0b14b5791d6 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 29 Jun 2015 00:17:29 +0200 Subject: [PATCH] * Check valency in L and R feature methods, to make feaure calculation faster --- spacy/syntax/stateclass.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spacy/syntax/stateclass.pyx b/spacy/syntax/stateclass.pyx index 0112a89f5..0708a00cf 100644 --- a/spacy/syntax/stateclass.pyx +++ b/spacy/syntax/stateclass.pyx @@ -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