Fix tag set serialisation
@@ -292,10 +292,11 @@ cdef class Vocab:
**exclude: Named attributes to prevent from being serialized.
RETURNS (bytes): The serialized form of the `Vocab` object.
"""
- getters = {
- 'strings': lambda: self.strings.to_bytes(),
- 'lexemes': lambda: self.lexemes_to_bytes()
- }
+ getters = OrderedDict((
+ ('strings', lambda: self.strings.to_bytes()),
+ ('lexemes', lambda: self.lexemes_to_bytes()),
+ ('tag_map', lambda: self.morphology.tag_map),
+ ))
return util.to_bytes(getters, exclude)
def from_bytes(self, bytes_data, **exclude):
@@ -305,9 +306,13 @@ cdef class Vocab:
**exclude: Named attributes to prevent from being loaded.
RETURNS (Vocab): The `Vocab` object.
"""
+ def set_tag_map(tag_map):
+ self.morphology = Morphology(self.strings, tag_map,
+ self.morphology.lemmatizer)
setters = OrderedDict((
('strings', lambda b: self.strings.from_bytes(b)),
- ('lexemes', lambda b: self.lexemes_from_bytes(b))
+ ('lexemes', lambda b: self.lexemes_from_bytes(b)),
+ ('tag_map', lambda b: set_tag_map(b))
))
return util.from_bytes(bytes_data, setters, exclude)
