From 75289b4761fa880b45f94c52c43e2f1da623e89d Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 13 Jun 2015 22:55:55 +0200 Subject: [PATCH] * Don't refuse to parse single token sentences, incase some transition system needs them, e.g. single word entity. Instead fix error in _init_state. --- spacy/syntax/parser.pyx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spacy/syntax/parser.pyx b/spacy/syntax/parser.pyx index 30d5b5f92..2a86c87f8 100644 --- a/spacy/syntax/parser.pyx +++ b/spacy/syntax/parser.pyx @@ -74,8 +74,6 @@ cdef class Parser: self.model = Model(self.moves.n_moves, templates, model_dir) def __call__(self, Tokens tokens): - if tokens.length == 0: - return 0 if self.cfg.get('beam_width', 1) < 1: self._greedy_parse(tokens) else: @@ -108,9 +106,9 @@ cdef class Parser: cdef int _beam_parse(self, Tokens tokens) except -1: cdef Beam beam = Beam(self.moves.n_moves, self.cfg.beam_width) + words = [w.orth_ for w in tokens] beam.initialize(_init_state, tokens.length, tokens.data) beam.check_done(_check_final_state, NULL) - words = [w.orth_ for w in tokens] while not beam.is_done: self._advance_beam(beam, None, False, words) state = beam.at(0) @@ -231,7 +229,7 @@ cdef int _transition_state(void* _dest, void* _src, class_t clas, void* _moves) cdef void* _init_state(Pool mem, int length, void* tokens) except NULL: cdef StateClass st = StateClass.init(tokens, length) - st.push() + st.fast_forward() Py_INCREF(st) return st