Add set_struct_attr staticmethod to token

This commit is contained in:
Matthew Honnibal 2016-11-25 12:41:47 +01:00
parent fb69aa648f
commit 87613edf8f
1 changed files with 21 additions and 0 deletions

View File

@ -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 = <univ_pos_t>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