def deserialize(self, stream: Stream) -> bool: vers = 0 b = stream.readbyte() if (b == (0xAA)): b = (stream.readbyte()) vers = (b) else: stream.position = stream.position - (1) self.__m_sofa = SourceOfAnalysis(None) self.__m_sofa.deserialize(stream) self.base_language = MorphLang._new56( SerializerHelper.deserialize_int(stream)) self.__m_entities = list() cou = SerializerHelper.deserialize_int(stream) i = 0 while i < cou: typ = SerializerHelper.deserialize_string(stream) r = ProcessorService.create_referent(typ) if (r is None): r = Referent("UNDEFINED") self.__m_entities.append(r) i += 1 i = 0 while i < cou: self.__m_entities[i].deserialize(stream, self.__m_entities, self.__m_sofa) i += 1 self.first_token = SerializerHelper.deserialize_tokens( stream, self, vers) self.__create_statistics() return True
def __deserialize_item(self, stream: Stream) -> 'MorphBaseInfo': from pullenti.ner.core.internal.SerializerHelper import SerializerHelper ty = stream.readbyte() res = (MorphBaseInfo() if ty == 0 else MorphWordForm()) res.class0_ = MorphClass._new53( SerializerHelper.deserialize_short(stream)) res.case_ = MorphCase._new29( SerializerHelper.deserialize_short(stream)) res.gender = Utils.valToEnum( SerializerHelper.deserialize_short(stream), MorphGender) res.number = Utils.valToEnum( SerializerHelper.deserialize_short(stream), MorphNumber) res.language = MorphLang._new56( SerializerHelper.deserialize_short(stream)) if (ty == 0): return res wf = Utils.asObjectOrNull(res, MorphWordForm) wf.normal_case = SerializerHelper.deserialize_string(stream) wf.normal_full = SerializerHelper.deserialize_string(stream) wf.undef_coef = SerializerHelper.deserialize_short(stream) cou = SerializerHelper.deserialize_int(stream) i = 0 while i < cou: if (wf.misc is None): wf.misc = MorphMiscInfo() wf.misc.attrs.append(SerializerHelper.deserialize_string(stream)) i += 1 return res
def __init__(self, source: 'MorphCollection' = None) -> None: super().__init__() self.__m_class = MorphClass() self.__m_gender = MorphGender.UNDEFINED self.__m_number = MorphNumber.UNDEFINED self.__m_case = MorphCase() self.__m_language = MorphLang() self.__m_voice = MorphVoice.UNDEFINED self.__m_need_recalc = True self.__m_items = None if (source is None): return for it in source.items: mi = None if (isinstance(it, MorphWordForm)): wf = MorphWordForm() wf.copy_from_word_form(Utils.asObjectOrNull(it, MorphWordForm)) mi = (wf) else: mi = MorphBaseInfo() mi.copy_from(it) if (self.__m_items is None): self.__m_items = list() self.__m_items.append(mi) self.__m_class = MorphClass._new53(source.__m_class.value) self.__m_gender = source.__m_gender self.__m_case = MorphCase._new29(source.__m_case.value) self.__m_number = source.__m_number self.__m_language = MorphLang._new56(source.__m_language.value) self.__m_voice = source.__m_voice self.__m_need_recalc = False
def clone(self) -> 'MorphCollection': """ Создать копию """ res = MorphCollection() if (self.__m_items is not None): res.__m_items = list() try: res.__m_items.extend(self.__m_items) except Exception as ex: pass if (not self.__m_need_recalc): res.__m_class = MorphClass._new53(self.__m_class.value) res.__m_gender = self.__m_gender res.__m_case = MorphCase._new29(self.__m_case.value) res.__m_number = self.__m_number res.__m_language = MorphLang._new56(self.__m_language.value) res.__m_need_recalc = False res.__m_voice = self.__m_voice return res
def _deserialize(self, stream: Stream) -> None: from pullenti.ner.core.internal.SerializerHelper import SerializerHelper self.__m_class = MorphClass._new53( SerializerHelper.deserialize_short(stream)) self.__m_case = MorphCase._new29( SerializerHelper.deserialize_short(stream)) self.__m_gender = (Utils.valToEnum( SerializerHelper.deserialize_short(stream), MorphGender)) self.__m_number = (Utils.valToEnum( SerializerHelper.deserialize_short(stream), MorphNumber)) self.__m_voice = (Utils.valToEnum( SerializerHelper.deserialize_short(stream), MorphVoice)) self.__m_language = MorphLang._new56( SerializerHelper.deserialize_short(stream)) cou = SerializerHelper.deserialize_int(stream) self.__m_items = list() i = 0 while i < cou: it = self.__deserialize_item(stream) if (it is not None): self.__m_items.append(it) i += 1 self.__m_need_recalc = False