def __attachSpecPostfix(t: 'Token') -> 'NumberExToken': if (t is None): return None if (t.isCharOf("%")): return NumberExToken(t, t, "", NumberSpellingType.DIGIT, NumberExType.PERCENT) money = NumberHelper._isMoneyChar(t) if (money is not None): return NumberExToken._new478(t, t, "", NumberSpellingType.DIGIT, NumberExType.MONEY, money) return None
def tryParseNumberWithPostfix(t: 'Token') -> 'NumberExToken': """ Выделение стандартных мер, типа: 10 кв.м. """ if (t is None): return None t0 = t is_dollar = None if (t.length_char == 1 and t.next0_ is not None): is_dollar = NumberHelper._isMoneyChar(t) if ((is_dollar) is not None): t = t.next0_ nt = Utils.asObjectOrNull(t, NumberToken) if (nt is None): if ((not ((isinstance(t.previous, NumberToken))) and t.isChar('(') and (isinstance(t.next0_, NumberToken))) and t.next0_.next0_ is not None and t.next0_.next0_.isChar(')')): toks1 = NumberExHelper._m_postfixes.tryParse( t.next0_.next0_.next0_, TerminParseAttr.NO) if (toks1 is not None and (Utils.valToEnum(toks1.termin.tag, NumberExType)) == NumberExType.MONEY): nt0 = Utils.asObjectOrNull(t.next0_, NumberToken) res = NumberExToken._new471(t, toks1.end_token, nt0.value, nt0.typ, NumberExType.MONEY, nt0.real_value, toks1.begin_token.morph) return NumberExHelper.__correctMoney( res, toks1.begin_token) tt = Utils.asObjectOrNull(t, TextToken) if (tt is None or not tt.morph.class0_.is_adjective): return None val = tt.term i = 4 first_pass2785 = True while True: if first_pass2785: first_pass2785 = False else: i += 1 if (not (i < (len(val) - 5))): break v = val[0:0 + i] li = NumberHelper._m_nums.tryAttachStr(v, tt.morph.language) if (li is None): continue vv = val[i:] lii = NumberExHelper._m_postfixes.tryAttachStr( vv, tt.morph.language) if (lii is not None and len(lii) > 0): re = NumberExToken._new472( t, t, str((li[0].tag)), NumberSpellingType.WORDS, Utils.valToEnum(lii[0].tag, NumberExType), t.morph) NumberExHelper.__correctExtTypes(re) return re break return None if (t.next0_ is None and is_dollar is None): return None f = nt.real_value t1 = nt.next0_ if (((t1 is not None and t1.isCharOf(",."))) or (((isinstance(t1, NumberToken)) and (t1.whitespaces_before_count < 3)))): tt11 = NumberHelper.tryParseRealNumber(nt, False) if (tt11 is not None): t1 = tt11.end_token.next0_ f = tt11.real_value if (t1 is None): if (is_dollar is None): return None elif ((t1.next0_ is not None and t1.next0_.isValue("С", "З") and t1.next0_.next0_ is not None) and t1.next0_.next0_.isValue("ПОЛОВИНА", None)): f += .5 t1 = t1.next0_.next0_ if (t1 is not None and t1.is_hiphen and t1.next0_ is not None): t1 = t1.next0_ det = False altf = f if (((isinstance(t1, NumberToken)) and t1.previous is not None and t1.previous.is_hiphen) and (t1).int_value == 0 and t1.length_char == 2): t1 = t1.next0_ if ((t1 is not None and t1.next0_ is not None and t1.isChar('(')) and (((isinstance(t1.next0_, NumberToken)) or t1.next0_.isValue("НОЛЬ", None))) and t1.next0_.next0_ is not None): nt1 = Utils.asObjectOrNull(t1.next0_, NumberToken) val = 0 if (nt1 is not None): val = nt1.real_value if (math.floor(f) == math.floor(val)): ttt = t1.next0_.next0_ if (ttt.isChar(')')): t1 = ttt.next0_ det = True if ((isinstance(t1, NumberToken)) and (t1).int_value is not None and (t1).int_value == 0): t1 = t1.next0_ elif ( ((((isinstance(ttt, NumberToken)) and ((ttt).real_value < 100) and ttt.next0_ is not None) and ttt.next0_.isChar('/') and ttt.next0_.next0_ is not None) and ttt.next0_.next0_.getSourceText() == "100" and ttt.next0_.next0_.next0_ is not None) and ttt.next0_.next0_.next0_.isChar(')')): rest = NumberExHelper.__getDecimalRest100(f) if ((ttt).int_value is not None and rest == (ttt).int_value): t1 = ttt.next0_.next0_.next0_.next0_ det = True elif ((ttt.isValue("ЦЕЛЫХ", None) and (isinstance(ttt.next0_, NumberToken)) and ttt.next0_.next0_ is not None) and ttt.next0_.next0_.next0_ is not None and ttt.next0_.next0_.next0_.isChar(')')): num2 = Utils.asObjectOrNull(ttt.next0_, NumberToken) altf = num2.real_value if (ttt.next0_.next0_.isValue("ДЕСЯТЫЙ", None)): altf /= (10) elif (ttt.next0_.next0_.isValue("СОТЫЙ", None)): altf /= (100) elif (ttt.next0_.next0_.isValue("ТЫСЯЧНЫЙ", None)): altf /= (1000) elif (ttt.next0_.next0_.isValue("ДЕСЯТИТЫСЯЧНЫЙ", None)): altf /= (10000) elif (ttt.next0_.next0_.isValue("СТОТЫСЯЧНЫЙ", None)): altf /= (100000) elif (ttt.next0_.next0_.isValue("МИЛЛИОННЫЙ", None)): altf /= (1000000) if (altf < 1): altf += val t1 = ttt.next0_.next0_.next0_.next0_ det = True else: toks1 = NumberExHelper._m_postfixes.tryParse( ttt, TerminParseAttr.NO) if (toks1 is not None): if ((Utils.valToEnum( toks1.termin.tag, NumberExType)) == NumberExType.MONEY): if (toks1.end_token.next0_ is not None and toks1.end_token.next0_.isChar(')')): res = NumberExToken._new473( t, toks1.end_token.next0_, nt.value, nt.typ, NumberExType.MONEY, f, altf, toks1.begin_token.morph) return NumberExHelper.__correctMoney( res, toks1.begin_token) res2 = NumberExHelper.tryParseNumberWithPostfix(t1.next0_) if (res2 is not None and res2.end_token.next0_ is not None and res2.end_token.next0_.isChar(')')): if (res2.int_value is not None): res2.begin_token = t res2.end_token = res2.end_token.next0_ res2.alt_real_value = res2.real_value res2.real_value = f NumberExHelper.__correctExtTypes(res2) if (res2.whitespaces_after_count < 2): toks2 = NumberExHelper._m_postfixes.tryParse( res2.end_token.next0_, TerminParseAttr.NO) if (toks2 is not None): if ((Utils.valToEnum( toks2.termin.tag, NumberExType) ) == NumberExType.MONEY): res2.end_token = toks2.end_token return res2 elif (nt1 is not None and nt1.typ == NumberSpellingType.WORDS and nt.typ == NumberSpellingType.DIGIT): altf = nt1.real_value ttt = t1.next0_.next0_ if (ttt.isChar(')')): t1 = ttt.next0_ det = True if (not det): altf = f if ((t1 is not None and t1.isChar('(') and t1.next0_ is not None) and t1.next0_.isValue("СУММА", None)): br = BracketHelper.tryParse(t1, BracketParseAttr.NO, 100) if (br is not None): t1 = br.end_token.next0_ if (is_dollar is not None): te = None if (t1 is not None): te = t1.previous else: t1 = t0 while t1 is not None: if (t1.next0_ is None): te = t1 t1 = t1.next0_ if (te is None): return None if (te.is_hiphen and te.next0_ is not None): if (te.next0_.isValue("МИЛЛИОННЫЙ", None)): f *= (1000000) altf *= (1000000) te = te.next0_ elif (te.next0_.isValue("МИЛЛИАРДНЫЙ", None)): f *= (1000000000) altf *= (1000000000) te = te.next0_ if (not te.is_whitespace_after and (isinstance(te.next0_, TextToken))): if (te.next0_.isValue("M", None)): f *= (1000000) altf *= (1000000) te = te.next0_ elif (te.next0_.isValue("BN", None)): f *= (1000000000) altf *= (1000000000) te = te.next0_ return NumberExToken._new474(t0, te, "", nt.typ, NumberExType.MONEY, f, altf, is_dollar) if (t1 is None or ((t1.is_newline_before and not det))): return None toks = NumberExHelper._m_postfixes.tryParse(t1, TerminParseAttr.NO) if ((toks is None and det and (isinstance(t1, NumberToken))) and (t1).value == "0"): toks = NumberExHelper._m_postfixes.tryParse( t1.next0_, TerminParseAttr.NO) if (toks is not None): t1 = toks.end_token if (not t1.isChar('.') and t1.next0_ is not None and t1.next0_.isChar('.')): if ((isinstance(t1, TextToken)) and t1.isValue( toks.termin.terms[0].canonical_text, None)): pass elif (not t1.chars.is_letter): pass else: t1 = t1.next0_ if (toks.termin.canonic_text == "LTL"): return None if (toks.begin_token == t1): if (t1.morph.class0_.is_preposition or t1.morph.class0_.is_conjunction): if (t1.is_whitespace_before and t1.is_whitespace_after): return None ty = Utils.valToEnum(toks.termin.tag, NumberExType) res = NumberExToken._new473(t, t1, nt.value, nt.typ, ty, f, altf, toks.begin_token.morph) if (ty != NumberExType.MONEY): NumberExHelper.__correctExtTypes(res) return res return NumberExHelper.__correctMoney(res, toks.begin_token) pfx = NumberExHelper.__attachSpecPostfix(t1) if (pfx is not None): pfx.begin_token = t pfx.value = nt.value pfx.typ = nt.typ pfx.real_value = f pfx.alt_real_value = altf return pfx if (t1.next0_ is not None and ((t1.morph.class0_.is_preposition or t1.morph.class0_.is_conjunction))): if (t1.isValue("НА", None)): pass else: nn = NumberExHelper.tryParseNumberWithPostfix(t1.next0_) if (nn is not None): return NumberExToken._new476(t, t, nt.value, nt.typ, nn.ex_typ, f, altf, nn.ex_typ2, nn.ex_typ_param) if (not t1.is_whitespace_after and (isinstance(t1.next0_, NumberToken)) and (isinstance(t1, TextToken))): term = (t1).term ty = NumberExType.UNDEFINED if (term == "СМХ" or term == "CMX"): ty = NumberExType.SANTIMETER elif (term == "MX" or term == "МХ"): ty = NumberExType.METER elif (term == "MMX" or term == "ММХ"): ty = NumberExType.MILLIMETER if (ty != NumberExType.UNDEFINED): return NumberExToken._new477(t, t1, nt.value, nt.typ, ty, f, altf, True) return None