From 87613edf8fe802e97861b1722c23c08f597c6fcd Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 25 Nov 2016 12:41:47 +0100 Subject: [PATCH] Add set_struct_attr staticmethod to token --- spacy/tokens/token.pxd | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spacy/tokens/token.pxd b/spacy/tokens/token.pxd index 5f32f176b..f63a0490c 100644 --- a/spacy/tokens/token.pxd +++ b/spacy/tokens/token.pxd @@ -3,6 +3,7 @@ from ..vocab cimport Vocab from ..structs cimport TokenC from ..attrs cimport * from ..typedefs cimport attr_t, flags_t +from ..parts_of_speech cimport univ_pos_t from .doc cimport Doc from ..lexeme cimport Lexeme @@ -52,3 +53,23 @@ cdef class Token: return token.ent_type else: return Lexeme.get_struct_attr(token.lex, feat_name) + + @staticmethod + cdef inline attr_t set_struct_attr(TokenC* token, attr_id_t feat_name, + attr_t value) nogil: + if feat_name == LEMMA: + token.lemma = value + elif feat_name == POS: + token.pos = value + elif feat_name == TAG: + token.tag = value + elif feat_name == DEP: + token.dep = value + elif feat_name == HEAD: + token.head = value + elif feat_name == SPACY: + token.spacy = value + elif feat_name == ENT_IOB: + token.ent_iob = value + elif feat_name == ENT_TYPE: + token.ent_type = value