mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-06 06:03:11 +03:00
* Add function partial to Parser
This commit is contained in:
parent
76a1f0481a
commit
3af938365f
|
@ -88,6 +88,22 @@ cdef class Parser:
|
||||||
self.parse(stcls, eg.c)
|
self.parse(stcls, eg.c)
|
||||||
tokens.set_parse(stcls._sent)
|
tokens.set_parse(stcls._sent)
|
||||||
|
|
||||||
|
def partial(self, Doc tokens, initial_actions):
|
||||||
|
cdef StateClass stcls = StateClass.init(tokens.data, tokens.length)
|
||||||
|
self.moves.initialize_state(stcls)
|
||||||
|
cdef object action_name
|
||||||
|
cdef Transition action
|
||||||
|
for action_name in initial_actions:
|
||||||
|
action = self.moves.lookup_transition(action_name)
|
||||||
|
action.do(stcls, action.label)
|
||||||
|
|
||||||
|
cdef Example eg = Example(self.model.n_classes, CONTEXT_SIZE,
|
||||||
|
self.model.n_feats, self.model.n_feats)
|
||||||
|
with nogil:
|
||||||
|
self.parse(stcls, eg.c)
|
||||||
|
tokens.set_parse(stcls._sent)
|
||||||
|
return stcls
|
||||||
|
|
||||||
cdef void parse(self, StateClass stcls, ExampleC eg) nogil:
|
cdef void parse(self, StateClass stcls, ExampleC eg) nogil:
|
||||||
while not stcls.is_final():
|
while not stcls.is_final():
|
||||||
memset(eg.scores, 0, eg.nr_class * sizeof(weight_t))
|
memset(eg.scores, 0, eg.nr_class * sizeof(weight_t))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user