From 51a297f93448df314612cf46d5a1946a6afb880b Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 25 Sep 2018 21:07:08 +0200 Subject: [PATCH] Fix morphology add and update --- spacy/morphology.pxd | 2 +- spacy/morphology.pyx | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spacy/morphology.pxd b/spacy/morphology.pxd index 589f500c2..bc8c44417 100644 --- a/spacy/morphology.pxd +++ b/spacy/morphology.pxd @@ -23,12 +23,12 @@ cdef class Morphology: cdef readonly PreshMapArray _cache cdef readonly int n_tags + cpdef update(self, hash_t morph, features) cdef hash_t insert(self, RichTagC tag) except 0 cdef int assign_untagged(self, TokenC* token) except -1 cdef int assign_tag(self, TokenC* token, tag) except -1 cdef int assign_tag_id(self, TokenC* token, int tag_id) except -1 - cpdef update_morph_key(self, hash_t morph, features) cdef int _assign_tag_from_exceptions(self, TokenC* token, int tag_id) except -1 diff --git a/spacy/morphology.pyx b/spacy/morphology.pyx index cc8cb1b19..6e45cab81 100644 --- a/spacy/morphology.pyx +++ b/spacy/morphology.pyx @@ -101,15 +101,14 @@ cdef class Morphology: cdef hash_t key = self.insert(tag) return key - cpdef update_morph_key(self, hash_t morph, features): + cpdef update(self, hash_t morph, features): """Update a morphological analysis with new feature values.""" tag = (self.tags.get(morph))[0] + features = intify_features(features) cdef univ_morph_t feature - cdef int value - for feature_, value in features.items(): - feature = self.strings.as_int(feature_) + for feature in features: set_feature(&tag, feature, 1) - morph = self.insert_tag(tag) + morph = self.insert(tag) return morph @@ -237,8 +236,9 @@ cdef hash_t hash_tag(RichTagC tag) nogil: cdef RichTagC create_rich_tag(features): cdef RichTagC tag cdef univ_morph_t feature - #for feature in features: - # set_feature(&tag, feature, 1) + memset(&tag, 0, sizeof(tag)) + for feature in features: + set_feature(&tag, feature, 1) return tag cdef tag_to_json(RichTagC tag):