From 3af938365faae661867dad0a1991e7d9d0eb770f Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 8 Aug 2015 23:32:15 +0200 Subject: [PATCH] * Add function partial to Parser --- spacy/syntax/parser.pyx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/spacy/syntax/parser.pyx b/spacy/syntax/parser.pyx index 69d70ad03..a45f17339 100644 --- a/spacy/syntax/parser.pyx +++ b/spacy/syntax/parser.pyx @@ -88,6 +88,22 @@ cdef class Parser: self.parse(stcls, eg.c) 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: while not stcls.is_final(): memset(eg.scores, 0, eg.nr_class * sizeof(weight_t)) @@ -109,9 +125,9 @@ cdef class Parser: cdef Transition G while not stcls.is_final(): memset(eg.c.scores, 0, eg.c.nr_class * sizeof(weight_t)) - + self.moves.set_costs(eg.c.is_valid, eg.c.costs, stcls, gold) - + fill_context(eg.c.atoms, stcls) self.model.train(eg)