def __tryParse(t: 'Token') -> 'AutoannoSentToken': if (t is None or not MiscHelper.canBeStartOfSentence(t)): return None res = AutoannoSentToken(t, t) has_verb = False while t is not None: if (MiscHelper.canBeStartOfSentence(t) and t != res.begin_token): break r = t.getReferent() if (isinstance(r, KeywordReferent)): res.rank += (r).rank if ((r).typ == KeywordType.PREDICATE): has_verb = True elif (isinstance(t, TextToken)): mc = t.getMorphClassInDictionary() if (mc.is_pronoun or mc.is_personal_pronoun): res.rank -= (1) elif (t.length_char > 1): res.rank -= .1 res.end_token = t t = t.next0_ if (not has_verb): res.rank /= (3) res.value = MiscHelper.getTextValueOfMetaToken( res, Utils.valToEnum( (GetTextAttr.KEEPREGISTER) | (GetTextAttr.KEEPQUOTES), GetTextAttr)) return res
def try_parse(t : 'Token', prev : 'WeaponItemToken', after_conj : bool, attach_high : bool=False) -> 'WeaponItemToken': res = WeaponItemToken.__try_parse(t, prev, after_conj, attach_high) if (res is None): npt = NounPhraseHelper.try_parse(t, NounPhraseParseAttr.NO, 0, None) if (npt is not None and npt.noun.begin_char > npt.begin_char): res = WeaponItemToken.__try_parse(npt.noun.begin_token, prev, after_conj, attach_high) if (res is not None): if (res.typ == WeaponItemToken.Typs.NOUN): str0_ = npt.get_normal_case_text(None, MorphNumber.SINGULAR, MorphGender.UNDEFINED, False) if (str0_ == "РУЧНОЙ ГРАНАТ"): str0_ = "РУЧНАЯ ГРАНАТА" if ((Utils.ifNotNull(str0_, "")).endswith(res.value)): if (res.alt_value is None): res.alt_value = str0_ else: str0_ = str0_[0:0+len(str0_) - len(res.value)].strip() res.alt_value = "{0} {1}".format(str0_, res.alt_value) res.begin_token = t return res return None if (res.typ == WeaponItemToken.Typs.NAME): br = BracketHelper.try_parse(res.end_token.next0_, BracketParseAttr.NO, 100) if (br is not None and br.is_char('(')): alt = MiscHelper.get_text_value_of_meta_token(br, GetTextAttr.NO) if (MiscHelper.can_be_equal_cyr_and_latss(res.value, alt)): res.alt_value = alt res.end_token = br.end_token return res
def __try_parse(t: 'Token') -> 'AutoannoSentToken': if (t is None or not MiscHelper.can_be_start_of_sentence(t)): return None res = AutoannoSentToken(t, t) has_verb = False while t is not None: if (MiscHelper.can_be_start_of_sentence(t) and t != res.begin_token): break r = t.get_referent() if (isinstance(r, KeywordReferent)): res.rank += r.rank if (r.typ == KeywordType.PREDICATE): has_verb = True elif (isinstance(t, TextToken)): mc = t.get_morph_class_in_dictionary() if (mc.is_pronoun or mc.is_personal_pronoun): res.rank -= (1) elif (t.length_char > 1): res.rank -= 0.1 res.end_token = t t = t.next0_ if (not has_verb): res.rank /= (3) res.value = MiscHelper.get_text_value_of_meta_token( res, Utils.valToEnum( (GetTextAttr.KEEPREGISTER) | (GetTextAttr.KEEPQUOTES), GetTextAttr)) return res
def __toShortString(self, lang : 'MorphLang') -> str: id0_ = None for a in self.slots: if (a.type_name == PersonReferent.ATTR_IDENTITY): s = str(a.value) if (id0_ is None or (len(s) < len(id0_))): id0_ = s if (id0_ is not None): return MiscHelper.convertFirstCharUpperAndOtherLower(id0_) n = self.getStringValue(PersonReferent.ATTR_LASTNAME) if (n is not None): res = io.StringIO() print(n, end="", file=res) s = self.__findForSurname(PersonReferent.ATTR_FIRSTNAME, n, True) if (s is not None): print(" {0}.".format(s[0]), end="", file=res, flush=True) s = self.__findForSurname(PersonReferent.ATTR_MIDDLENAME, n, False) if (s is not None): print("{0}.".format(s[0]), end="", file=res, flush=True) return MiscHelper.convertFirstCharUpperAndOtherLower(Utils.toStringStringIO(res)) tit = self.__findShortestKingTitul(True) if (tit is not None): nam = self.getStringValue(PersonReferent.ATTR_FIRSTNAME) if (nam is not None): return MiscHelper.convertFirstCharUpperAndOtherLower("{0} {1}".format(tit, nam)) return self.__toFullString(False, lang)
def to_string(self, short_variant: bool, lang: 'MorphLang' = None, lev: int = 0) -> str: if (short_variant): return self.__to_short_string(lang) else: res = self.__to_full_string( PersonReferent.SHOW_LASTNAME_ON_FIRST_POSITION, lang) if (self.find_slot(PersonReferent.ATTR_NICKNAME, None, True) is None): return res niks = self.get_string_values(PersonReferent.ATTR_NICKNAME) if (len(niks) == 1): return "{0} ({1})".format( res, MiscHelper.convert_first_char_upper_and_other_lower( niks[0])) tmp = io.StringIO() print(res, end="", file=tmp) print(" (", end="", file=tmp) for s in niks: if (s != niks[0]): print(", ", end="", file=tmp) print(MiscHelper.convert_first_char_upper_and_other_lower(s), end="", file=tmp) print(")", end="", file=tmp) return Utils.toStringStringIO(tmp)
def __compare_surnames_strs(self, s1: str, s2: str) -> bool: # Сравнение с учётом возможных окончаний if (s1.startswith(s2) or s2.startswith(s1)): return True if (PersonReferent._del_surname_end(s1) == PersonReferent._del_surname_end(s2)): return True n1 = MiscHelper.get_absolute_normal_value(s1, False) if (n1 is not None): if (n1 == MiscHelper.get_absolute_normal_value(s2, False)): return True if (MiscHelper.can_be_equals(s1, s2, True, True, False)): return True return False
def __checkNames(self, attr_name : str, p : 'PersonReferent') -> bool: names1 = list() inits1 = list() normn1 = list() for s in self.slots: if (s.type_name == attr_name): n = str(s.value) if (PersonReferent.__isInitial(n)): inits1.append(n) else: names1.append(n) sn = MiscHelper.getAbsoluteNormalValue(n, False) if (sn is not None): normn1.append(sn) names2 = list() inits2 = list() normn2 = list() for s in p.slots: if (s.type_name == attr_name): n = str(s.value) if (PersonReferent.__isInitial(n)): inits2.append(n) else: names2.append(n) sn = MiscHelper.getAbsoluteNormalValue(n, False) if (sn is not None): normn2.append(sn) if (len(names1) > 0 and len(names2) > 0): for n in names1: if (n in names2): return True for n in normn1: if (n in normn2): return True return False if (len(inits1) > 0): for n in inits1: if (n in inits2): return True for nn in names2: if (nn.startswith(n)): return True if (len(inits2) > 0): for n in inits2: if (n in inits1): return True for nn in names1: if (nn.startswith(n)): return True return False
def tryParse(t: 'Token', prev: 'TransItemToken', after_conj: bool, attach_high: bool = False) -> 'TransItemToken': res = TransItemToken.__TryParse(t, prev, after_conj, attach_high) if (res is None): return None if (res.typ == TransItemToken.Typs.NAME): br = BracketHelper.tryParse(res.end_token.next0_, BracketParseAttr.NO, 100) if (br is not None and br.begin_token.isChar('(')): alt = MiscHelper.getTextValueOfMetaToken(br, GetTextAttr.NO) if (MiscHelper.canBeEqualCyrAndLatSS(res.value, alt)): res.alt_value = alt res.end_token = br.end_token return res
def to_string(self, short_variant: bool, lang: 'MorphLang', lev: int = 0) -> str: res = io.StringIO() print(MiscHelper.convert_first_char_upper_and_other_lower( Utils.ifNotNull(self.typ, "?")), end="", file=res) org0_ = Utils.asObjectOrNull( self.get_slot_value(InstrumentParticipantReferent.ATTR_REF), Referent) del0_ = Utils.asObjectOrNull( self.get_slot_value(InstrumentParticipantReferent.ATTR_DELEGATE), Referent) if (org0_ is not None): print(": {0}".format(org0_.to_string(short_variant, lang, 0)), end="", file=res, flush=True) if (not short_variant and del0_ is not None): print(" (в лице {0})".format( del0_.to_string(True, lang, lev + 1)), end="", file=res, flush=True) elif (del0_ is not None): print(": в лице {0}".format( del0_.to_string(short_variant, lang, lev + 1)), end="", file=res, flush=True) return Utils.toStringStringIO(res)
def to_string(self, short_variant: bool, lang: 'MorphLang', lev: int = 0) -> str: res = io.StringIO() str0_ = None str0_ = self.get_string_value(InstrumentReferent.ATTR_APPENDIX) if ((str0_) is not None): strs = self.get_string_values(InstrumentReferent.ATTR_APPENDIX) if (len(strs) == 1): print("Приложение{0}{1}; ".format( ("" if len(str0_) == 0 else " "), str0_), end="", file=res, flush=True) else: print("Приложения ", end="", file=res) i = 0 while i < len(strs): if (i > 0): print(",", end="", file=res) print(strs[i], end="", file=res) i += 1 print("; ", end="", file=res) str0_ = self.get_string_value(InstrumentReferent.ATTR_PART) if ((str0_) is not None): print("Часть {0}; ".format(str0_), end="", file=res, flush=True) if (self.typ is not None): print(MiscHelper.convert_first_char_upper_and_other_lower( self.typ), end="", file=res) else: print("Документ", end="", file=res) if (self.reg_number is not None): print(" №{0}".format(self.reg_number), end="", file=res, flush=True) for s in self.slots: if (s.type_name == InstrumentReferent.ATTR_REGNUMBER and str(s.value) != self.reg_number): print("/{0}".format(s.value), end="", file=res, flush=True) if (self.case_number is not None): print(" дело №{0}".format(self.case_number), end="", file=res, flush=True) dt = self.get_string_value(InstrumentReferent.ATTR_DATE) if (dt is not None): print(" от {0}".format(dt), end="", file=res, flush=True) str0_ = self.get_string_value(InstrumentBlockReferent.ATTR_NAME) if ((str0_) is not None): if (len(str0_) > 100): str0_ = (str0_[0:0 + 100] + "...") print(" \"{0}\"".format(str0_), end="", file=res, flush=True) str0_ = self.get_string_value(InstrumentReferent.ATTR_GEO) if ((str0_) is not None): print(" ({0})".format(str0_), end="", file=res, flush=True) return Utils.toStringStringIO(res).strip()
def tryAttach(t: 'Token', can_be_pure_number: bool = False, typ: 'OrgItemTypeToken' = None) -> 'OrgItemNumberToken': if (t is None): return None tt = Utils.asObjectOrNull(t, TextToken) if (tt is not None): t1 = MiscHelper.checkNumberPrefix(tt) if ((isinstance(t1, NumberToken)) and not t1.is_newline_before): return OrgItemNumberToken._new1704(tt, t1, str((t1).value)) if ((t.is_hiphen and (isinstance(t.next0_, NumberToken)) and not t.is_whitespace_before) and not t.is_whitespace_after): if (NumberHelper.tryParseAge(t.next0_) is None): return OrgItemNumberToken._new1704(t, t.next0_, str((t.next0_).value)) if (isinstance(t, NumberToken)): if ((not t.is_whitespace_before and t.previous is not None and t.previous.is_hiphen)): return OrgItemNumberToken._new1704(t, t, str((t).value)) if (typ is not None and typ.typ is not None and (( (typ.typ == "войсковая часть" or typ.typ == "військова частина" or "колония" in typ.typ) or "колонія" in typ.typ))): if (t.length_char >= 4 or t.length_char <= 6): res = OrgItemNumberToken._new1704(t, t, str((t).value)) if (t.next0_ is not None and ((t.next0_.is_hiphen or t.next0_.isCharOf("\\/"))) and not t.next0_.is_whitespace_after): if ((isinstance(t.next0_.next0_, NumberToken)) and ((t.length_char + t.next0_.next0_.length_char) < 9)): res.end_token = t.next0_.next0_ res.number = "{0}-{1}".format( res.number, (res.end_token).value) elif ((isinstance(t.next0_.next0_, TextToken)) and t.next0_.next0_.length_char == 1 and t.next0_.next0_.chars.is_letter): res.end_token = t.next0_.next0_ res.number = "{0}{1}".format( res.number, (res.end_token).term) elif ((isinstance(t.next0_, TextToken)) and t.next0_.length_char == 1 and t.next0_.chars.is_letter): res.end_token = t.next0_ res.number = "{0}{1}".format(res.number, (res.end_token).term) return res if (((isinstance(t, TextToken)) and t.length_char == 1 and t.chars.is_letter) and not t.is_whitespace_after): if (typ is not None and typ.typ is not None and (( (typ.typ == "войсковая часть" or typ.typ == "військова частина" or "колония" in typ.typ) or "колонія" in typ.typ))): tt1 = t.next0_ if (tt1 is not None and tt1.is_hiphen): tt1 = tt1.next0_ if ((isinstance(tt1, NumberToken)) and not tt1.is_whitespace_before): res = OrgItemNumberToken(t, tt1) res.number = "{0}{1}".format((t).term, (tt1).value) return res return None
def __ToString(self, short_variant : bool, lang : 'MorphLang', out_cladr : bool, lev : int) -> str: if (self.is_union and not self.is_state): res = io.StringIO() print(self.getStringValue(GeoReferent.ATTR_TYPE), end="", file=res) for s in self.slots: if (s.type_name == GeoReferent.ATTR_REF and (isinstance(s.value, Referent))): print("; {0}".format((s.value).toString(True, lang, 0)), end="", file=res, flush=True) return Utils.toStringStringIO(res) name = MiscHelper.convertFirstCharUpperAndOtherLower(self.__getName(lang is not None and lang.is_en)) if (not short_variant): if (not self.is_state): if (self.is_city and self.is_region): pass else: typ = self.getStringValue(GeoReferent.ATTR_TYPE) if (typ is not None): if (not self.is_city): i = typ.rfind(' ') if (i > 0): typ = typ[i + 1:] name = "{0} {1}".format(typ, name) if (not short_variant and out_cladr): kladr = self.getSlotValue(GeoReferent.ATTR_FIAS) if (isinstance(kladr, Referent)): name = "{0} (ФИАС: {1})".format(name, Utils.ifNotNull((kladr).getStringValue("GUID"), "?")) bti = self.getStringValue(GeoReferent.ATTR_BTI) if (bti is not None): name = "{0} (БТИ {1})".format(name, bti) if (not short_variant and self.higher is not None and (lev < 10)): if (((self.higher.is_city and self.is_region)) or ((self.findSlot(GeoReferent.ATTR_TYPE, "город", True) is None and self.findSlot(GeoReferent.ATTR_TYPE, "місто", True) is None and self.is_city))): return "{0}; {1}".format(name, self.higher.__ToString(False, lang, False, lev + 1)) return name
def __tryParseRu(t: 'Token') -> 'VerbPhraseToken': res = None t0 = t not0_ = None has_verb = False first_pass2814 = True while True: if first_pass2814: first_pass2814 = False else: t = t.next0_ if (not (t is not None)): break if (not ((isinstance(t, TextToken)))): break tt = Utils.asObjectOrNull(t, TextToken) if (tt.term == "НЕ"): not0_ = t continue ty = 0 mc = tt.getMorphClassInDictionary() if (tt.term == "НЕТ"): ty = 1 elif (mc.is_adverb): ty = 2 elif (tt.is_pure_verb or tt.is_verb_be): ty = 1 elif (mc.is_verb): if (mc.is_preposition or mc.is_misc): pass elif (mc.is_noun): if (tt.term == "СТАЛИ"): ty = 1 elif (not tt.chars.is_all_lower and not MiscHelper.canBeStartOfSentence(tt)): ty = 1 elif (mc.is_proper): if (tt.chars.is_all_lower): ty = 1 else: ty = 1 if (ty == 0): break if (res is None): res = VerbPhraseToken(t0, t) res.end_token = t it = VerbPhraseItemToken._new638(t, t, MorphCollection(t.morph)) if (not0_ is not None): it.begin_token = not0_ it.not0_ = True not0_ = (None) it.is_adverb = ty == 2 it.normal = t.getNormalCaseText( (MorphClass.ADVERB if ty == 2 else MorphClass.VERB), False, MorphGender.UNDEFINED, False) res.items.append(it) if (not has_verb and ty == 1): res.morph = it.morph has_verb = True if (not has_verb): return None return res
def __corr_chars(str0_: str, ci: 'CharsInfo', keep_chars: bool) -> str: if (not keep_chars): return str0_ if (ci.is_all_lower): return str0_.lower() if (ci.is_capital_upper): return MiscHelper.convert_first_char_upper_and_other_lower(str0_) return str0_
def __corrChars(self, str0_: str, keep: bool) -> str: if (not keep): return str0_ if (self.chars.is_all_lower): return str0_.lower() if (self.chars.is_capital_upper): return MiscHelper.convertFirstCharUpperAndOtherLower(str0_) return str0_
def __corr_chars(self, str0_: str, keep: bool) -> str: if (not keep): return str0_ if (self.chars.is_all_lower): return str0_.lower() if (self.chars.is_capital_upper): return MiscHelper.convert_first_char_upper_and_other_lower(str0_) return str0_
def to_string(self, short_variant: bool, lang: 'MorphLang' = None, lev: int = 0) -> str: res = io.StringIO() str0_ = None for s in self.slots: if (s.type_name == WeaponReferent.ATTR_TYPE): n = s.value if (str0_ is None or (len(n) < len(str0_))): str0_ = n if (str0_ is not None): print(str0_.lower(), end="", file=res) str0_ = self.get_string_value(WeaponReferent.ATTR_BRAND) if ((str0_) is not None): print(" {0}".format( MiscHelper.convert_first_char_upper_and_other_lower(str0_)), end="", file=res, flush=True) str0_ = self.get_string_value(WeaponReferent.ATTR_MODEL) if ((str0_) is not None): print(" {0}".format(str0_), end="", file=res, flush=True) str0_ = self.get_string_value(WeaponReferent.ATTR_NAME) if ((str0_) is not None): print(" \"{0}\"".format( MiscHelper.convert_first_char_upper_and_other_lower(str0_)), end="", file=res, flush=True) for s in self.slots: if (s.type_name == WeaponReferent.ATTR_NAME and str0_ != (s.value)): if (LanguageHelper.is_cyrillic_char(str0_[0]) != LanguageHelper.is_cyrillic_char(s.value[0])): print(" ({0})".format( MiscHelper. convert_first_char_upper_and_other_lower(s.value)), end="", file=res, flush=True) break str0_ = self.get_string_value(WeaponReferent.ATTR_NUMBER) if ((str0_) is not None): print(", номер {0}".format(str0_), end="", file=res, flush=True) return Utils.toStringStringIO(res)
def toString(self, short_variant: bool, lang: 'MorphLang', lev: int = 0) -> str: res = io.StringIO() if (self.typ is not None): print(MiscHelper.convertFirstCharUpperAndOtherLower(self.typ), end="", file=res) else: kind_ = self.getStringValue(FundsReferent.ATTR_KIND) if (kind_ is not None): kind_ = (Utils.asObjectOrNull( FundsMeta.GLOBAL_META.kind_feature. convertInnerValueToOuterValue(kind_, None), str)) if (kind_ is not None): print(MiscHelper.convertFirstCharUpperAndOtherLower(kind_), end="", file=res) else: print("?", end="", file=res) if (self.source is not None): print("; {0}".format(self.source.toString(short_variant, lang, 0)), end="", file=res, flush=True) if (self.count > 0): print("; кол-во {0}".format(self.count), end="", file=res, flush=True) if (self.percent > 0): print("; {0}%".format(self.percent), end="", file=res, flush=True) if (not short_variant): if (self.sum0_ is not None): print("; {0}".format(self.sum0_.toString(False, lang, 0)), end="", file=res, flush=True) if (self.price is not None): print("; номинал {0}".format( self.price.toString(False, lang, 0)), end="", file=res, flush=True) return Utils.toStringStringIO(res)
def __corrChars(str0_: str, ci: 'CharsInfo', keep_chars: bool) -> str: if (not keep_chars): return str0_ if (ci.is_all_lower): return str0_.lower() if (ci.is_capital_upper): return MiscHelper.convertFirstCharUpperAndOtherLower(str0_) return str0_
def __checkDetail(rt : 'ReferentToken') -> None: if (rt.end_token.whitespaces_after_count > 2 or rt.end_token.next0_ is None): return if (rt.end_token.next0_.isChar('(')): br = BracketHelper.tryParse(rt.end_token.next0_, BracketParseAttr.NO, 100) if (br is not None): (rt.referent).detail = MiscHelper.getTextValue(br.begin_token.next0_, br.end_token.previous, GetTextAttr.NO) rt.end_token = br.end_token
def process_ontology_item(self, begin: 'Token') -> 'ReferentToken': if (begin is None): return None ga = GoodAttributeReferent() if (begin.chars.is_latin_letter): if (begin.is_value("KEYWORD", None)): ga.typ = GoodAttrType.KEYWORD begin = begin.next0_ elif (begin.is_value("CHARACTER", None)): ga.typ = GoodAttrType.CHARACTER begin = begin.next0_ elif (begin.is_value("PROPER", None)): ga.typ = GoodAttrType.PROPER begin = begin.next0_ elif (begin.is_value("MODEL", None)): ga.typ = GoodAttrType.MODEL begin = begin.next0_ if (begin is None): return None res = ReferentToken(ga, begin, begin) t = begin first_pass3181 = True while True: if first_pass3181: first_pass3181 = False else: t = t.next0_ if (not (t is not None)): break if (t.is_char(';')): ga.add_slot( GoodAttributeReferent.ATTR_VALUE, MiscHelper.get_text_value(begin, t.previous, GetTextAttr.NO), False, 0) begin = t.next0_ continue res.end_token = t if (res.end_char > begin.begin_char): ga.add_slot( GoodAttributeReferent.ATTR_VALUE, MiscHelper.get_text_value(begin, res.end_token, GetTextAttr.NO), False, 0) if (ga.typ == GoodAttrType.UNDEFINED): if (not begin.chars.is_all_lower): ga.typ = GoodAttrType.PROPER return res
def __compareSurnamesStrs(self, s1 : str, s2 : str) -> bool: """ Сравнение с учётом возможных окончаний Args: s1(str): s2(str): """ if (s1.startswith(s2) or s2.startswith(s1)): return True if (PersonReferent._DelSurnameEnd(s1) == PersonReferent._DelSurnameEnd(s2)): return True n1 = MiscHelper.getAbsoluteNormalValue(s1, False) if (n1 is not None): if (n1 == MiscHelper.getAbsoluteNormalValue(s2, False)): return True if (MiscHelper.canBeEquals(s1, s2, True, True, False)): return True return False
def get_normal_case_text(self, mc : 'MorphClass'=None, num : 'MorphNumber'=MorphNumber.UNDEFINED, gender : 'MorphGender'=MorphGender.UNDEFINED, keep_chars : bool=False) -> str: res = self.normal if (keep_chars): if (self.chars.is_all_lower): res = res.lower() elif (self.chars.is_all_upper): pass elif (self.chars.is_capital_upper): res = MiscHelper.convert_first_char_upper_and_other_lower(res) return res
def try_parse_author( t: 'Token', prev_pers_template: 'FioTemplateType' = FioTemplateType.UNDEFINED ) -> 'BookLinkToken': if (t is None): return None rtp = PersonItemToken.try_parse_person(t, prev_pers_template) if (rtp is not None): re = None if (rtp.data is None): re = BookLinkToken._new326(t, (t if rtp == t else rtp.end_token), BookLinkTyp.PERSON, rtp.referent) else: re = BookLinkToken._new327(t, rtp.end_token, BookLinkTyp.PERSON, rtp) re.person_template = (Utils.valToEnum(rtp.misc_attrs, FioTemplateType)) tt = rtp.begin_token first_pass3018 = True while True: if first_pass3018: first_pass3018 = False else: tt = tt.next0_ if (not (tt is not None and tt.end_char <= rtp.end_char)): break if (not (isinstance(tt.get_referent(), PersonPropertyReferent))): continue rt = Utils.asObjectOrNull(tt, ReferentToken) if (rt.begin_token.chars.is_capital_upper and tt != rtp.begin_token): re.start_of_name = MiscHelper.get_text_value_of_meta_token( rt, GetTextAttr.KEEPREGISTER) break return None return re if (t.is_char('[')): re = BookLinkToken.try_parse_author(t.next0_, FioTemplateType.UNDEFINED) if (re is not None and re.end_token.next0_ is not None and re.end_token.next0_.is_char(']')): re.begin_token = t re.end_token = re.end_token.next0_ return re if (((t.is_value("И", None) or t.is_value("ET", None))) and t.next0_ is not None): if (t.next0_.is_value("ДРУГИЕ", None) or t.next0_.is_value("ДР", None) or t.next0_.is_value("AL", None)): res = BookLinkToken._new328(t, t.next0_, BookLinkTyp.ANDOTHERS) if (t.next0_.next0_ is not None and t.next0_.next0_.is_char('.')): res.end_token = res.end_token.next0_ return res return None
def get_morph_variant(self, cas : 'MorphCase', plural : bool) -> str: """ Сгенерировать текст именной группы в нужном падеже и числе Args: cas(MorphCase): нужный падеж plural(bool): нужное число Returns: str: результирующая строка """ mi = MorphBaseInfo._new499(cas, MorphLang.RU) if (plural): mi.number = MorphNumber.PLURAL else: mi.number = MorphNumber.SINGULAR res = None for a in self.adjectives: tt = MiscHelper.get_text_value_of_meta_token(a, GetTextAttr.NO) if (a.begin_token != a.end_token or not (isinstance(a.begin_token, TextToken))): pass else: tt2 = MorphologyService.get_wordform(tt, mi) if (tt2 is not None): tt = tt2 if (res is None): res = tt else: res = "{0} {1}".format(res, tt) if (self.noun is not None): tt = MiscHelper.get_text_value_of_meta_token(self.noun, GetTextAttr.NO) if (self.noun.begin_token != self.noun.end_token or not (isinstance(self.noun.begin_token, TextToken))): pass else: tt2 = MorphologyService.get_wordform(tt, mi) if (tt2 is not None): tt = tt2 if (res is None): res = tt else: res = "{0} {1}".format(res, tt) return res
def getMorphVariant(self, cas: 'MorphCase', plural: bool) -> str: """ Сгенерировать текст именной группы в нужном падеже и числе Args: cas(MorphCase): plural(bool): """ mi = MorphBaseInfo._new551(cas, MorphLang.RU) if (plural): mi.number = MorphNumber.PLURAL else: mi.number = MorphNumber.SINGULAR res = None for a in self.adjectives: tt = MiscHelper.getTextValueOfMetaToken(a, GetTextAttr.NO) if (a.begin_token != a.end_token or not ((isinstance(a.begin_token, TextToken)))): pass else: tt2 = Morphology.getWordform(tt, mi) if (tt2 is not None): tt = tt2 if (res is None): res = tt else: res = "{0} {1}".format(res, tt) if (self.noun is not None): tt = MiscHelper.getTextValueOfMetaToken(self.noun, GetTextAttr.NO) if (self.noun.begin_token != self.noun.end_token or not ((isinstance(self.noun.begin_token, TextToken)))): pass else: tt2 = Morphology.getWordform(tt, mi) if (tt2 is not None): tt = tt2 if (res is None): res = tt else: res = "{0} {1}".format(res, tt) return res
def __attachRusAutoNumber(t: 'Token') -> 'TransItemToken': v1 = MiscHelper.getCyrLatWord(t, 1) if (v1 is None or v1.cyr_word is None): return None t0 = t doubt = 0 if (not t.chars.is_all_upper or t.is_whitespace_after): doubt += 1 t = t.next0_ nt = Utils.asObjectOrNull(t, NumberToken) if ((nt is None or nt.typ != NumberSpellingType.DIGIT or nt.morph.class0_.is_adjective) or (nt.end_char - nt.begin_char) != 2): return None t = t.next0_ v2 = MiscHelper.getCyrLatWord(t, 2) if (v2 is None or v2.cyr_word is None or v2.length != 2): return None if (not t.chars.is_all_upper or t.is_whitespace_after): doubt += 1 res = TransItemToken._new2533(t0, t, TransItemToken.Typs.NUMBER, TransportKind.AUTO) res.value = "{0}{1}{2}".format(v1.cyr_word, nt.getSourceText(), v2.cyr_word) nt = (Utils.asObjectOrNull(t.next0_, NumberToken)) if (((nt is not None and nt.int_value is not None and nt.typ == NumberSpellingType.DIGIT) and not nt.morph.class0_.is_adjective and (nt.int_value < 200)) and (t.whitespaces_after_count < 2)): n = nt.value if (len(n) < 2): n = ("0" + n) res.alt_value = n res.end_token = nt if (res.end_token.next0_ is not None and res.end_token.next0_.isValue("RUS", None)): res.end_token = res.end_token.next0_ doubt = 0 if (doubt > 1): res.is_doubt = True return res
def __getShortName(self) -> str: nam = self.name if (nam is None): return None if (len(nam) > 100): i = 100 while i < len(nam): if (not str.isalpha(nam[i])): break i += 1 if (i < len(nam)): nam = (nam[0:0 + i] + "...") return MiscHelper.convertFirstCharUpperAndOtherLower(nam)
def __get_short_name(self) -> str: nam = self.name if (nam is None): return None if (len(nam) > 100): i = 100 while i < len(nam): if (not str.isalpha(nam[i])): break i += 1 if (i < len(nam)): nam = (nam[0:0 + i] + "...") return MiscHelper.convert_first_char_upper_and_other_lower(nam)
def __correctModel(self) -> None: tt = self.end_token.next0_ if (tt is None or tt.whitespaces_before_count > 2): return if (tt.isValue(":\\/.", None) or tt.is_hiphen): tt = tt.next0_ if (isinstance(tt, NumberToken)): tmp = io.StringIO() print((tt).value, end="", file=tmp) is_lat = LanguageHelper.isLatinChar(self.value[0]) self.end_token = tt tt = tt.next0_ first_pass3157 = True while True: if first_pass3157: first_pass3157 = False else: tt = tt.next0_ if (not (tt is not None)): break if ((isinstance(tt, TextToken)) and tt.length_char == 1 and tt.chars.is_letter): if (not tt.is_whitespace_before or ((tt.previous is not None and tt.previous.is_hiphen))): ch = (tt).term[0] self.end_token = tt ch2 = chr(0) if (LanguageHelper.isLatinChar(ch) and not is_lat): ch2 = LanguageHelper.getCyrForLat(ch) if (ch2 != (chr(0))): ch = ch2 elif (LanguageHelper.isCyrillicChar(ch) and is_lat): ch2 = LanguageHelper.getLatForCyr(ch) if (ch2 != (chr(0))): ch = ch2 print(ch, end="", file=tmp) continue break self.value = "{0}-{1}".format(self.value, Utils.toStringStringIO(tmp)) self.alt_value = MiscHelper.createCyrLatAlternative(self.value) if (not self.end_token.is_whitespace_after and self.end_token.next0_ is not None and ((self.end_token.next0_.is_hiphen or self.end_token.next0_.isCharOf("\\/")))): if (not self.end_token.next0_.is_whitespace_after and (isinstance(self.end_token.next0_.next0_, NumberToken))): self.end_token = self.end_token.next0_.next0_ self.value = "{0}-{1}".format(self.value, (self.end_token).value) if (self.alt_value is not None): self.alt_value = "{0}-{1}".format(self.alt_value, (self.end_token).value)