From 833eb35c57703b3a265febd57ebc2dfe1f1736b2 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 3 Nov 2015 18:45:54 +1100 Subject: [PATCH] * Fix tag assignment in doc.from_array --- spacy/morphology.pyx | 2 ++ spacy/tokens/doc.pyx | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spacy/morphology.pyx b/spacy/morphology.pyx index e8b1f3520..442aebd68 100644 --- a/spacy/morphology.pyx +++ b/spacy/morphology.pyx @@ -38,6 +38,8 @@ cdef class Morphology: tag_id = self.reverse_index[self.strings[tag]] else: tag_id = tag + if tag_id >= self.n_tags: + raise ValueError("Unknown tag: %s" % tag) analysis = self._cache.get(tag_id, token.lex.orth) if analysis is NULL: analysis = self.mem.alloc(1, sizeof(MorphAnalysisC)) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index 9c3387059..6b14d761c 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -398,7 +398,8 @@ cdef class Doc: self.is_parsed = True elif attr_id == TAG: for i in range(length): - self.vocab.morphology.assign_tag(&tokens[i], values[i]) + self.vocab.morphology.assign_tag(&tokens[i], + self.vocab.strings[values[i]]) if not self.is_tagged and tokens[i].tag != 0: self.is_tagged = True elif attr_id == POS: