def deserialize(self, str0 : Stream, ignore_rev_tree : bool, lazy_load : bool) -> None: tmp = MemoryStream() MorphDeserializer.deflate_gzip(str0, tmp) arr = tmp.toarray() buf = ByteArrayWrapper(arr) pos = 0 wrappos23 = RefOutArgWrapper(pos) cou = buf.deserialize_int(wrappos23) pos = wrappos23.value while cou > 0: mi = MorphMiscInfo() wrappos15 = RefOutArgWrapper(pos) mi._deserialize(buf, wrappos15) pos = wrappos15.value self.add_misc_info(mi) cou -= 1 wrappos22 = RefOutArgWrapper(pos) cou = buf.deserialize_int(wrappos22) pos = wrappos22.value while cou > 0: wrappos17 = RefOutArgWrapper(pos) p1 = buf.deserialize_int(wrappos17) pos = wrappos17.value r = MorphRule() if (lazy_load): r.lazy_pos = pos pos = p1 else: wrappos16 = RefOutArgWrapper(pos) r._deserialize(buf, wrappos16) pos = wrappos16.value self.add_rule(r) cou -= 1 root = MorphTreeNode() if (lazy_load): wrappos18 = RefOutArgWrapper(pos) root._deserialize_lazy(buf, self, wrappos18) pos = wrappos18.value else: wrappos19 = RefOutArgWrapper(pos) root._deserialize(buf, wrappos19) pos = wrappos19.value self.m_root = root if (not ignore_rev_tree): root_rev = MorphTreeNode() if (lazy_load): wrappos20 = RefOutArgWrapper(pos) root_rev._deserialize_lazy(buf, self, wrappos20) pos = wrappos20.value else: wrappos21 = RefOutArgWrapper(pos) root_rev._deserialize(buf, wrappos21) pos = wrappos21.value self.m_root_reverce = root_rev tmp.close() if (lazy_load): self.__m_lazy_buf = buf
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 verb_morph(self) -> 'MorphWordForm': """ Полное морф.информация (для глагола) """ if (self.__m_verb_morph is not None): return self.__m_verb_morph for f in self.morph.items: if (f.class0_.is_verb and (isinstance(f, MorphWordForm)) and ((f.misc.person) & (MorphPerson.THIRD)) != (MorphPerson.UNDEFINED)): if (f.normal_case.endswith("СЯ")): return Utils.asObjectOrNull(f, MorphWordForm) for f in self.morph.items: if (f.class0_.is_verb and (isinstance(f, MorphWordForm)) and ((f.misc.person) & (MorphPerson.THIRD)) != (MorphPerson.UNDEFINED)): return Utils.asObjectOrNull(f, MorphWordForm) for f in self.morph.items: if (f.class0_.is_verb and (isinstance(f, MorphWordForm))): return Utils.asObjectOrNull(f, MorphWordForm) for f in self.morph.items: if (f.class0_.is_adjective and (isinstance(f, MorphWordForm))): return Utils.asObjectOrNull(f, MorphWordForm) if (self.__m_normal == "НЕТ"): return MorphWordForm._new605(MorphClass.VERB, MorphMiscInfo()) return None
def deserializeAll(str0: io.IOBase, me: 'MorphEngine', ignore_rev_tree: bool, lazy_load: bool) -> 'ByteArrayWrapper': tmp = io.BytesIO() MorphSerializeHelper.deflateGzip(str0, tmp) buf = ByteArrayWrapper(bytearray(tmp.getvalue())) me._m_vars.clear() me.m_rules.clear() me.m_root = MorphTreeNode() me.m_root_reverce = MorphTreeNode() cou = buf.deserializeInt() while cou > 0: mi = MorphMiscInfo() MorphSerializeHelper.__deserializeMorphMiscInfo(buf, mi) me._m_vars.append(mi) cou -= 1 cou = buf.deserializeInt() while cou > 0: p1 = buf.deserializeInt() r = MorphRule() if (lazy_load): r.lazy_pos = buf.position buf.seek(p1) else: MorphSerializeHelper.__deserializeMorphRule(buf, r, me) me.m_rules.append(r) cou -= 1 if (lazy_load): MorphSerializeHelper._deserializeMorphTreeNodeLazy( buf, me.m_root, me) else: MorphSerializeHelper.__deserializeMorphTreeNode(buf, me.m_root, me) if (not ignore_rev_tree): if (lazy_load): MorphSerializeHelper._deserializeMorphTreeNodeLazy( buf, me.m_root_reverce, me) else: MorphSerializeHelper.__deserializeMorphTreeNode( buf, me.m_root_reverce, me) tmp.close() return buf
def deserialize_all(str0: io.IOBase, me: 'MorphEngine', ignore_rev_tree: bool, lazy_load: bool) -> 'ByteArrayWrapper': tmp = io.BytesIO() MorphSerializeHelper.deflate_gzip(str0, tmp) buf = ByteArrayWrapper(bytearray(tmp.getvalue())) me._m_vars.clear() me.m_rules.clear() me.m_root = MorphTreeNode() me.m_root_reverce = MorphTreeNode() pos = 0 wrappos50 = RefOutArgWrapper(pos) cou = buf.deserialize_int(wrappos50) pos = wrappos50.value while cou > 0: mi = MorphMiscInfo() wrappos42 = RefOutArgWrapper(pos) MorphSerializeHelper.__deserialize_morph_misc_info( buf, mi, wrappos42) pos = wrappos42.value me._m_vars.append(mi) cou -= 1 wrappos49 = RefOutArgWrapper(pos) cou = buf.deserialize_int(wrappos49) pos = wrappos49.value while cou > 0: wrappos44 = RefOutArgWrapper(pos) p1 = buf.deserialize_int(wrappos44) pos = wrappos44.value r = MorphRule() if (lazy_load): r.lazy_pos = pos pos = p1 else: wrappos43 = RefOutArgWrapper(pos) MorphSerializeHelper.__deserialize_morph_rule( buf, r, me, wrappos43) pos = wrappos43.value me.m_rules.append(r) cou -= 1 if (lazy_load): wrappos45 = RefOutArgWrapper(pos) MorphSerializeHelper._deserialize_morph_tree_node_lazy( buf, me.m_root, me, wrappos45) pos = wrappos45.value else: wrappos46 = RefOutArgWrapper(pos) MorphSerializeHelper.__deserialize_morph_tree_node( buf, me.m_root, me, wrappos46) pos = wrappos46.value if (not ignore_rev_tree): if (lazy_load): wrappos47 = RefOutArgWrapper(pos) MorphSerializeHelper._deserialize_morph_tree_node_lazy( buf, me.m_root_reverce, me, wrappos47) pos = wrappos47.value else: wrappos48 = RefOutArgWrapper(pos) MorphSerializeHelper.__deserialize_morph_tree_node( buf, me.m_root_reverce, me, wrappos48) pos = wrappos48.value tmp.close() return buf
def _static_ctor(): Morphology.__m_inner = InnerMorphology() Morphology.__m_empty_word_forms = list() Morphology.__m_empty_misc = MorphMiscInfo()
def _static_ctor(): MorphologyService.__m_empty_word_forms = list() MorphologyService.__m_empty_misc = MorphMiscInfo() MorphologyService.__m_morph = InnerMorphology()