From 312b3a45f3049af448ab4fe784cbc3aba9338681 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 10 Feb 2015 10:15:58 -0500 Subject: [PATCH] * Fix issue #19: Allow parsing/pos tagging of empty strings --- spacy/en/pos.pyx | 2 ++ spacy/syntax/parser.pyx | 3 +++ 2 files changed, 5 insertions(+) diff --git a/spacy/en/pos.pyx b/spacy/en/pos.pyx index fd6d468a9..5a19bbf27 100644 --- a/spacy/en/pos.pyx +++ b/spacy/en/pos.pyx @@ -265,6 +265,8 @@ cdef class EnPosTagger: Args: tokens (Tokens): The tokens to be tagged. """ + if tokens.length == 0: + return 0 cdef int i cdef atom_t[N_CONTEXT_FIELDS] context cdef const weight_t* scores diff --git a/spacy/syntax/parser.pyx b/spacy/syntax/parser.pyx index 33e4af179..061aee6df 100644 --- a/spacy/syntax/parser.pyx +++ b/spacy/syntax/parser.pyx @@ -72,6 +72,9 @@ cdef class GreedyParser: Transition guess uint64_t state_key + if tokens.length == 0: + return 0 + cdef atom_t[CONTEXT_SIZE] context cdef int n_feats cdef Pool mem = Pool()