From 5ede7cec9b45a6edf873fbb442369b503592237e Mon Sep 17 00:00:00 2001 From: Explosion Bot Date: Mon, 30 Oct 2017 11:49:11 +0100 Subject: [PATCH] Improve Lexeme.set_attrs method --- spacy/lexeme.pyx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spacy/lexeme.pyx b/spacy/lexeme.pyx index 88748af33..a64e394c3 100644 --- a/spacy/lexeme.pyx +++ b/spacy/lexeme.pyx @@ -13,6 +13,8 @@ from .typedefs cimport attr_t, flags_t from .attrs cimport IS_ALPHA, IS_ASCII, IS_DIGIT, IS_LOWER, IS_PUNCT, IS_SPACE from .attrs cimport IS_TITLE, IS_UPPER, LIKE_URL, LIKE_NUM, LIKE_EMAIL, IS_STOP from .attrs cimport IS_BRACKET, IS_QUOTE, IS_LEFT_PUNCT, IS_RIGHT_PUNCT, IS_OOV +from .attrs cimport PROB +from .attrs import intify_attrs from . import about @@ -68,6 +70,17 @@ cdef class Lexeme: def __hash__(self): return self.c.orth + def set_attrs(self, **attrs): + cdef attr_id_t attr + attrs = intify_attrs(attrs) + for attr, value in attrs.items(): + if attr == PROB: + self.c.prob = value + elif isinstance(value, int) or isinstance(value, long): + Lexeme.set_struct_attr(self.c, attr, value) + else: + Lexeme.set_struct_attr(self.c, attr, self.vocab.strings.add(value)) + def set_flag(self, attr_id_t flag_id, bint value): """Change the value of a boolean flag.