diff --git a/spacy/attrs.pyx b/spacy/attrs.pyx index 8ce0f7a17..8d76160f4 100644 --- a/spacy/attrs.pyx +++ b/spacy/attrs.pyx @@ -1,4 +1,4 @@ -ATTR_IDS = { +IDS = { "NULL_ATTR": NULL_ATTR, "IS_ALPHA": IS_ALPHA, "IS_ASCII": IS_ASCII, @@ -87,4 +87,4 @@ ATTR_IDS = { } # ATTR IDs, in order of the symbol -ATTR_NAMES = [key for key, value in sorted(ATTR_IDS.items(), key=lambda item: item[1])] +NAMES = [key for key, value in sorted(IDS.items(), key=lambda item: item[1])] diff --git a/spacy/morphology.pyx b/spacy/morphology.pyx index 534f64a59..8d2a73608 100644 --- a/spacy/morphology.pyx +++ b/spacy/morphology.pyx @@ -6,7 +6,7 @@ try: except ImportError: import json -from .parts_of_speech import UNIV_POS_NAMES +from .parts_of_speech import IDS as POS_IDS from .parts_of_speech cimport ADJ, VERB, NOUN, PUNCT @@ -24,7 +24,7 @@ cdef class Morphology: self.rich_tags[i].id = i self.rich_tags[i].name = self.strings[tag_str] self.rich_tags[i].morph = 0 - self.rich_tags[i].pos = UNIV_POS_NAMES[props['pos'].upper()] + self.rich_tags[i].pos = POS_IDS[props['pos'].upper()] self.reverse_index[self.rich_tags[i].name] = i self._cache = PreshMapArray(self.n_tags) diff --git a/spacy/parts_of_speech.pyx b/spacy/parts_of_speech.pyx index 8c2348a47..57d9c801b 100644 --- a/spacy/parts_of_speech.pyx +++ b/spacy/parts_of_speech.pyx @@ -1,7 +1,7 @@ from __future__ import unicode_literals -UNIV_POS_NAMES = { +IDS = { "NO_TAG": NO_TAG, "ADJ": ADJ, "ADP": ADP, @@ -23,3 +23,6 @@ UNIV_POS_NAMES = { "EOL": EOL, "SPACE": SPACE } + + +NAMES = [key for key, value in sorted(IDS.items(), key=lambda item: item[1])] diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index eab6c044e..50b19d4c1 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -14,7 +14,6 @@ from ..typedefs cimport attr_t, flags_t from ..attrs cimport attr_id_t from ..attrs cimport ID, ORTH, NORM, LOWER, SHAPE, PREFIX, SUFFIX, LENGTH, CLUSTER from ..attrs cimport POS, LEMMA, TAG, DEP, HEAD, SPACY, ENT_IOB, ENT_TYPE -from ..parts_of_speech import UNIV_POS_NAMES from ..parts_of_speech cimport CONJ, PUNCT, NOUN from ..parts_of_speech cimport univ_pos_t from ..lexeme cimport Lexeme diff --git a/spacy/tokens/token.pyx b/spacy/tokens/token.pyx index 25db3f47e..af80b5359 100644 --- a/spacy/tokens/token.pyx +++ b/spacy/tokens/token.pyx @@ -9,7 +9,7 @@ import numpy from ..lexeme cimport Lexeme -from ..parts_of_speech import UNIV_POS_NAMES +from .. import parts_of_speech from ..attrs cimport LEMMA from ..attrs cimport ID, ORTH, NORM, LOWER, SHAPE, PREFIX, SUFFIX, LENGTH, CLUSTER @@ -318,7 +318,7 @@ cdef class Token: property pos_: def __get__(self): - return _pos_id_to_string[self.c.pos] + return parts_of_speech.NAMES[self.c.pos] property tag_: def __get__(self): @@ -363,6 +363,3 @@ cdef class Token: property like_email: def __get__(self): return Lexeme.c_check_flag(self.c.lex, LIKE_EMAIL) - - -_pos_id_to_string = {id_: string for string, id_ in UNIV_POS_NAMES.items()}