mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
* Continue proxying. Some problem currently
This commit is contained in:
parent
2169bbb7ea
commit
7a0e3bb9c1
|
@ -56,11 +56,12 @@ cdef cppclass StateC:
|
|||
this._sent[i].lex = &EMPTY_LEXEME
|
||||
|
||||
__dealloc__():
|
||||
free(this._buffer)
|
||||
free(this._stack)
|
||||
free(this.shifted)
|
||||
free(this._sent)
|
||||
free(this._ents)
|
||||
cdef int PADDING = 5
|
||||
free(this._sent - PADDING)
|
||||
free(this._ents - PADDING)
|
||||
free(this._buffer - PADDING)
|
||||
free(this._stack - PADDING)
|
||||
free(this.shifted - PADDING)
|
||||
|
||||
int S(int i) nogil:
|
||||
if i >= this._s_i:
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
# test
|
|
@ -382,6 +382,9 @@ cdef class ArcEager(TransitionSystem):
|
|||
st._sent[i].sent_start = False
|
||||
st._sent[i].l_edge = i
|
||||
st._sent[i].r_edge = i
|
||||
st.c._sent[i].sent_start = False
|
||||
st.c._sent[i].l_edge = i
|
||||
st.c._sent[i].r_edge = i
|
||||
st.fast_forward()
|
||||
|
||||
cdef int finalize_state(self, StateClass st) nogil:
|
||||
|
@ -389,10 +392,12 @@ cdef class ArcEager(TransitionSystem):
|
|||
for i in range(st.length):
|
||||
if st._sent[i].head == 0 and st._sent[i].dep == 0:
|
||||
st._sent[i].dep = self.root_label
|
||||
st.c._sent[i].dep = self.root_label
|
||||
# If we're not using the Break transition, we segment via root-labelled
|
||||
# arcs between the root words.
|
||||
elif USE_ROOT_ARC_SEGMENT and st._sent[i].dep == self.root_label:
|
||||
st._sent[i].head = 0
|
||||
st.c._sent[i].head = 0
|
||||
|
||||
cdef int set_valid(self, int* output, StateClass stcls) nogil:
|
||||
cdef bint[N_MOVES] is_valid
|
||||
|
|
|
@ -204,7 +204,7 @@ cdef class StepwiseState:
|
|||
|
||||
@property
|
||||
def deps(self):
|
||||
return [self.doc.vocab.strings[self.stcls._sent[i].dep]
|
||||
return [self.doc.vocab.strings[self.stcls.c._sent[i].dep]
|
||||
for i in range(self.stcls.length)]
|
||||
|
||||
def predict(self):
|
||||
|
@ -235,7 +235,7 @@ cdef class StepwiseState:
|
|||
def finish(self):
|
||||
if self.stcls.is_final():
|
||||
self.parser.moves.finalize_state(self.stcls)
|
||||
self.doc.set_parse(self.stcls._sent)
|
||||
self.doc.set_parse(self.stcls.c._sent)
|
||||
|
||||
|
||||
cdef int _arg_max_clas(const weight_t* scores, int move, const Transition* actions,
|
||||
|
|
|
@ -81,7 +81,7 @@ cdef class StateClass:
|
|||
return &self._sent[i]
|
||||
|
||||
cdef inline int H(self, int i) nogil:
|
||||
self.c.H(i)
|
||||
return self.c.H(i)
|
||||
if i < 0 or i >= self.length:
|
||||
return -1
|
||||
return self._sent[i].head + i
|
||||
|
@ -109,7 +109,7 @@ cdef class StateClass:
|
|||
return self.stack_depth() <= 0 and self._b_i >= self.length
|
||||
|
||||
cdef inline bint has_head(self, int i) nogil:
|
||||
self.c.has_head(i)
|
||||
#return self.c.has_head(i)
|
||||
return self.safe_get(i).head != 0
|
||||
|
||||
cdef inline int n_L(self, int i) nogil:
|
||||
|
|
|
@ -38,6 +38,10 @@ cdef class StateClass:
|
|||
self._buffer[i] = i
|
||||
self._empty_token.lex = &EMPTY_LEXEME
|
||||
|
||||
|
||||
def __dealloc__(self):
|
||||
del self.c
|
||||
|
||||
@property
|
||||
def stack(self):
|
||||
return {self.S(i) for i in range(self._s_i)}
|
||||
|
@ -47,64 +51,13 @@ cdef class StateClass:
|
|||
return {self.B(i) for i in range(self._b_i)}
|
||||
|
||||
cdef int E(self, int i) nogil:
|
||||
self.c.E(i)
|
||||
if self._e_i <= 0 or self._e_i >= self.length:
|
||||
return 0
|
||||
if i < 0 or i >= self._e_i:
|
||||
return 0
|
||||
return self._ents[self._e_i - (i+1)].start
|
||||
return self.c.E(i)
|
||||
|
||||
cdef int L(self, int i, int idx) nogil:
|
||||
self.c.L(i, idx)
|
||||
if idx < 1:
|
||||
return -1
|
||||
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[target.l_edge]
|
||||
|
||||
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
|
||||
# child.
|
||||
if (ptr.head >= 1) and (ptr + ptr.head) < target:
|
||||
ptr += ptr.head
|
||||
|
||||
elif ptr + ptr.head == target:
|
||||
idx -= 1
|
||||
if idx == 0:
|
||||
return ptr - self._sent
|
||||
ptr += 1
|
||||
else:
|
||||
ptr += 1
|
||||
return -1
|
||||
return self.c.L(i, idx)
|
||||
|
||||
cdef int R(self, int i, int idx) nogil:
|
||||
self.c.R(i, idx)
|
||||
if idx < 1:
|
||||
return -1
|
||||
if i < 0 or i >= self.length:
|
||||
return -1
|
||||
cdef const TokenC* target = &self._sent[i]
|
||||
if target.r_kids < idx:
|
||||
return -1
|
||||
cdef const TokenC* ptr = &self._sent[target.r_edge]
|
||||
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
|
||||
# child.
|
||||
if (ptr.head < 0) and ((ptr + ptr.head) > target):
|
||||
ptr += ptr.head
|
||||
elif ptr + ptr.head == target:
|
||||
idx -= 1
|
||||
if idx == 0:
|
||||
return ptr - self._sent
|
||||
ptr -= 1
|
||||
else:
|
||||
ptr -= 1
|
||||
return -1
|
||||
return self.c.R(i, idx)
|
||||
|
||||
cdef void push(self) nogil:
|
||||
self.c.push()
|
||||
|
@ -204,6 +157,7 @@ cdef class StateClass:
|
|||
self._sent[i].ent_iob = ent_iob
|
||||
self._sent[i].ent_type = ent_type
|
||||
|
||||
|
||||
cdef void set_break(self, int _) nogil:
|
||||
self.c.set_break(_)
|
||||
if 0 <= self.B(0) < self.length:
|
||||
|
|
Loading…
Reference in New Issue
Block a user