def __calc_newline_between_coef(fr1: 'FragToken', fr2: 'FragToken') -> int:
     if (fr1.newlines_after_count > 1):
         return 1
     tt = fr1.begin_token
     while tt is not None and tt.end_char <= fr1.end_char:
         if (BracketHelper.can_be_start_of_sequence(tt, False, False)):
             br = BracketHelper.try_parse(tt,
                                          BracketParseAttr.CANBEMANYLINES,
                                          100)
             if (br is not None and br.end_char >= fr2.begin_char):
                 return -1
         tt = tt.next0_
     t = fr1.end_token
     if (t.is_char_of(":;.")):
         return 1
     if ((isinstance(t, TextToken))
             and ((t.morph.class0_.is_preposition
                   or t.morph.class0_.is_conjunction))):
         return -1
     t1 = fr2.begin_token
     if (isinstance(t1, TextToken)):
         if (t1.chars.is_all_lower):
             return -1
         if (BracketHelper.can_be_start_of_sequence(t1, False, False)):
             if (t.chars.is_all_lower):
                 return -1
     elif (isinstance(t1, NumberToken)):
         if (t.chars.is_all_lower):
             return -1
     if (t.chars.is_all_lower):
         if (fr2.end_token.is_char(';')):
             return -1
     return 0
Beispiel #2
0
 def try_attach_city(li: typing.List['CityItemToken'],
                     ad: 'AnalyzerDataWithOntology',
                     always: bool = False) -> 'ReferentToken':
     if (li is None):
         return None
     oi = None
     if (len(li) > 2 and li[0].typ == CityItemToken.ItemType.MISC
             and li[1].typ == CityItemToken.ItemType.NOUN):
         li[1].doubtful = False
         del li[0]
     res = None
     if (res is None and len(li) > 1):
         res = CityAttachHelper.__try4(li)
         if (res is not None and res.end_char <= li[1].end_char):
             res = (None)
     if (res is None):
         wrapoi1125 = RefOutArgWrapper(None)
         res = CityAttachHelper.__try1(li, wrapoi1125, ad)
         oi = wrapoi1125.value
     if (res is None):
         wrapoi1126 = RefOutArgWrapper(None)
         res = CityAttachHelper.__try_noun_name(li, wrapoi1126, False)
         oi = wrapoi1126.value
     if (res is None):
         wrapoi1127 = RefOutArgWrapper(None)
         res = CityAttachHelper.__try_name_exist(li, wrapoi1127, False)
         oi = wrapoi1127.value
     if (res is None):
         res = CityAttachHelper.__try4(li)
     if (res is None and always):
         wrapoi1128 = RefOutArgWrapper(None)
         res = CityAttachHelper.__try_noun_name(li, wrapoi1128, True)
         oi = wrapoi1128.value
     if (res is None and always):
         if (AddressItemToken.try_attach_org(li[0].begin_token)
                 is not None):
             pass
         else:
             wrapoi1129 = RefOutArgWrapper(None)
             res = CityAttachHelper.__try_name_exist(li, wrapoi1129, True)
             oi = wrapoi1129.value
     if (res is None):
         return None
     if (res is not None and res.morph is not None):
         pass
     if (res.begin_token.previous is not None):
         if (res.begin_token.previous.is_value("ТЕРРИТОРИЯ", None)):
             res.begin_token = res.begin_token.previous
             res.morph = res.begin_token.morph
         if ((BracketHelper.can_be_start_of_sequence(
                 res.begin_token.previous, False, False)
              and BracketHelper.can_be_end_of_sequence(
                  res.end_token.next0_, False, None, False)
              and res.begin_token.previous.previous is not None)
                 and res.begin_token.previous.previous.is_value(
                     "ТЕРРИТОРИЯ", None)):
             res.begin_token = res.begin_token.previous.previous
             res.morph = res.begin_token.morph
             res.end_token = res.end_token.next0_
     return res
 def process(self, kit : 'AnalysisKit') -> None:
     # Основная функция выделения объектов
     ad = Utils.asObjectOrNull(kit.get_analyzer_data(self), AnalyzerDataWithOntology)
     for k in range(2):
         detect_new_denoms = False
         dt = datetime.datetime.now()
         t = kit.first_token
         first_pass3147 = True
         while True:
             if first_pass3147: first_pass3147 = False
             else: t = t.next0_
             if (not (t is not None)): break
             if (t.is_whitespace_before): 
                 pass
             elif (t.previous is not None and ((t.previous.is_char_of(",") or BracketHelper.can_be_start_of_sequence(t.previous, False, False)))): 
                 pass
             else: 
                 continue
             rt0 = self.__try_attach_spec(t)
             if (rt0 is not None): 
                 rt0.referent = ad.register_referent(rt0.referent)
                 kit.embed_token(rt0)
                 t = (rt0)
                 continue
             if (not t.chars.is_letter): 
                 continue
             if (not self.__can_be_start_of_denom(t)): 
                 continue
             ot = None
             ot = ad.local_ontology.try_attach(t, None, False)
             if (ot is not None and (isinstance(ot[0].item.referent, DenominationReferent))): 
                 if (self.__check_attach(ot[0].begin_token, ot[0].end_token)): 
                     cl = Utils.asObjectOrNull(ot[0].item.referent.clone(), DenominationReferent)
                     cl.occurrence.clear()
                     rt = ReferentToken(cl, ot[0].begin_token, ot[0].end_token)
                     kit.embed_token(rt)
                     t = (rt)
                     continue
             if (k > 0): 
                 continue
             if (t is not None and t.kit.ontology is not None): 
                 ot = t.kit.ontology.attach_token(DenominationReferent.OBJ_TYPENAME, t)
                 if ((ot) is not None): 
                     if (self.__check_attach(ot[0].begin_token, ot[0].end_token)): 
                         dr = DenominationReferent()
                         dr.merge_slots(ot[0].item.referent, True)
                         rt = ReferentToken(ad.register_referent(dr), ot[0].begin_token, ot[0].end_token)
                         kit.embed_token(rt)
                         t = (rt)
                         continue
             rt0 = self.try_attach(t, False)
             if (rt0 is not None): 
                 rt0.referent = ad.register_referent(rt0.referent)
                 kit.embed_token(rt0)
                 detect_new_denoms = True
                 t = (rt0)
                 if (len(ad.local_ontology.items) > 1000): 
                     break
         if (not detect_new_denoms): 
             break
 def _add_name(self, begin: 'Token', end: 'Token') -> 'Termin':
     if (BracketHelper.can_be_start_of_sequence(begin, True, False)):
         br = BracketHelper.try_parse(begin, BracketParseAttr.NO, 100)
         if (br is not None and br.end_token == end):
             begin = begin.next0_
             end = end.previous
     val = MiscHelper.get_text_value(
         begin, end,
         Utils.valToEnum(
             (GetTextAttr.KEEPREGISTER) | (GetTextAttr.KEEPQUOTES),
             GetTextAttr))
     if (val is None):
         return None
     if (val.endswith(".") and not val.endswith("..")):
         val = val[0:0 + len(val) - 1].strip()
     self.add_slot(TitlePageReferent.ATTR_NAME, val, False, 0)
     return Termin(val.upper())
Beispiel #5
0
 def __try_attach_pure_terr(li: typing.List['TerrItemToken'],
                            ad: 'AnalyzerData') -> 'ReferentToken':
     aid = None
     t = li[0].end_token.next0_
     if (t is None):
         return None
     tt = t
     if (BracketHelper.can_be_start_of_sequence(tt, True, False)):
         tt = tt.next0_
     if (len(li) > 1):
         tmp = list(li)
         del tmp[0]
         rt0 = TerrAttachHelper.try_attach_territory(
             tmp, ad, False, None, None)
         if (rt0 is None and len(tmp) == 2):
             if (((tmp[0].termin_item is None
                   and tmp[1].termin_item is not None))
                     or ((tmp[0].termin_item is not None
                          and tmp[1].termin_item is None))):
                 if (aid is None):
                     rt0 = TerrAttachHelper.try_attach_territory(
                         tmp, ad, True, None, None)
         if (rt0 is not None):
             if (rt0.referent.is_state):
                 return None
             rt0.begin_token = li[0].begin_token
             rt0.morph = li[0].morph
             return rt0
     if (aid is None):
         aid = AddressItemToken.try_attach_org(tt)
     if (aid is not None):
         rt = aid.create_geo_org_terr()
         if (rt is None):
             return None
         rt.begin_token = li[0].begin_token
         t1 = rt.end_token
         if (tt != t and BracketHelper.can_be_end_of_sequence(
                 t1.next0_, False, None, False)):
             t1 = t1.next0_
             rt.end_token = t1
         return rt
     return None
Beispiel #6
0
 def try_parse(t : 'Token', add_units : 'TerminCollection', can_be_set : bool=True, can_units_absent : bool=False, is_resctriction : bool=False, is_subval : bool=False) -> 'MeasureToken':
     if (not (isinstance(t, TextToken))): 
         return None
     if (t.is_table_control_char): 
         return None
     t0 = t
     whd = None
     minmax = 0
     wrapminmax1625 = RefOutArgWrapper(minmax)
     tt = NumbersWithUnitToken._is_min_or_max(t0, wrapminmax1625)
     minmax = wrapminmax1625.value
     if (tt is not None): 
         t = tt.next0_
     npt = NounPhraseHelper.try_parse(t, Utils.valToEnum((NounPhraseParseAttr.PARSEPREPOSITION) | (NounPhraseParseAttr.IGNOREBRACKETS), NounPhraseParseAttr), 0, None)
     if (npt is None): 
         whd = NumbersWithUnitToken._try_parsewhl(t)
         if (whd is not None): 
             npt = NounPhraseToken(t0, whd.end_token)
         elif (t0.is_value("КПД", None)): 
             npt = NounPhraseToken(t0, t0)
         elif ((isinstance(t0, TextToken)) and t0.length_char > 3 and t0.get_morph_class_in_dictionary().is_undefined): 
             npt = NounPhraseToken(t0, t0)
         elif (t0.is_value("T", None) and t0.chars.is_all_lower): 
             npt = NounPhraseToken(t0, t0)
             t = t0
             if (t.next0_ is not None and t.next0_.is_char('=')): 
                 npt.end_token = t.next0_
         elif ((isinstance(t0, TextToken)) and t0.chars.is_letter and is_subval): 
             if (NumbersWithUnitToken.try_parse(t, add_units, False, False, False, False) is not None): 
                 return None
             npt = NounPhraseToken(t0, t0)
             t = t0.next0_
             while t is not None: 
                 if (t.whitespaces_before_count > 2): 
                     break
                 elif (not (isinstance(t, TextToken))): 
                     break
                 elif (not t.chars.is_letter): 
                     br = BracketHelper.try_parse(t, BracketParseAttr.NO, 100)
                     if (br is not None): 
                         t = br.end_token
                         npt.end_token = t
                     else: 
                         break
                 elif (NumbersWithUnitToken.try_parse(t, add_units, False, False, False, False) is not None): 
                     break
                 else: 
                     npt.end_token = t
                 t = t.next0_
         else: 
             return None
     elif (NumberHelper.try_parse_real_number(t, True, False) is not None): 
         return None
     else: 
         dtok = DateItemToken.try_attach(t, None, False)
         if (dtok is not None): 
             return None
     t1 = npt.end_token
     t = npt.end_token
     name_ = MetaToken._new509(npt.begin_token, npt.end_token, npt.morph)
     units = None
     units2 = None
     internals_ = list()
     not0_ = False
     tt = t1.next0_
     first_pass3305 = True
     while True:
         if first_pass3305: first_pass3305 = False
         else: tt = tt.next0_
         if (not (tt is not None)): break
         if (tt.is_newline_before): 
             break
         if (tt.is_table_control_char): 
             break
         wrapminmax1617 = RefOutArgWrapper(minmax)
         tt2 = NumbersWithUnitToken._is_min_or_max(tt, wrapminmax1617)
         minmax = wrapminmax1617.value
         if (tt2 is not None): 
             tt = tt2
             t = tt
             t1 = t
             continue
         if ((tt.is_value("БЫТЬ", None) or tt.is_value("ДОЛЖЕН", None) or tt.is_value("ДОЛЖНЫЙ", None)) or tt.is_value("МОЖЕТ", None) or ((tt.is_value("СОСТАВЛЯТЬ", None) and not tt.get_morph_class_in_dictionary().is_adjective))): 
             t = tt
             t1 = t
             if (tt.previous.is_value("НЕ", None)): 
                 not0_ = True
             continue
         www = NumbersWithUnitToken._try_parsewhl(tt)
         if (www is not None): 
             whd = www
             tt = www.end_token
             t = tt
             t1 = t
             continue
         if (tt.is_value("ПРИ", None)): 
             mt1 = MeasureToken.try_parse(tt.next0_, add_units, False, False, True, False)
             if (mt1 is not None): 
                 internals_.append(mt1)
                 tt = mt1.end_token
                 t = tt
                 t1 = t
                 continue
             n1 = NumbersWithUnitToken.try_parse(tt.next0_, add_units, False, False, False, False)
             if (n1 is not None and len(n1.units) > 0): 
                 mt1 = MeasureToken._new1612(n1.begin_token, n1.end_token, n1)
                 internals_.append(mt1)
                 tt = mt1.end_token
                 t = tt
                 t1 = t
                 continue
         if (tt.is_value("ПО", None) and tt.next0_ is not None and tt.next0_.is_value("U", None)): 
             tt = tt.next0_
             t = tt
             t1 = t
             continue
         if (len(internals_) > 0): 
             if (tt.is_char(':')): 
                 break
             mt1 = MeasureToken.try_parse(tt.next0_, add_units, False, False, True, False)
             if (mt1 is not None and mt1.reliable): 
                 internals_.append(mt1)
                 tt = mt1.end_token
                 t = tt
                 t1 = t
                 continue
         if ((isinstance(tt, NumberToken)) and tt.typ == NumberSpellingType.WORDS): 
             npt3 = NounPhraseHelper.try_parse(tt, NounPhraseParseAttr.PARSENUMERICASADJECTIVE, 0, None)
             if (npt3 is not None): 
                 tt = npt3.end_token
                 t1 = tt
                 if (len(internals_) == 0): 
                     name_.end_token = t1
                 continue
         if (((tt.is_hiphen and not tt.is_whitespace_before and not tt.is_whitespace_after) and (isinstance(tt.next0_, NumberToken)) and (isinstance(tt.previous, TextToken))) and tt.previous.chars.is_all_upper): 
             t = tt.next0_
             tt = t
             t1 = tt
             if (len(internals_) == 0): 
                 name_.end_token = t1
             continue
         if (((isinstance(tt, NumberToken)) and not tt.is_whitespace_before and (isinstance(tt.previous, TextToken))) and tt.previous.chars.is_all_upper): 
             t = tt
             t1 = t
             if (len(internals_) == 0): 
                 name_.end_token = t1
             continue
         if ((((isinstance(tt, NumberToken)) and not tt.is_whitespace_after and tt.next0_.is_hiphen) and not tt.next0_.is_whitespace_after and (isinstance(tt.next0_.next0_, TextToken))) and tt.next0_.next0_.length_char > 2): 
             tt = tt.next0_.next0_
             t = tt
             t1 = t
             npt1 = NounPhraseHelper.try_parse(tt, NounPhraseParseAttr.NO, 0, None)
             if (npt1 is not None and npt1.end_char > tt.end_char): 
                 tt = npt1.end_token
                 t = tt
                 t1 = t
             if (len(internals_) == 0): 
                 name_.end_token = t1
             continue
         if ((isinstance(tt, NumberToken)) and tt.previous is not None): 
             if (tt.previous.is_value("USB", None)): 
                 t = tt
                 t1 = t
                 if (len(internals_) == 0): 
                     name_.end_token = t1
                 ttt = tt.next0_
                 while ttt is not None: 
                     if (ttt.is_whitespace_before): 
                         break
                     if (ttt.is_char_of(",:")): 
                         break
                     tt = ttt
                     t = tt
                     t1 = t
                     if (len(internals_) == 0): 
                         name_.end_token = t1
                     ttt = ttt.next0_
                 continue
         mt0 = NumbersWithUnitToken.try_parse(tt, add_units, False, False, False, False)
         if (mt0 is not None): 
             npt1 = NounPhraseHelper.try_parse(tt, Utils.valToEnum((NounPhraseParseAttr.PARSENUMERICASADJECTIVE) | (NounPhraseParseAttr.PARSEPREPOSITION), NounPhraseParseAttr), 0, None)
             if (npt1 is not None and npt1.end_char > mt0.end_char): 
                 tt = npt1.end_token
                 t = tt
                 t1 = t
                 if (len(internals_) == 0): 
                     name_.end_token = t1
                 continue
             break
         if (((tt.is_comma or tt.is_char('('))) and tt.next0_ is not None): 
             www = NumbersWithUnitToken._try_parsewhl(tt.next0_)
             if (www is not None): 
                 whd = www
                 tt = www.end_token
                 t = tt
                 t1 = t
                 if (tt.next0_ is not None and tt.next0_.is_comma): 
                     tt = tt.next0_
                     t1 = tt
                 if (tt.next0_ is not None and tt.next0_.is_char(')')): 
                     tt = tt.next0_
                     t1 = tt
                     continue
             uu = UnitToken.try_parse_list(tt.next0_, add_units, False)
             if (uu is not None): 
                 t = uu[len(uu) - 1].end_token
                 t1 = t
                 units = uu
                 if (tt.is_char('(') and t1.next0_ is not None and t1.next0_.is_char(')')): 
                     tt = t1.next0_
                     t = tt
                     t1 = t
                     continue
                 elif (t1.next0_ is not None and t1.next0_.is_char('(')): 
                     uu = UnitToken.try_parse_list(t1.next0_.next0_, add_units, False)
                     if (uu is not None and uu[len(uu) - 1].end_token.next0_ is not None and uu[len(uu) - 1].end_token.next0_.is_char(')')): 
                         units2 = uu
                         tt = uu[len(uu) - 1].end_token.next0_
                         t = tt
                         t1 = t
                         continue
                     www = NumbersWithUnitToken._try_parsewhl(t1.next0_)
                     if (www is not None): 
                         whd = www
                         tt = www.end_token
                         t = tt
                         t1 = t
                         continue
                 if (uu is not None and len(uu) > 0 and not uu[0].is_doubt): 
                     break
                 if (t1.next0_ is not None): 
                     if (t1.next0_.is_table_control_char or t1.is_newline_after): 
                         break
                 units = (None)
         if (BracketHelper.can_be_start_of_sequence(tt, False, False) and not (isinstance(tt.next0_, NumberToken))): 
             br = BracketHelper.try_parse(tt, BracketParseAttr.NO, 100)
             if (br is not None): 
                 tt = br.end_token
                 t = tt
                 t1 = t
                 continue
         if (tt.is_value("НЕ", None) and tt.next0_ is not None): 
             mc = tt.next0_.get_morph_class_in_dictionary()
             if (mc.is_adverb or mc.is_misc): 
                 break
             continue
         if (tt.is_value("ЯМЗ", None)): 
             pass
         npt2 = NounPhraseHelper.try_parse(tt, Utils.valToEnum((NounPhraseParseAttr.PARSEPREPOSITION) | (NounPhraseParseAttr.IGNOREBRACKETS) | (NounPhraseParseAttr.PARSEPRONOUNS), NounPhraseParseAttr), 0, None)
         if (npt2 is None): 
             if (tt.morph.class0_.is_preposition or tt.morph.class0_.is_conjunction): 
                 to = NumbersWithUnitToken.M_TERMINS.try_parse(tt, TerminParseAttr.NO)
                 if (to is not None): 
                     if ((isinstance(to.end_token.next0_, TextToken)) and to.end_token.next0_.is_letters): 
                         pass
                     else: 
                         break
                 t1 = tt
                 continue
             mc = tt.get_morph_class_in_dictionary()
             if (((isinstance(tt, TextToken)) and tt.chars.is_letter and tt.length_char > 1) and (((tt.chars.is_all_upper or mc.is_adverb or mc.is_undefined) or mc.is_adjective))): 
                 uu = UnitToken.try_parse_list(tt, add_units, False)
                 if (uu is not None): 
                     if (uu[0].length_char > 1 or len(uu) > 1): 
                         units = uu
                         t = uu[len(uu) - 1].end_token
                         t1 = t
                         break
                 t = tt
                 t1 = t
                 if (len(internals_) == 0): 
                     name_.end_token = tt
                 continue
             if (tt.is_comma): 
                 continue
             if (tt.is_char('.')): 
                 if (not MiscHelper.can_be_start_of_sentence(tt.next0_)): 
                     continue
                 uu = UnitToken.try_parse_list(tt.next0_, add_units, False)
                 if (uu is not None): 
                     if (uu[0].length_char > 2 or len(uu) > 1): 
                         units = uu
                         t = uu[len(uu) - 1].end_token
                         t1 = t
                         break
             break
         tt = npt2.end_token
         t = tt
         t1 = t
         if (len(internals_) > 0): 
             pass
         elif (t.is_value("ПРЕДЕЛ", None) or t.is_value("ГРАНИЦА", None) or t.is_value("ДИАПАЗОН", None)): 
             pass
         elif (t.chars.is_letter): 
             name_.end_token = t1
     t11 = t1
     t1 = t1.next0_
     first_pass3306 = True
     while True:
         if first_pass3306: first_pass3306 = False
         else: t1 = t1.next0_
         if (not (t1 is not None)): break
         if (t1.is_table_control_char): 
             pass
         elif (t1.is_char_of(":,_")): 
             if (is_resctriction): 
                 return None
             www = NumbersWithUnitToken._try_parsewhl(t1.next0_)
             if (www is not None): 
                 whd = www
                 t = www.end_token
                 t1 = t
                 continue
             uu = UnitToken.try_parse_list(t1.next0_, add_units, False)
             if (uu is not None): 
                 if (uu[0].length_char > 1 or len(uu) > 1): 
                     units = uu
                     t = uu[len(uu) - 1].end_token
                     t1 = t
                     continue
             if (t1.is_char(':')): 
                 li = list()
                 ttt = t1.next0_
                 first_pass3307 = True
                 while True:
                     if first_pass3307: first_pass3307 = False
                     else: ttt = ttt.next0_
                     if (not (ttt is not None)): break
                     if (ttt.is_hiphen or ttt.is_table_control_char): 
                         continue
                     if ((isinstance(ttt, TextToken)) and not ttt.chars.is_letter): 
                         continue
                     mt1 = MeasureToken.try_parse(ttt, add_units, True, True, False, True)
                     if (mt1 is None): 
                         break
                     li.append(mt1)
                     ttt = mt1.end_token
                     if (ttt.next0_ is not None and ttt.next0_.is_char(';')): 
                         ttt = ttt.next0_
                     if (ttt.is_char(';')): 
                         pass
                     elif (ttt.is_newline_after and mt1.is_newline_before): 
                         pass
                     else: 
                         break
                 if (len(li) > 1): 
                     res0 = MeasureToken._new1618(t0, li[len(li) - 1].end_token, li, True)
                     if (internals_ is not None and len(internals_) > 0): 
                         res0.internal_ex = internals_[0]
                     nam = MiscHelper.get_text_value_of_meta_token(name_, GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE)
                     li[0].begin_token = t0
                     for v in li: 
                         v.name = "{0} ({1})".format(nam, Utils.ifNotNull(v.name, "")).strip()
                         if (v.nums is not None and len(v.nums.units) == 0 and units is not None): 
                             v.nums.units = units
                     return res0
         elif (t1.is_hiphen and t1.is_whitespace_after and t1.is_whitespace_before): 
             pass
         elif (t1.is_hiphen and t1.next0_ is not None and t1.next0_.is_char('(')): 
             pass
         else: 
             break
     if (t1 is None): 
         return None
     mts = NumbersWithUnitToken.try_parse_multi(t1, add_units, False, not0_, True, is_resctriction)
     if (mts is None): 
         if (units is not None and len(units) > 0): 
             if (t1 is None or t1.previous.is_char(':')): 
                 mts = list()
                 if (t1 is None): 
                     t1 = t11
                     while t1 is not None and t1.next0_ is not None: 
                         pass
                         t1 = t1.next0_
                 else: 
                     t1 = t1.previous
                 mts.append(NumbersWithUnitToken._new1619(t0, t1, math.nan))
         if (mts is None): 
             return None
     mt = mts[0]
     if (mt.begin_token == mt.end_token and not (isinstance(mt.begin_token, NumberToken))): 
         return None
     if (not is_subval and name_.begin_token.morph.class0_.is_preposition): 
         name_.begin_token = name_.begin_token.next0_
     if (mt.whl is not None): 
         whd = mt.whl
     for kk in range(10):
         if (whd is not None and whd.end_token == name_.end_token): 
             name_.end_token = whd.begin_token.previous
             continue
         if (units is not None): 
             if (units[len(units) - 1].end_token == name_.end_token): 
                 name_.end_token = units[0].begin_token.previous
                 continue
         break
     if (len(mts) > 1 and len(internals_) == 0): 
         if (len(mt.units) == 0): 
             if (units is not None): 
                 for m in mts: 
                     m.units = units
         res1 = MeasureToken._new1620(t0, mts[len(mts) - 1].end_token, name_.morph, True)
         res1.name = MiscHelper.get_text_value_of_meta_token(name_, GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE)
         k = 0
         while k < len(mts): 
             ttt = MeasureToken._new1612(mts[k].begin_token, mts[k].end_token, mts[k])
             if (whd is not None): 
                 nams = Utils.asObjectOrNull(whd.tag, list)
                 if (k < len(nams)): 
                     ttt.name = nams[k]
             res1.internals.append(ttt)
             k += 1
         tt1 = res1.end_token.next0_
         if (tt1 is not None and tt1.is_char('±')): 
             nn = NumbersWithUnitToken._try_parse(tt1, add_units, True, False, False)
             if (nn is not None and nn.plus_minus_percent): 
                 res1.end_token = nn.end_token
                 res1.nums = nn
                 if (len(nn.units) > 0 and units is None and len(mt.units) == 0): 
                     for m in mts: 
                         m.units = nn.units
         return res1
     if (not mt.is_whitespace_before): 
         if (mt.begin_token.previous is None): 
             return None
         if (mt.begin_token.previous.is_char_of(":),") or mt.begin_token.previous.is_table_control_char or mt.begin_token.previous.is_value("IP", None)): 
             pass
         elif (mt.begin_token.is_hiphen and len(mt.units) > 0 and not mt.units[0].is_doubt): 
             pass
         else: 
             return None
     if (len(mt.units) == 0 and units is not None): 
         mt.units = units
         if (mt.div_num is not None and len(units) > 1 and len(mt.div_num.units) == 0): 
             i = 1
             while i < len(units): 
                 if (units[i].pow0_ == -1): 
                     j = i
                     while j < len(units): 
                         mt.div_num.units.append(units[j])
                         units[j].pow0_ = (- units[j].pow0_)
                         j += 1
                     del mt.units[i:i+len(units) - i]
                     break
                 i += 1
     if ((minmax < 0) and mt.single_val is not None): 
         mt.from_val = mt.single_val
         mt.from_include = True
         mt.single_val = (None)
     if (minmax > 0 and mt.single_val is not None): 
         mt.to_val = mt.single_val
         mt.to_include = True
         mt.single_val = (None)
     if (len(mt.units) == 0): 
         units = UnitToken.try_parse_list(mt.end_token.next0_, add_units, True)
         if (units is None): 
             if (can_units_absent): 
                 pass
             else: 
                 return None
         else: 
             mt.units = units
     res = MeasureToken._new1622(t0, mt.end_token, name_.morph, internals_)
     if (((not t0.is_whitespace_before and t0.previous is not None and t0 == name_.begin_token) and t0.previous.is_hiphen and not t0.previous.is_whitespace_before) and (isinstance(t0.previous.previous, TextToken))): 
         name_.begin_token = res.begin_token = name_.begin_token.previous.previous
     res.name = MiscHelper.get_text_value_of_meta_token(name_, (GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE if not is_subval else GetTextAttr.NO))
     res.nums = mt
     for u in res.nums.units: 
         if (u.keyword is not None): 
             if (u.keyword.begin_char >= res.begin_char): 
                 res.reliable = True
     res.__parse_internals(add_units)
     if (len(res.internals) > 0 or not can_be_set): 
         return res
     t1 = res.end_token.next0_
     if (t1 is not None and t1.is_comma_and): 
         t1 = t1.next0_
     mts1 = NumbersWithUnitToken.try_parse_multi(t1, add_units, False, False, False, False)
     if ((mts1 is not None and len(mts1) == 1 and (t1.whitespaces_before_count < 3)) and len(mts1[0].units) > 0 and not UnitToken.can_be_equals(mts[0].units, mts1[0].units)): 
         res.is_set = True
         res.nums = (None)
         res.internals.append(MeasureToken._new1612(mt.begin_token, mt.end_token, mt))
         res.internals.append(MeasureToken._new1612(mts1[0].begin_token, mts1[0].end_token, mts1[0]))
         res.end_token = mts1[0].end_token
     return res
 def __try_attach(t: 'Token', prev: typing.List['DateItemToken'],
                  detail_regime: bool) -> 'DateItemToken':
     from pullenti.ner.measure.internal.MeasureToken import MeasureToken
     if (t is None):
         return None
     nt = Utils.asObjectOrNull(t, NumberToken)
     begin = t
     end = t
     is_in_brack = False
     if ((BracketHelper.can_be_start_of_sequence(t, False, False)
          and t.next0_ is not None and (isinstance(t.next0_, NumberToken)))
             and BracketHelper.can_be_end_of_sequence(
                 t.next0_.next0_, False, None, False)):
         nt = (Utils.asObjectOrNull(t.next0_, NumberToken))
         end = t.next0_.next0_
         is_in_brack = True
     if ((t.is_newline_before and BracketHelper.is_bracket(t, False) and
          (isinstance(t.next0_, NumberToken)))
             and BracketHelper.is_bracket(t.next0_.next0_, False)):
         nt = (Utils.asObjectOrNull(t.next0_, NumberToken))
         end = t.next0_.next0_
         is_in_brack = True
     if (nt is not None):
         if (nt.int_value is None):
             return None
         if (nt.typ == NumberSpellingType.WORDS):
             if (nt.morph.class0_.is_noun
                     and not nt.morph.class0_.is_adjective):
                 if (t.next0_ is not None
                         and ((t.next0_.is_value("КВАРТАЛ", None)
                               or t.next0_.is_value("ПОЛУГОДИЕ", None)
                               or t.next0_.is_value("ПІВРІЧЧЯ", None)))):
                     pass
                 else:
                     return None
         if (NumberHelper.try_parse_age(nt) is not None):
             return None
         tt = None
         res = DateItemToken._new628(begin, end,
                                     DateItemToken.DateItemType.NUMBER,
                                     nt.int_value, nt.morph)
         if ((res.int_value == 20 and (isinstance(nt.next0_, NumberToken))
              and nt.next0_.int_value is not None)
                 and nt.next0_.length_char == 2 and prev is not None):
             num = 2000 + nt.next0_.int_value
             if ((num < 2030) and len(prev) > 0 and prev[len(prev) - 1].typ
                     == DateItemToken.DateItemType.MONTH):
                 ok = False
                 if (nt.whitespaces_after_count == 1):
                     ok = True
                 elif (nt.is_newline_after and nt.is_newline_after):
                     ok = True
                 if (ok):
                     nt = (Utils.asObjectOrNull(nt.next0_, NumberToken))
                     res.end_token = nt
                     res.int_value = num
         if (res.int_value == 20 or res.int_value == 201):
             tt = t.next0_
             if (tt is not None and tt.is_char('_')):
                 while tt is not None:
                     if (not tt.is_char('_')):
                         break
                     tt = tt.next0_
                 tt = DateItemToken.__test_year_rus_word(tt, False)
                 if (tt is not None):
                     res.int_value = 0
                     res.end_token = tt
                     res.typ = DateItemToken.DateItemType.YEAR
                     return res
         if (res.int_value <= 12 and t.next0_ is not None
                 and (t.whitespaces_after_count < 3)):
             tt = t.next0_
             if (tt.is_value("ЧАС", None)):
                 if (((isinstance(t.previous, TextToken))
                      and not t.previous.chars.is_letter
                      and not t.is_whitespace_before)
                         and (isinstance(t.previous.previous, NumberToken))
                         and not t.previous.is_whitespace_before):
                     pass
                 else:
                     res.typ = DateItemToken.DateItemType.HOUR
                     res.end_token = tt
                     tt = tt.next0_
                     if (tt is not None and tt.is_char('.')):
                         res.end_token = tt
                         tt = tt.next0_
             first_pass3072 = True
             while True:
                 if first_pass3072: first_pass3072 = False
                 else: tt = tt.next0_
                 if (not (tt is not None)): break
                 if (tt.is_value("УТРО", "РАНОК")):
                     res.end_token = tt
                     res.typ = DateItemToken.DateItemType.HOUR
                     return res
                 if (tt.is_value("ВЕЧЕР", "ВЕЧІР")):
                     res.end_token = tt
                     res.int_value += 12
                     res.typ = DateItemToken.DateItemType.HOUR
                     return res
                 if (tt.is_value("ДЕНЬ", None)):
                     res.end_token = tt
                     if (res.int_value < 10):
                         res.int_value += 12
                     res.typ = DateItemToken.DateItemType.HOUR
                     return res
                 if (tt.is_value("НОЧЬ", "НІЧ")):
                     res.end_token = tt
                     if (res.int_value == 12):
                         res.int_value = 0
                     elif (res.int_value > 9):
                         res.int_value += 12
                     res.typ = DateItemToken.DateItemType.HOUR
                     return res
                 if (tt.is_comma or tt.morph.class0_.is_adverb):
                     continue
                 break
             if (res.typ == DateItemToken.DateItemType.HOUR):
                 return res
         can_be_year_ = True
         if (prev is not None and len(prev) > 0 and prev[len(prev) - 1].typ
                 == DateItemToken.DateItemType.MONTH):
             pass
         elif ((prev is not None and len(prev) >= 4 and
                prev[len(prev) - 1].typ == DateItemToken.DateItemType.DELIM)
               and prev[len(prev) - 2].can_by_month):
             pass
         elif (nt.next0_ is not None
               and ((nt.next0_.is_value("ГОД", None)
                     or nt.next0_.is_value("РІК", None)))):
             if (res.int_value < 1000):
                 can_be_year_ = False
         tt = DateItemToken.__test_year_rus_word(nt.next0_, False)
         if (tt is not None and DateItemToken.__is_new_age(tt.next0_)):
             res.typ = DateItemToken.DateItemType.YEAR
             res.end_token = tt
         elif (can_be_year_):
             if (res.can_be_year
                     or res.typ == DateItemToken.DateItemType.NUMBER):
                 tt = DateItemToken.__test_year_rus_word(
                     nt.next0_, res.is_newline_before)
                 if ((tt) is not None):
                     if ((tt.is_value("Г", None)
                          and not tt.is_whitespace_before
                          and t.previous is not None)
                             and ((t.previous.is_value("КОРПУС", None)
                                   or t.previous.is_value("КОРП", None)))):
                         pass
                     elif (
                         (((nt.next0_.is_value("Г", None) and
                            (t.whitespaces_before_count < 3) and t.previous
                            is not None) and t.previous.is_value("Я", None)
                           and t.previous.previous is not None)
                          and t.previous.previous.is_char_of("\\/")
                          and t.previous.previous.previous is not None)
                             and t.previous.previous.previous.is_value(
                                 "А", None)):
                         return None
                     elif (nt.next0_.length_char == 1
                           and not res.can_be_year
                           and ((prev is None or
                                 ((len(prev) > 0 and prev[len(prev) - 1].typ
                                   != DateItemToken.DateItemType.DELIM))))):
                         pass
                     else:
                         res.end_token = tt
                         res.typ = DateItemToken.DateItemType.YEAR
                         res.lang = tt.morph.language
             elif (tt is not None and (nt.whitespaces_after_count < 2)
                   and (nt.end_char - nt.begin_char) == 1):
                 res.end_token = tt
                 res.typ = DateItemToken.DateItemType.YEAR
                 res.lang = tt.morph.language
         if (nt.previous is not None):
             if (nt.previous.is_value("В", "У")
                     or nt.previous.is_value("К", None)
                     or nt.previous.is_value("ДО", None)):
                 tt = DateItemToken.__test_year_rus_word(nt.next0_, False)
                 if ((tt) is not None):
                     ok = False
                     if ((res.int_value < 100)
                             and (isinstance(tt, TextToken)) and
                         ((tt.term == "ГОДА" or tt.term == "РОКИ"))):
                         pass
                     else:
                         ok = True
                         if (nt.previous.is_value("ДО", None)
                                 and nt.next0_.is_value("Г", None)):
                             cou = 0
                             ttt = nt.previous.previous
                             while ttt is not None and (cou < 10):
                                 mt = MeasureToken.try_parse(
                                     ttt, None, False, False, False, False)
                                 if (mt is not None
                                         and mt.end_char > nt.end_char):
                                     ok = False
                                     break
                                 ttt = ttt.previous
                                 cou += 1
                     if (ok):
                         res.end_token = tt
                         res.typ = DateItemToken.DateItemType.YEAR
                         res.lang = tt.morph.language
                         res.begin_token = nt.previous
             elif (((nt.previous.is_value("IN", None)
                     or nt.previous.is_value("SINCE", None)))
                   and res.can_be_year):
                 uu = (NumbersWithUnitToken.try_parse(
                     nt, None, False, False, False, False)
                       if nt.previous.is_value("IN", None) else None)
                 if (uu is not None and len(uu.units) > 0):
                     pass
                 else:
                     res.typ = DateItemToken.DateItemType.YEAR
                     res.begin_token = nt.previous
             elif (nt.previous.is_value("NEL", None)
                   or nt.previous.is_value("DEL", None)):
                 if (res.can_be_year):
                     res.typ = DateItemToken.DateItemType.YEAR
                     res.lang = MorphLang.IT
                     res.begin_token = nt.previous
             elif (nt.previous.is_value("IL", None) and res.can_be_day):
                 res.lang = MorphLang.IT
                 res.begin_token = nt.previous
         t1 = res.end_token.next0_
         if (t1 is not None):
             if (t1.is_value("ЧАС", "ГОДИНА") or t1.is_value("HOUR", None)):
                 if ((((prev is not None and len(prev) == 2
                        and prev[0].can_be_hour)
                       and prev[1].typ == DateItemToken.DateItemType.DELIM
                       and not prev[1].is_whitespace_after)
                      and not prev[1].is_whitespace_after
                      and res.int_value >= 0) and (res.int_value < 59)):
                     prev[0].typ = DateItemToken.DateItemType.HOUR
                     res.typ = DateItemToken.DateItemType.MINUTE
                     res.end_token = t1
                 elif (res.int_value < 24):
                     if (t1.next0_ is not None and t1.next0_.is_char('.')):
                         t1 = t1.next0_
                     res.typ = DateItemToken.DateItemType.HOUR
                     res.end_token = t1
             elif ((res.int_value < 60)
                   and ((t1.is_value("МИНУТА", "ХВИЛИНА") or t1.is_value(
                       "МИН", None) or t.is_value("MINUTE", None)))):
                 if (t1.next0_ is not None and t1.next0_.is_char('.')):
                     t1 = t1.next0_
                 res.typ = DateItemToken.DateItemType.MINUTE
                 res.end_token = t1
             elif (
                 (res.int_value < 60) and
                 ((t1.is_value("СЕКУНДА", None) or t1.is_value("СЕК", None)
                   or t1.is_value("SECOND", None)))):
                 if (t1.next0_ is not None and t1.next0_.is_char('.')):
                     t1 = t1.next0_
                 res.typ = DateItemToken.DateItemType.SECOND
                 res.end_token = t1
             elif ((res.int_value < 30)
                   and ((t1.is_value("ВЕК", "ВІК")
                         or t1.is_value("СТОЛЕТИЕ", "СТОЛІТТЯ")))):
                 res.typ = DateItemToken.DateItemType.CENTURY
                 res.end_token = t1
             elif (res.int_value <= 4 and t1.is_value("КВАРТАЛ", None)):
                 res.typ = DateItemToken.DateItemType.QUARTAL
                 res.end_token = t1
             elif (res.int_value <= 2
                   and ((t1.is_value("ПОЛУГОДИЕ", None)
                         or t1.is_value("ПІВРІЧЧЯ", None)))):
                 res.typ = DateItemToken.DateItemType.HALFYEAR
                 res.end_token = t1
         return res
     t0 = Utils.asObjectOrNull(t, TextToken)
     if (t0 is None):
         return None
     txt = t0.get_source_text()
     if ((txt[0] == 'I' or txt[0] == 'X' or txt[0] == 'Х')
             or txt[0] == 'V'):
         lat = NumberHelper.try_parse_roman(t)
         if (lat is not None and lat.end_token.next0_ is not None
                 and lat.int_value is not None):
             val = lat.int_value
             tt = lat.end_token.next0_
             if (tt.is_value("КВАРТАЛ", None) and val > 0 and val <= 4):
                 return DateItemToken._new629(
                     t, tt, DateItemToken.DateItemType.QUARTAL, val)
             if (tt.is_value("ПОЛУГОДИЕ", "ПІВРІЧЧЯ") and val > 0
                     and val <= 2):
                 return DateItemToken._new629(
                     t, lat.end_token.next0_,
                     DateItemToken.DateItemType.HALFYEAR, val)
             if (tt.is_value("ВЕК", "ВІК")
                     or tt.is_value("СТОЛЕТИЕ", "СТОЛІТТЯ")):
                 return DateItemToken._new629(
                     t, lat.end_token.next0_,
                     DateItemToken.DateItemType.CENTURY, val)
             if (tt.is_value("В", None) and tt.next0_ is not None
                     and tt.next0_.is_char('.')):
                 if (prev is not None and len(prev) > 0
                         and prev[len(prev) - 1].typ
                         == DateItemToken.DateItemType.POINTER):
                     return DateItemToken._new629(
                         t, tt.next0_, DateItemToken.DateItemType.CENTURY,
                         val)
                 if (DateItemToken.__is_new_age(tt.next0_.next0_)):
                     return DateItemToken._new629(
                         t, tt.next0_, DateItemToken.DateItemType.CENTURY,
                         val)
             if (tt.is_hiphen):
                 lat2 = NumberHelper.try_parse_roman(tt.next0_)
                 if (lat2 is not None and lat2.int_value is not None
                         and lat2.end_token.next0_ is not None):
                     if (lat2.end_token.next0_.is_value("ВЕК", "ВІК")
                             or lat2.end_token.next0_.is_value(
                                 "СТОЛЕТИЕ", "СТОЛІТТЯ")):
                         ddd = DateItemToken.try_attach(
                             tt.next0_, None, False)
                         return DateItemToken._new634(
                             t, lat.end_token,
                             DateItemToken.DateItemType.CENTURY, val,
                             ((ddd.new_age if ddd is not None else 0)))
     if (t is not None and t.is_value("НАПРИКІНЦІ", None)):
         return DateItemToken._new635(t, t,
                                      DateItemToken.DateItemType.POINTER,
                                      "конец")
     if (t is not None and t.is_value("ДОНЕДАВНА", None)):
         return DateItemToken._new635(t, t,
                                      DateItemToken.DateItemType.POINTER,
                                      "сегодня")
     if (prev is None):
         if (t is not None):
             if (t.is_value("ОКОЛО", "БІЛЯ")
                     or t.is_value("ПРИМЕРНО", "ПРИБЛИЗНО")
                     or t.is_value("ABOUT", None)):
                 return DateItemToken._new635(
                     t, t, DateItemToken.DateItemType.POINTER, "около")
         if (t.is_value("ОК", None) or t.is_value("OK", None)):
             if (t.next0_ is not None and t.next0_.is_char('.')):
                 return DateItemToken._new635(
                     t, t.next0_, DateItemToken.DateItemType.POINTER,
                     "около")
             return DateItemToken._new635(
                 t, t, DateItemToken.DateItemType.POINTER, "около")
     tok = DateItemToken.M_SEASONS.try_parse(t, TerminParseAttr.NO)
     if ((tok is not None and
          (Utils.valToEnum(tok.termin.tag, DatePointerType))
          == DatePointerType.SUMMER and t.morph.language.is_ru)
             and (isinstance(t, TextToken))):
         str0_ = t.term
         if (str0_ != "ЛЕТОМ" and str0_ != "ЛЕТА" and str0_ != "ЛЕТО"):
             tok = (None)
     if (tok is not None):
         return DateItemToken._new629(
             t, tok.end_token, DateItemToken.DateItemType.POINTER,
             Utils.valToEnum(tok.termin.tag, DatePointerType))
     npt = NounPhraseHelper.try_parse(t, NounPhraseParseAttr.NO, 0, None)
     if (npt is not None):
         tok = DateItemToken.M_SEASONS.try_parse(npt.end_token,
                                                 TerminParseAttr.NO)
         if ((tok is not None and
              (Utils.valToEnum(tok.termin.tag, DatePointerType))
              == DatePointerType.SUMMER and t.morph.language.is_ru)
                 and (isinstance(t, TextToken))):
             str0_ = t.term
             if (str0_ != "ЛЕТОМ" and str0_ != "ЛЕТА" and str0_ != "ЛЕТО"):
                 tok = (None)
         if (tok is not None):
             return DateItemToken._new629(
                 t, tok.end_token, DateItemToken.DateItemType.POINTER,
                 Utils.valToEnum(tok.termin.tag, DatePointerType))
         typ_ = DateItemToken.DateItemType.NUMBER
         if (npt.noun.is_value("КВАРТАЛ", None)):
             typ_ = DateItemToken.DateItemType.QUARTAL
         elif (npt.end_token.is_value("ПОЛУГОДИЕ", None)
               or npt.end_token.is_value("ПІВРІЧЧЯ", None)):
             typ_ = DateItemToken.DateItemType.HALFYEAR
         elif (npt.end_token.is_value("НАЧАЛО", None)
               or npt.end_token.is_value("ПОЧАТОК", None)):
             return DateItemToken._new635(
                 t, npt.end_token, DateItemToken.DateItemType.POINTER,
                 "начало")
         elif (npt.end_token.is_value("СЕРЕДИНА", None)):
             return DateItemToken._new635(
                 t, npt.end_token, DateItemToken.DateItemType.POINTER,
                 "середина")
         elif (npt.end_token.is_value("КОНЕЦ", None)
               or npt.end_token.is_value("КІНЕЦЬ", None)
               or npt.end_token.is_value("НАПРИКІНЕЦЬ", None)):
             return DateItemToken._new635(
                 t, npt.end_token, DateItemToken.DateItemType.POINTER,
                 "конец")
         elif (npt.end_token.is_value("ВРЕМЯ", None)
               and len(npt.adjectives) > 0
               and npt.end_token.previous.is_value("НАСТОЯЩЕЕ", None)):
             return DateItemToken._new635(
                 t, npt.end_token, DateItemToken.DateItemType.POINTER,
                 "сегодня")
         elif (npt.end_token.is_value("ЧАС", None)
               and len(npt.adjectives) > 0
               and npt.end_token.previous.is_value("ДАНИЙ", None)):
             return DateItemToken._new635(
                 t, npt.end_token, DateItemToken.DateItemType.POINTER,
                 "сегодня")
         if (typ_ != DateItemToken.DateItemType.NUMBER or detail_regime):
             delta = 0
             if (len(npt.adjectives) > 0):
                 if (npt.adjectives[0].is_value("ПОСЛЕДНИЙ", "ОСТАННІЙ")):
                     return DateItemToken._new629(
                         t0, npt.end_token, typ_,
                         (4 if typ_ == DateItemToken.DateItemType.QUARTAL
                          else 2))
                 if (npt.adjectives[0].is_value("ПРЕДЫДУЩИЙ", "ПОПЕРЕДНІЙ")
                         or npt.adjectives[0].is_value("ПРОШЛЫЙ", None)):
                     delta = -1
                 elif (npt.adjectives[0].is_value("СЛЕДУЮЩИЙ", None)
                       or npt.adjectives[0].is_value("ПОСЛЕДУЮЩИЙ", None)
                       or npt.adjectives[0].is_value("НАСТУПНИЙ", None)):
                     delta = 1
                 else:
                     return None
             cou = 0
             tt = t.previous
             first_pass3073 = True
             while True:
                 if first_pass3073: first_pass3073 = False
                 else: tt = tt.previous
                 if (not (tt is not None)): break
                 if (cou > 200):
                     break
                 dr = Utils.asObjectOrNull(tt.get_referent(),
                                           DateRangeReferent)
                 if (dr is None):
                     continue
                 if (typ_ == DateItemToken.DateItemType.QUARTAL):
                     ii = dr.quarter_number
                     if (ii < 1):
                         continue
                     ii += delta
                     if ((ii < 1) or ii > 4):
                         continue
                     return DateItemToken._new629(t0, npt.end_token, typ_,
                                                  ii)
                 if (typ_ == DateItemToken.DateItemType.HALFYEAR):
                     ii = dr.halfyear_number
                     if (ii < 1):
                         continue
                     ii += delta
                     if ((ii < 1) or ii > 2):
                         continue
                     return DateItemToken._new629(t0, npt.end_token, typ_,
                                                  ii)
     term = t0.term
     if (not str.isalnum(term[0])):
         if (t0.is_char_of(".\\/:") or t0.is_hiphen):
             return DateItemToken._new635(t0, t0,
                                          DateItemToken.DateItemType.DELIM,
                                          term)
         elif (t0.is_char(',')):
             return DateItemToken._new635(t0, t0,
                                          DateItemToken.DateItemType.DELIM,
                                          term)
         else:
             return None
     if (term == "O" or term == "О"):
         if ((isinstance(t.next0_, NumberToken))
                 and not t.is_whitespace_after
                 and len(t.next0_.value) == 1):
             return DateItemToken._new629(t, t.next0_,
                                          DateItemToken.DateItemType.NUMBER,
                                          t.next0_.int_value)
     if (str.isalpha(term[0])):
         inf = DateItemToken.M_MONTHES.try_parse(t, TerminParseAttr.NO)
         if (inf is not None and inf.termin.tag is None):
             inf = DateItemToken.M_MONTHES.try_parse(
                 inf.end_token.next0_, TerminParseAttr.NO)
         if (inf is not None and (isinstance(inf.termin.tag, int))):
             return DateItemToken._new653(inf.begin_token, inf.end_token,
                                          DateItemToken.DateItemType.MONTH,
                                          inf.termin.tag, inf.termin.lang)
     return None
Beispiel #8
0
 def try_attach_territory(
         li: typing.List['TerrItemToken'],
         ad: 'AnalyzerData',
         attach_always: bool = False,
         cits: typing.List['CityItemToken'] = None,
         exists: typing.List['GeoReferent'] = None) -> 'ReferentToken':
     if (li is None or len(li) == 0):
         return None
     ex_obj = None
     new_name = None
     adj_list = list()
     noun = None
     add_noun = None
     rt = TerrAttachHelper.__try_attach_moscowao(li, ad)
     if (rt is not None):
         return rt
     if (li[0].termin_item is not None
             and li[0].termin_item.canonic_text == "ТЕРРИТОРИЯ"):
         res2 = TerrAttachHelper.__try_attach_pure_terr(li, ad)
         return res2
     if (len(li) == 2):
         if (li[0].rzd is not None and li[1].rzd_dir is not None):
             rzd = GeoReferent()
             rzd._add_name(li[1].rzd_dir)
             rzd._add_typ_ter(li[0].kit.base_language)
             rzd.add_slot(GeoReferent.ATTR_REF, li[0].rzd.referent, False,
                          0)
             rzd.add_ext_referent(li[0].rzd)
             return ReferentToken(rzd, li[0].begin_token, li[1].end_token)
         if (li[1].rzd is not None and li[0].rzd_dir is not None):
             rzd = GeoReferent()
             rzd._add_name(li[0].rzd_dir)
             rzd._add_typ_ter(li[0].kit.base_language)
             rzd.add_slot(GeoReferent.ATTR_REF, li[1].rzd.referent, False,
                          0)
             rzd.add_ext_referent(li[1].rzd)
             return ReferentToken(rzd, li[0].begin_token, li[1].end_token)
     can_be_city_before = False
     adj_terr_before = False
     if (cits is not None):
         if (cits[0].typ == CityItemToken.ItemType.CITY):
             can_be_city_before = True
         elif (cits[0].typ == CityItemToken.ItemType.NOUN
               and len(cits) > 1):
             can_be_city_before = True
     k = 0
     k = 0
     while k < len(li):
         if (li[k].onto_item is not None):
             if (ex_obj is not None or new_name is not None):
                 break
             if (noun is not None):
                 if (k == 1):
                     if (noun.termin_item.canonic_text == "РАЙОН"
                             or noun.termin_item.canonic_text == "ОБЛАСТЬ"
                             or noun.termin_item.canonic_text == "СОЮЗ"):
                         if (isinstance(li[k].onto_item.referent,
                                        GeoReferent)):
                             if (li[k].onto_item.referent.is_state):
                                 break
                         ok = False
                         tt = li[k].end_token.next0_
                         if (tt is None):
                             ok = True
                         elif (tt.is_char_of(",.")):
                             ok = True
                         if (not ok):
                             ok = MiscLocationHelper.check_geo_object_before(
                                 li[0].begin_token)
                         if (not ok):
                             adr = AddressItemToken.try_parse(
                                 tt, None, False, False, None)
                             if (adr is not None):
                                 if (adr.typ ==
                                         AddressItemToken.ItemType.STREET):
                                     ok = True
                         if (not ok):
                             break
                     if (li[k].onto_item is not None):
                         if (noun.begin_token.is_value("МО", None)
                                 or noun.begin_token.is_value("ЛО", None)):
                             return None
             ex_obj = li[k]
         elif (li[k].termin_item is not None):
             if (noun is not None):
                 break
             if (li[k].termin_item.is_always_prefix and k > 0):
                 break
             if (k > 0 and li[k].is_doubt):
                 if (li[k].begin_token == li[k].end_token
                         and li[k].begin_token.is_value("ЗАО", None)):
                     break
             if (li[k].termin_item.is_adjective
                     or li[k].is_geo_in_dictionary):
                 adj_list.append(li[k])
             else:
                 if (ex_obj is not None):
                     geo_ = Utils.asObjectOrNull(ex_obj.onto_item.referent,
                                                 GeoReferent)
                     if (geo_ is None):
                         break
                     if (ex_obj.is_adjective and
                         ((li[k].termin_item.canonic_text == "СОЮЗ" or
                           li[k].termin_item.canonic_text == "ФЕДЕРАЦИЯ"))):
                         str0_ = str(ex_obj.onto_item)
                         if (not li[k].termin_item.canonic_text in str0_):
                             return None
                     if (li[k].termin_item.canonic_text == "РАЙОН"
                             or li[k].termin_item.canonic_text == "ОКРУГ"
                             or li[k].termin_item.canonic_text == "КРАЙ"):
                         tmp = io.StringIO()
                         for s in geo_.slots:
                             if (s.type_name == GeoReferent.ATTR_TYPE):
                                 print("{0};".format(s.value),
                                       end="",
                                       file=tmp,
                                       flush=True)
                         if (not li[k].termin_item.canonic_text
                                 in Utils.toStringStringIO(tmp).upper()):
                             if (k != 1 or new_name is not None):
                                 break
                             new_name = li[0]
                             new_name.is_adjective = True
                             new_name.onto_item = (None)
                             ex_obj = (None)
                 noun = li[k]
                 if (k == 0):
                     tt = TerrItemToken.try_parse(
                         li[k].begin_token.previous, None, True, False,
                         None)
                     if (tt is not None and tt.morph.class0_.is_adjective):
                         adj_terr_before = True
         else:
             if (ex_obj is not None):
                 break
             if (new_name is not None):
                 break
             new_name = li[k]
         k += 1
     name = None
     alt_name = None
     full_name = None
     morph_ = None
     if (ex_obj is not None):
         if (ex_obj.is_adjective and not ex_obj.morph.language.is_en
                 and noun is None):
             if (attach_always and ex_obj.end_token.next0_ is not None):
                 npt = NounPhraseHelper.try_parse(ex_obj.begin_token,
                                                  NounPhraseParseAttr.NO, 0,
                                                  None)
                 if (ex_obj.end_token.next0_.is_comma_and):
                     pass
                 elif (npt is None):
                     pass
                 else:
                     str0_ = StreetItemToken.try_parse(
                         ex_obj.end_token.next0_, None, False, None, False)
                     if (str0_ is not None):
                         if (str0_.typ == StreetItemType.NOUN
                                 and str0_.end_token == npt.end_token):
                             return None
             else:
                 cit = CityItemToken.try_parse(ex_obj.end_token.next0_,
                                               None, False, None)
                 if (cit is not None
                         and ((cit.typ == CityItemToken.ItemType.NOUN
                               or cit.typ == CityItemToken.ItemType.CITY))):
                     npt = NounPhraseHelper.try_parse(
                         ex_obj.begin_token, NounPhraseParseAttr.NO, 0,
                         None)
                     if (npt is not None
                             and npt.end_token == cit.end_token):
                         pass
                     else:
                         return None
                 elif (ex_obj.begin_token.is_value("ПОДНЕБЕСНЫЙ", None)):
                     pass
                 else:
                     return None
         if (noun is None and ex_obj.can_be_city):
             cit0 = CityItemToken.try_parse_back(
                 ex_obj.begin_token.previous)
             if (cit0 is not None
                     and cit0.typ != CityItemToken.ItemType.PROPERNAME):
                 return None
         if (ex_obj.is_doubt and noun is None):
             ok2 = False
             if (TerrAttachHelper.__can_be_geo_after(
                     ex_obj.end_token.next0_)):
                 ok2 = True
             elif (not ex_obj.can_be_surname and not ex_obj.can_be_city):
                 if ((ex_obj.end_token.next0_ is not None
                      and ex_obj.end_token.next0_.is_char(')')
                      and ex_obj.begin_token.previous is not None)
                         and ex_obj.begin_token.previous.is_char('(')):
                     ok2 = True
                 elif (ex_obj.chars.is_latin_letter
                       and ex_obj.begin_token.previous is not None):
                     if (ex_obj.begin_token.previous.is_value("IN", None)):
                         ok2 = True
                     elif (ex_obj.begin_token.previous.is_value(
                             "THE", None) and
                           ex_obj.begin_token.previous.previous is not None
                           and
                           ex_obj.begin_token.previous.previous.is_value(
                               "IN", None)):
                         ok2 = True
             if (not ok2):
                 cit0 = CityItemToken.try_parse_back(
                     ex_obj.begin_token.previous)
                 if (cit0 is not None
                         and cit0.typ != CityItemToken.ItemType.PROPERNAME):
                     pass
                 elif (MiscLocationHelper.check_geo_object_before(
                         ex_obj.begin_token.previous)):
                     pass
                 else:
                     return None
         name = ex_obj.onto_item.canonic_text
         morph_ = ex_obj.morph
     elif (new_name is not None):
         if (noun is None):
             return None
         j = 1
         while j < k:
             if (li[j].is_newline_before and not li[0].is_newline_before):
                 if (BracketHelper.can_be_start_of_sequence(
                         li[j].begin_token, False, False)):
                     pass
                 else:
                     return None
             j += 1
         morph_ = noun.morph
         if (new_name.is_adjective):
             if (noun.termin_item.acronym == "АО"):
                 if (noun.begin_token != noun.end_token):
                     return None
                 if (new_name.morph.gender != MorphGender.FEMINIE):
                     return None
             geo_before = None
             tt0 = li[0].begin_token.previous
             if (tt0 is not None and tt0.is_comma_and):
                 tt0 = tt0.previous
             if (not li[0].is_newline_before and tt0 is not None):
                 geo_before = (Utils.asObjectOrNull(tt0.get_referent(),
                                                    GeoReferent))
             if (Utils.indexOfList(li, noun, 0) < Utils.indexOfList(
                     li, new_name, 0)):
                 if (noun.termin_item.is_state):
                     return None
                 if (new_name.can_be_surname and geo_before is None):
                     if (((noun.morph.case_)
                          & new_name.morph.case_).is_undefined):
                         return None
                 if (MiscHelper.is_exists_in_dictionary(
                         new_name.begin_token, new_name.end_token,
                     (MorphClass.ADJECTIVE) | MorphClass.PRONOUN
                         | MorphClass.VERB)):
                     if (noun.begin_token != new_name.begin_token):
                         if (geo_before is None):
                             if (len(li) == 2 and
                                     TerrAttachHelper.__can_be_geo_after(
                                         li[1].end_token.next0_)):
                                 pass
                             elif (len(li) == 3
                                   and li[2].termin_item is not None
                                   and TerrAttachHelper.__can_be_geo_after(
                                       li[2].end_token.next0_)):
                                 pass
                             elif (new_name.is_geo_in_dictionary):
                                 pass
                             elif (new_name.end_token.is_newline_after):
                                 pass
                             else:
                                 return None
                 npt = NounPhraseHelper.try_parse(
                     new_name.end_token, NounPhraseParseAttr.PARSEPRONOUNS,
                     0, None)
                 if (npt is not None
                         and npt.end_token != new_name.end_token):
                     if (len(li) >= 3 and li[2].termin_item is not None
                             and npt.end_token == li[2].end_token):
                         add_noun = li[2]
                     else:
                         return None
                 rtp = new_name.kit.process_referent(
                     "PERSON", new_name.begin_token)
                 if (rtp is not None):
                     return None
                 name = ProperNameHelper.get_name_ex(
                     new_name.begin_token, new_name.end_token,
                     MorphClass.ADJECTIVE, MorphCase.UNDEFINED,
                     noun.termin_item.gender, False, False)
             else:
                 ok = False
                 if (((k + 1) < len(li)) and li[k].termin_item is None
                         and li[k + 1].termin_item is not None):
                     ok = True
                 elif ((k < len(li)) and li[k].onto_item is not None):
                     ok = True
                 elif (k == len(li) and not new_name.is_adj_in_dictionary):
                     ok = True
                 elif (MiscLocationHelper.check_geo_object_before(
                         li[0].begin_token) or can_be_city_before):
                     ok = True
                 elif (MiscLocationHelper.check_geo_object_after(
                         li[k - 1].end_token, False)):
                     ok = True
                 elif (len(li) == 3 and k == 2):
                     cit = CityItemToken.try_parse(li[2].begin_token, None,
                                                   False, None)
                     if (cit is not None):
                         if (cit.typ == CityItemToken.ItemType.CITY
                                 or cit.typ == CityItemToken.ItemType.NOUN):
                             ok = True
                 elif (len(li) == 2):
                     ok = TerrAttachHelper.__can_be_geo_after(
                         li[len(li) - 1].end_token.next0_)
                 if (not ok and not li[0].is_newline_before
                         and not li[0].chars.is_all_lower):
                     rt00 = li[0].kit.process_referent(
                         "PERSONPROPERTY", li[0].begin_token.previous)
                     if (rt00 is not None):
                         ok = True
                 if (noun.termin_item is not None
                         and noun.termin_item.is_strong
                         and new_name.is_adjective):
                     ok = True
                 if (noun.is_doubt and len(adj_list) == 0
                         and geo_before is None):
                     return None
                 name = ProperNameHelper.get_name_ex(
                     new_name.begin_token, new_name.end_token,
                     MorphClass.ADJECTIVE, MorphCase.UNDEFINED,
                     noun.termin_item.gender, False, False)
                 if (not ok and not attach_always):
                     if (MiscHelper.is_exists_in_dictionary(
                             new_name.begin_token, new_name.end_token,
                         (MorphClass.ADJECTIVE) | MorphClass.PRONOUN
                             | MorphClass.VERB)):
                         if (exists is not None):
                             for e0_ in exists:
                                 if (e0_.find_slot(GeoReferent.ATTR_NAME,
                                                   name, True) is not None):
                                     ok = True
                                     break
                         if (not ok):
                             return None
                 full_name = "{0} {1}".format(
                     ProperNameHelper.get_name_ex(li[0].begin_token,
                                                  noun.begin_token.previous,
                                                  MorphClass.ADJECTIVE,
                                                  MorphCase.UNDEFINED,
                                                  noun.termin_item.gender,
                                                  False, False),
                     noun.termin_item.canonic_text)
         else:
             if (not attach_always or
                 ((noun.termin_item is not None
                   and noun.termin_item.canonic_text == "ФЕДЕРАЦИЯ"))):
                 is_latin = noun.chars.is_latin_letter and new_name.chars.is_latin_letter
                 if (Utils.indexOfList(li, noun, 0) > Utils.indexOfList(
                         li, new_name, 0)):
                     if (not is_latin):
                         return None
                 if (not new_name.is_district_name
                         and not BracketHelper.can_be_start_of_sequence(
                             new_name.begin_token, False, False)):
                     if (len(adj_list) == 0
                             and MiscHelper.is_exists_in_dictionary(
                                 new_name.begin_token, new_name.end_token,
                                 (MorphClass.NOUN) | MorphClass.PRONOUN)):
                         if (len(li) == 2 and noun.is_city_region
                                 and (noun.whitespaces_after_count < 2)):
                             pass
                         else:
                             return None
                     if (not is_latin):
                         if ((noun.termin_item.is_region
                              and not attach_always and
                              ((not adj_terr_before or new_name.is_doubt)))
                                 and not noun.is_city_region and
                                 not noun.termin_item.is_specific_prefix):
                             if (not MiscLocationHelper.
                                     check_geo_object_before(
                                         noun.begin_token)):
                                 if (not noun.is_doubt and noun.begin_token
                                         != noun.end_token):
                                     pass
                                 elif ((noun.termin_item.is_always_prefix
                                        and len(li) == 2 and li[0] == noun)
                                       and li[1] == new_name):
                                     pass
                                 else:
                                     return None
                         if (noun.is_doubt and len(adj_list) == 0):
                             if (noun.termin_item.acronym == "МО"
                                     or noun.termin_item.acronym == "ЛО"):
                                 if (k == (len(li) - 1)
                                         and li[k].termin_item is not None):
                                     add_noun = li[k]
                                     k += 1
                                 elif (len(li) == 2 and noun == li[0]
                                       and str(new_name).endswith("совет")):
                                     pass
                                 else:
                                     return None
                             else:
                                 return None
                         pers = new_name.kit.process_referent(
                             "PERSON", new_name.begin_token)
                         if (pers is not None):
                             return None
             name = MiscHelper.get_text_value(new_name.begin_token,
                                              new_name.end_token,
                                              GetTextAttr.NO)
             if (new_name.begin_token != new_name.end_token):
                 ttt = new_name.begin_token.next0_
                 while ttt is not None and ttt.end_char <= new_name.end_char:
                     if (ttt.chars.is_letter):
                         ty = TerrItemToken.try_parse(
                             ttt, None, False, False, None)
                         if ((ty is not None and ty.termin_item is not None
                              and noun is not None)
                                 and ((noun.termin_item.canonic_text
                                       in ty.termin_item.canonic_text
                                       or ty.termin_item.canonic_text
                                       in noun.termin_item.canonic_text))):
                             name = MiscHelper.get_text_value(
                                 new_name.begin_token, ttt.previous,
                                 GetTextAttr.NO)
                             break
                     ttt = ttt.next0_
             if (len(adj_list) > 0):
                 npt = NounPhraseHelper.try_parse(adj_list[0].begin_token,
                                                  NounPhraseParseAttr.NO, 0,
                                                  None)
                 if (npt is not None and npt.end_token == noun.end_token):
                     alt_name = "{0} {1}".format(
                         npt.get_normal_case_text(None,
                                                  MorphNumber.UNDEFINED,
                                                  MorphGender.UNDEFINED,
                                                  False), name)
     else:
         if ((len(li) == 1 and noun is not None
              and noun.end_token.next0_ is not None) and (isinstance(
                  noun.end_token.next0_.get_referent(), GeoReferent))):
             g = Utils.asObjectOrNull(noun.end_token.next0_.get_referent(),
                                      GeoReferent)
             if (noun.termin_item is not None):
                 tyy = noun.termin_item.canonic_text.lower()
                 ooo = False
                 if (g.find_slot(GeoReferent.ATTR_TYPE, tyy, True)
                         is not None):
                     ooo = True
                 elif (tyy.endswith("район") and g.find_slot(
                         GeoReferent.ATTR_TYPE, "район", True) is not None):
                     ooo = True
                 if (ooo):
                     return ReferentToken._new734(g, noun.begin_token,
                                                  noun.end_token.next0_,
                                                  noun.begin_token.morph)
         if ((len(li) == 1 and noun == li[0]
              and li[0].termin_item is not None)
                 and TerrItemToken.try_parse(li[0].end_token.next0_, None,
                                             True, False, None) is None and
                 TerrItemToken.try_parse(li[0].begin_token.previous, None,
                                         True, False, None) is None):
             if (li[0].morph.number == MorphNumber.PLURAL):
                 return None
             cou = 0
             str0_ = li[0].termin_item.canonic_text.lower()
             tt = li[0].begin_token.previous
             first_pass3158 = True
             while True:
                 if first_pass3158: first_pass3158 = False
                 else: tt = tt.previous
                 if (not (tt is not None)): break
                 if (tt.is_newline_after):
                     cou += 10
                 else:
                     cou += 1
                 if (cou > 500):
                     break
                 g = Utils.asObjectOrNull(tt.get_referent(), GeoReferent)
                 if (g is None):
                     continue
                 ok = True
                 cou = 0
                 tt = li[0].end_token.next0_
                 first_pass3159 = True
                 while True:
                     if first_pass3159: first_pass3159 = False
                     else: tt = tt.next0_
                     if (not (tt is not None)): break
                     if (tt.is_newline_before):
                         cou += 10
                     else:
                         cou += 1
                     if (cou > 500):
                         break
                     tee = TerrItemToken.try_parse(tt, None, True, False,
                                                   None)
                     if (tee is None):
                         continue
                     ok = False
                     break
                 if (ok):
                     ii = 0
                     while g is not None and (ii < 3):
                         if (g.find_slot(GeoReferent.ATTR_TYPE, str0_, True)
                                 is not None):
                             return ReferentToken._new734(
                                 g, li[0].begin_token, li[0].end_token,
                                 noun.begin_token.morph)
                         g = g.higher
                         ii += 1
                 break
         return None
     ter = None
     if (ex_obj is not None and (isinstance(ex_obj.tag, GeoReferent))):
         ter = (Utils.asObjectOrNull(ex_obj.tag, GeoReferent))
     else:
         ter = GeoReferent()
         if (ex_obj is not None):
             geo_ = Utils.asObjectOrNull(ex_obj.onto_item.referent,
                                         GeoReferent)
             if (geo_ is not None and not geo_.is_city):
                 ter._merge_slots2(geo_, li[0].kit.base_language)
             else:
                 ter._add_name(name)
             if (noun is None and ex_obj.can_be_city):
                 ter._add_typ_city(li[0].kit.base_language)
             else:
                 pass
         elif (new_name is not None):
             ter._add_name(name)
             if (alt_name is not None):
                 ter._add_name(alt_name)
         if (noun is not None):
             if (noun.termin_item.canonic_text == "АО"):
                 ter._add_typ(
                     ("АВТОНОМНИЙ ОКРУГ" if li[0].kit.base_language.is_ua
                      else "АВТОНОМНЫЙ ОКРУГ"))
             elif (noun.termin_item.canonic_text == "МУНИЦИПАЛЬНОЕ СОБРАНИЕ"
                   or noun.termin_item.canonic_text
                   == "МУНІЦИПАЛЬНЕ ЗБОРИ"):
                 ter._add_typ(("МУНІЦИПАЛЬНЕ УТВОРЕННЯ"
                               if li[0].kit.base_language.is_ua else
                               "МУНИЦИПАЛЬНОЕ ОБРАЗОВАНИЕ"))
             elif (noun.termin_item.acronym == "МО"
                   and add_noun is not None):
                 ter._add_typ(add_noun.termin_item.canonic_text)
             else:
                 if (noun.termin_item.canonic_text == "СОЮЗ"
                         and ex_obj is not None
                         and ex_obj.end_char > noun.end_char):
                     return ReferentToken._new734(ter, ex_obj.begin_token,
                                                  ex_obj.end_token,
                                                  ex_obj.morph)
                 ter._add_typ(noun.termin_item.canonic_text)
                 if (noun.termin_item.is_region and ter.is_state):
                     ter._add_typ_reg(li[0].kit.base_language)
         if (ter.is_state and ter.is_region):
             for a in adj_list:
                 if (a.termin_item.is_region):
                     ter._add_typ_reg(li[0].kit.base_language)
                     break
         if (ter.is_state):
             if (full_name is not None):
                 ter._add_name(full_name)
     res = ReferentToken(ter, li[0].begin_token, li[k - 1].end_token)
     if (noun is not None and noun.morph.class0_.is_noun):
         res.morph = noun.morph
     else:
         res.morph = MorphCollection()
         ii = 0
         while ii < k:
             for v in li[ii].morph.items:
                 bi = MorphBaseInfo()
                 bi.copy_from(v)
                 if (noun is not None):
                     if (bi.class0_.is_adjective):
                         bi.class0_ = MorphClass.NOUN
                 res.morph.add_item(bi)
             ii += 1
     if (li[0].termin_item is not None
             and li[0].termin_item.is_specific_prefix):
         res.begin_token = li[0].end_token.next0_
     if (add_noun is not None and add_noun.end_char > res.end_char):
         res.end_token = add_noun.end_token
     if ((isinstance(res.begin_token.previous, TextToken))
             and (res.whitespaces_before_count < 2)):
         tt = Utils.asObjectOrNull(res.begin_token.previous, TextToken)
         if (tt.term == "АР"):
             for ty in ter.typs:
                 if ("республика" in ty or "республіка" in ty):
                     res.begin_token = tt
                     break
     return res
Beispiel #9
0
 def try_attach(t : 'Token', p1 : 'InstrumentParticipantReferent'=None, p2 : 'InstrumentParticipantReferent'=None, is_contract : bool=False) -> 'ParticipantToken':
     if (t is None): 
         return None
     tt = t
     br = False
     if (p1 is None and p2 is None and is_contract): 
         r1 = t.get_referent()
         if ((r1 is not None and t.next0_ is not None and t.next0_.is_comma_and) and (isinstance(t.next0_.next0_, ReferentToken))): 
             r2 = t.next0_.next0_.get_referent()
             if (r1.type_name == r2.type_name): 
                 ttt = t.next0_.next0_.next0_
                 refs = list()
                 refs.append(r1)
                 refs.append(r2)
                 first_pass3282 = True
                 while True:
                     if first_pass3282: first_pass3282 = False
                     else: ttt = ttt.next0_
                     if (not (ttt is not None)): break
                     if ((ttt.is_comma_and and ttt.next0_ is not None and ttt.next0_.get_referent() is not None) and ttt.next0_.get_referent().type_name == r1.type_name): 
                         ttt = ttt.next0_
                         if (not ttt.get_referent() in refs): 
                             refs.append(ttt.get_referent())
                         continue
                     break
                 first_pass3283 = True
                 while True:
                     if first_pass3283: first_pass3283 = False
                     else: ttt = ttt.next0_
                     if (not (ttt is not None)): break
                     if (ttt.is_comma or ttt.morph.class0_.is_preposition): 
                         continue
                     if ((ttt.is_value("ИМЕНОВАТЬ", None) or ttt.is_value("ДАЛЬНЕЙШИЙ", None) or ttt.is_value("ДАЛЕЕ", None)) or ttt.is_value("ТЕКСТ", None)): 
                         continue
                     if (ttt.is_value("ДОГОВАРИВАТЬСЯ", None)): 
                         continue
                     npt = NounPhraseHelper.try_parse(ttt, NounPhraseParseAttr.NO, 0, None)
                     if (npt is not None and npt.noun.is_value("СТОРОНА", None) and npt.morph.number != MorphNumber.SINGULAR): 
                         re = ParticipantToken._new1573(t, npt.end_token, ParticipantToken.Kinds.NAMEDASPARTS)
                         re.parts = refs
                         return re
                     break
         if ((isinstance(r1, OrganizationReferent)) or (isinstance(r1, PersonReferent))): 
             has_br = False
             has_named = False
             if (isinstance(r1, PersonReferent)): 
                 if (t.previous is not None and t.previous.is_value("ЛИЦО", None)): 
                     return None
             elif (t.previous is not None and ((t.previous.is_value("ВЫДАВАТЬ", None) or t.previous.is_value("ВЫДАТЬ", None)))): 
                 return None
             ttt = t.begin_token
             while ttt is not None and (ttt.end_char < t.end_char): 
                 if (ttt.is_char('(')): 
                     has_br = True
                 elif ((ttt.is_value("ИМЕНОВАТЬ", None) or ttt.is_value("ДАЛЬНЕЙШИЙ", None) or ttt.is_value("ДАЛЕЕ", None)) or ttt.is_value("ТЕКСТ", None)): 
                     has_named = True
                 elif ((ttt.is_comma or ttt.morph.class0_.is_preposition or ttt.is_hiphen) or ttt.is_char(':')): 
                     pass
                 elif (isinstance(ttt, ReferentToken)): 
                     pass
                 elif (has_br or has_named): 
                     npt = NounPhraseHelper.try_parse(ttt, NounPhraseParseAttr.REFERENTCANBENOUN, 0, None)
                     if (npt is None): 
                         break
                     if (has_br): 
                         if (npt.end_token.next0_ is None or not npt.end_token.next0_.is_char(')')): 
                             break
                     if (not has_named): 
                         if (ParticipantToken.M_ONTOLOGY.try_parse(ttt, TerminParseAttr.NO) is None): 
                             break
                     re = ParticipantToken._new1573(t, t, ParticipantToken.Kinds.NAMEDAS)
                     re.typ = npt.get_normal_case_text(None, MorphNumber.SINGULAR, MorphGender.UNDEFINED, False)
                     re.parts = list()
                     re.parts.append(r1)
                     return re
                 ttt = ttt.next0_
             has_br = False
             has_named = False
             end_side = None
             brr = None
             add_refs = None
             ttt = t.next0_
             first_pass3284 = True
             while True:
                 if first_pass3284: first_pass3284 = False
                 else: ttt = ttt.next0_
                 if (not (ttt is not None)): break
                 if ((isinstance(ttt, NumberToken)) and (isinstance(ttt.next0_, TextToken)) and ttt.next0_.term == "СТОРОНЫ"): 
                     ttt = ttt.next0_
                     end_side = ttt
                     if (ttt.next0_ is not None and ttt.next0_.is_comma): 
                         ttt = ttt.next0_
                     if (ttt.next0_ is not None and ttt.next0_.is_and): 
                         break
                 if (brr is not None and ttt.begin_char > brr.end_char): 
                     brr = (None)
                 if (BracketHelper.can_be_start_of_sequence(ttt, False, False)): 
                     brr = BracketHelper.try_parse(ttt, BracketParseAttr.NO, 100)
                     if (brr is not None and (brr.length_char < 7) and ttt.is_char('(')): 
                         ttt = brr.end_token
                         brr = (None)
                         continue
                 elif ((ttt.is_value("ИМЕНОВАТЬ", None) or ttt.is_value("ДАЛЬНЕЙШИЙ", None) or ttt.is_value("ДАЛЕЕ", None)) or ttt.is_value("ТЕКСТ", None)): 
                     has_named = True
                 elif ((ttt.is_comma or ttt.morph.class0_.is_preposition or ttt.is_hiphen) or ttt.is_char(':')): 
                     pass
                 elif (brr is not None or has_named): 
                     if (BracketHelper.can_be_start_of_sequence(ttt, True, False)): 
                         ttt = ttt.next0_
                     npt = NounPhraseHelper.try_parse(ttt, NounPhraseParseAttr.REFERENTCANBENOUN, 0, None)
                     typ22 = None
                     if (npt is not None): 
                         ttt = npt.end_token
                         if (npt.end_token.is_value("ДОГОВОР", None)): 
                             continue
                     else: 
                         ttok = None
                         if (isinstance(ttt, MetaToken)): 
                             ttok = ParticipantToken.M_ONTOLOGY.try_parse(ttt.begin_token, TerminParseAttr.NO)
                         if (ttok is not None): 
                             typ22 = ttok.termin.canonic_text
                         elif (has_named and ttt.morph.class0_.is_adjective): 
                             typ22 = ttt.get_normal_case_text(MorphClass.ADJECTIVE, MorphNumber.UNDEFINED, MorphGender.UNDEFINED, False)
                         elif (brr is not None): 
                             continue
                         else: 
                             break
                     if (BracketHelper.can_be_end_of_sequence(ttt.next0_, True, None, False)): 
                         ttt = ttt.next0_
                     if (brr is not None): 
                         if (ttt.next0_ is None): 
                             ttt = brr.end_token
                             continue
                         ttt = ttt.next0_
                     if (not has_named and typ22 is None): 
                         if (ParticipantToken.M_ONTOLOGY.try_parse(npt.begin_token, TerminParseAttr.NO) is None): 
                             break
                     re = ParticipantToken._new1573(t, ttt, ParticipantToken.Kinds.NAMEDAS)
                     re.typ = (Utils.ifNotNull(typ22, npt.get_normal_case_text(None, MorphNumber.SINGULAR, MorphGender.UNDEFINED, False)))
                     re.parts = list()
                     re.parts.append(r1)
                     return re
                 elif ((ttt.is_value("ЗАРЕГИСТРИРОВАННЫЙ", None) or ttt.is_value("КАЧЕСТВО", None) or ttt.is_value("ПРОЖИВАЮЩИЙ", None)) or ttt.is_value("ЗАРЕГ", None)): 
                     pass
                 elif (ttt.get_referent() == r1): 
                     pass
                 elif ((isinstance(ttt.get_referent(), PersonIdentityReferent)) or (isinstance(ttt.get_referent(), AddressReferent))): 
                     if (add_refs is None): 
                         add_refs = list()
                     add_refs.append(ttt.get_referent())
                 else: 
                     prr = ttt.kit.process_referent("PERSONPROPERTY", ttt)
                     if (prr is not None): 
                         ttt = prr.end_token
                         continue
                     if (isinstance(ttt.get_referent(), GeoReferent)): 
                         continue
                     npt = NounPhraseHelper.try_parse(ttt, NounPhraseParseAttr.NO, 0, None)
                     if (npt is not None): 
                         if ((npt.noun.is_value("МЕСТО", None) or npt.noun.is_value("ЖИТЕЛЬСТВО", None) or npt.noun.is_value("ПРЕДПРИНИМАТЕЛЬ", None)) or npt.noun.is_value("ПОЛ", None) or npt.noun.is_value("РОЖДЕНИЕ", None)): 
                             ttt = npt.end_token
                             continue
                     if (ttt.is_newline_before): 
                         break
                     if (ttt.length_char < 3): 
                         continue
                     mc = ttt.get_morph_class_in_dictionary()
                     if (mc.is_adverb or mc.is_adjective): 
                         continue
                     if (ttt.chars.is_all_upper): 
                         continue
                     break
             if (end_side is not None or ((add_refs is not None and t.previous is not None and t.previous.is_and))): 
                 re = ParticipantToken._new1573(t, Utils.ifNotNull(end_side, t), ParticipantToken.Kinds.NAMEDAS)
                 re.typ = (None)
                 re.parts = list()
                 re.parts.append(r1)
                 if (add_refs is not None): 
                     re.parts.extend(add_refs)
                 return re
         too = ParticipantToken.M_ONTOLOGY.try_parse(t, TerminParseAttr.NO)
         if (too is not None): 
             if ((isinstance(t.previous, TextToken)) and t.previous.is_value("ЛИЦО", None)): 
                 too = (None)
         if (too is not None and too.termin.tag is not None and too.termin.canonic_text != "СТОРОНА"): 
             tt1 = too.end_token.next0_
             if (tt1 is not None): 
                 if (tt1.is_hiphen or tt1.is_char(':')): 
                     tt1 = tt1.next0_
             if (isinstance(tt1, ReferentToken)): 
                 r1 = tt1.get_referent()
                 if ((isinstance(r1, PersonReferent)) or (isinstance(r1, OrganizationReferent))): 
                     re = ParticipantToken._new1573(t, tt1, ParticipantToken.Kinds.NAMEDAS)
                     re.typ = too.termin.canonic_text
                     re.parts = list()
                     re.parts.append(r1)
                     return re
     add_typ1 = (None if p1 is None else p1.typ)
     add_typ2 = (None if p2 is None else p2.typ)
     if (BracketHelper.can_be_start_of_sequence(tt, False, False) and tt.next0_ is not None): 
         br = True
         tt = tt.next0_
     term1 = None
     term2 = None
     if (add_typ1 is not None and add_typ1.find(' ') > 0 and not add_typ1.startswith("СТОРОНА")): 
         term1 = Termin(add_typ1)
     if (add_typ2 is not None and add_typ2.find(' ') > 0 and not add_typ2.startswith("СТОРОНА")): 
         term2 = Termin(add_typ2)
     named = False
     typ_ = None
     t1 = None
     t0 = tt
     first_pass3285 = True
     while True:
         if first_pass3285: first_pass3285 = False
         else: tt = tt.next0_
         if (not (tt is not None)): break
         if (tt.morph.class0_.is_preposition and typ_ is not None): 
             continue
         if (tt.is_char_of("(:)") or tt.is_hiphen): 
             continue
         if (tt.is_table_control_char): 
             break
         if (tt.is_newline_before and tt != t0): 
             if (isinstance(tt, NumberToken)): 
                 break
             if ((isinstance(tt, TextToken)) and (isinstance(tt.previous, TextToken))): 
                 if (tt.previous.is_value(tt.term, None)): 
                     break
         if (BracketHelper.is_bracket(tt, False)): 
             continue
         tok = (ParticipantToken.M_ONTOLOGY.try_parse(tt, TerminParseAttr.NO) if ParticipantToken.M_ONTOLOGY is not None else None)
         if (tok is not None and (isinstance(tt.previous, TextToken))): 
             if (tt.previous.is_value("ЛИЦО", None)): 
                 return None
         if (tok is None): 
             if (add_typ1 is not None and ((MiscHelper.is_not_more_than_one_error(add_typ1, tt) or (((isinstance(tt, MetaToken)) and tt.begin_token.is_value(add_typ1, None)))))): 
                 if (typ_ is not None): 
                     if (not ParticipantToken.__is_types_equal(add_typ1, typ_)): 
                         break
                 typ_ = add_typ1
                 t1 = tt
                 continue
             if (add_typ2 is not None and ((MiscHelper.is_not_more_than_one_error(add_typ2, tt) or (((isinstance(tt, MetaToken)) and tt.begin_token.is_value(add_typ2, None)))))): 
                 if (typ_ is not None): 
                     if (not ParticipantToken.__is_types_equal(add_typ2, typ_)): 
                         break
                 typ_ = add_typ2
                 t1 = tt
                 continue
             if (tt.chars.is_letter): 
                 if (term1 is not None): 
                     tok1 = term1.try_parse(tt, TerminParseAttr.NO)
                     if (tok1 is not None): 
                         if (typ_ is not None): 
                             if (not ParticipantToken.__is_types_equal(add_typ1, typ_)): 
                                 break
                         typ_ = add_typ1
                         tt = tok1.end_token
                         t1 = tt
                         continue
                 if (term2 is not None): 
                     tok2 = term2.try_parse(tt, TerminParseAttr.NO)
                     if (tok2 is not None): 
                         if (typ_ is not None): 
                             if (not ParticipantToken.__is_types_equal(add_typ2, typ_)): 
                                 break
                         typ_ = add_typ2
                         tt = tok2.end_token
                         t1 = tt
                         continue
                 if (named and tt.get_morph_class_in_dictionary().is_noun): 
                     if (not tt.chars.is_all_lower or BracketHelper.is_bracket(tt.previous, True)): 
                         if (DecreeToken.is_keyword(tt, False) is None): 
                             val = tt.get_normal_case_text(MorphClass.NOUN, MorphNumber.SINGULAR, MorphGender.UNDEFINED, False)
                             if (typ_ is not None): 
                                 if (not ParticipantToken.__is_types_equal(typ_, val)): 
                                     break
                             typ_ = val
                             t1 = tt
                             continue
             if (named and typ_ is None and is_contract): 
                 if ((isinstance(tt, TextToken)) and tt.chars.is_cyrillic_letter and tt.chars.is_capital_upper): 
                     dc = tt.get_morph_class_in_dictionary()
                     if (dc.is_undefined or dc.is_noun): 
                         dt = DecreeToken.try_attach(tt, None, False)
                         ok = True
                         if (dt is not None): 
                             ok = False
                         elif (tt.is_value("СТОРОНА", None)): 
                             ok = False
                         if (ok): 
                             typ_ = tt.lemma
                             t1 = tt
                             continue
                     if (dc.is_adjective): 
                         npt = NounPhraseHelper.try_parse(tt, NounPhraseParseAttr.NO, 0, None)
                         if (npt is not None and len(npt.adjectives) > 0 and npt.noun.get_morph_class_in_dictionary().is_noun): 
                             typ_ = npt.get_normal_case_text(None, MorphNumber.SINGULAR, MorphGender.UNDEFINED, False)
                             t1 = npt.end_token
                             continue
             if (tt == t): 
                 break
             if ((isinstance(tt, NumberToken)) or tt.is_char('.')): 
                 break
             if (tt.length_char < 4): 
                 if (typ_ is not None): 
                     continue
             break
         if (tok.termin.tag is None): 
             named = True
         else: 
             if (typ_ is not None): 
                 break
             if (tok.termin.canonic_text == "СТОРОНА"): 
                 tt1 = tt.next0_
                 if (tt1 is not None and tt1.is_hiphen): 
                     tt1 = tt1.next0_
                 if (not (isinstance(tt1, NumberToken))): 
                     break
                 if (tt1.is_newline_before): 
                     break
                 typ_ = "{0} {1}".format(tok.termin.canonic_text, tt1.value)
                 t1 = tt1
             else: 
                 typ_ = tok.termin.canonic_text
                 t1 = tok.end_token
             break
         tt = tok.end_token
     if (typ_ is None): 
         return None
     if (not named and t1 != t and not typ_.startswith("СТОРОНА")): 
         if (not ParticipantToken.__is_types_equal(typ_, add_typ1) and not ParticipantToken.__is_types_equal(typ_, add_typ2)): 
             return None
     if (BracketHelper.can_be_end_of_sequence(t1.next0_, False, None, False)): 
         t1 = t1.next0_
         if (not t.is_whitespace_before and BracketHelper.can_be_start_of_sequence(t.previous, False, False)): 
             t = t.previous
     elif (BracketHelper.can_be_start_of_sequence(t, False, False) and BracketHelper.can_be_end_of_sequence(t1.next0_, True, t, True)): 
         t1 = t1.next0_
     if (br and t1.next0_ is not None and BracketHelper.can_be_end_of_sequence(t1.next0_, False, None, False)): 
         t1 = t1.next0_
     res = ParticipantToken._new1578(t, t1, (ParticipantToken.Kinds.NAMEDAS if named else ParticipantToken.Kinds.PURE), typ_)
     if (t.is_char(':')): 
         res.begin_token = t.next0_
     return res
 def try_attach(t: 'Token',
                prev: typing.List['DateItemToken'],
                detail_regime: bool = False) -> 'DateItemToken':
     if (t is None):
         return None
     t0 = t
     if (t0.is_char('_')):
         t = t.next0_
         while t is not None:
             if (t.is_newline_before):
                 return None
             if (not t.is_char('_')):
                 break
             t = t.next0_
     elif (BracketHelper.can_be_start_of_sequence(t0, True, False)):
         ok = False
         t = t.next0_
         while t is not None:
             if (BracketHelper.can_be_end_of_sequence(t, True, t0, False)):
                 ok = True
                 break
             elif (not t.is_char('_')):
                 break
             t = t.next0_
         if (not ok):
             t = t0
         else:
             t = t.next0_
             while t is not None:
                 if (not t.is_char('_')):
                     break
                 t = t.next0_
     elif ((isinstance(t0, TextToken)) and t0.is_value("THE", None)):
         res0 = DateItemToken.__try_attach(t.next0_, prev, detail_regime)
         if (res0 is not None):
             res0.begin_token = t
             return res0
     res = DateItemToken.__try_attach(t, prev, detail_regime)
     if (res is None):
         return None
     res.begin_token = t0
     if (not res.is_whitespace_after and res.end_token.next0_ is not None
             and res.end_token.next0_.is_char('_')):
         t = res.end_token.next0_
         while t is not None:
             if (not t.is_char('_')):
                 break
             else:
                 res.end_token = t
             t = t.next0_
     if (res.typ == DateItemToken.DateItemType.YEAR
             or res.typ == DateItemToken.DateItemType.CENTURY
             or res.typ == DateItemToken.DateItemType.NUMBER):
         tok = None
         ii = 0
         t = res.end_token.next0_
         if (t is not None and t.is_value("ДО", None)):
             tok = DateItemToken.M_NEW_AGE.try_parse(
                 t.next0_, TerminParseAttr.NO)
             ii = -1
         elif (t is not None and t.is_value("ОТ", "ВІД")):
             tok = DateItemToken.M_NEW_AGE.try_parse(
                 t.next0_, TerminParseAttr.NO)
             ii = 1
         else:
             tok = DateItemToken.M_NEW_AGE.try_parse(t, TerminParseAttr.NO)
             ii = 1
         if (tok is not None):
             res.new_age = (-1 if ii < 0 else 1)
             res.end_token = tok.end_token
             if (res.typ == DateItemToken.DateItemType.NUMBER):
                 res.typ = DateItemToken.DateItemType.YEAR
     return res
Beispiel #11
0
 def _process(begin : 'Token', max_char_pos : int, kit : 'AnalysisKit', end_token : 'Token') -> 'TitlePageReferent':
     end_token.value = begin
     res = TitlePageReferent()
     term = None
     lines = Line.parse(begin, 30, 1500, max_char_pos)
     if (len(lines) < 1): 
         return None
     cou = len(lines)
     min_newlines_count = 10
     lines_count_stat = dict()
     i = 0
     while i < len(lines): 
         if (TitleNameToken.can_be_start_of_text_or_content(lines[i].begin_token, lines[i].end_token)): 
             cou = i
             break
         j = lines[i].newlines_before_count
         if (i > 0 and j > 0): 
             if (not j in lines_count_stat): 
                 lines_count_stat[j] = 1
             else: 
                 lines_count_stat[j] += 1
         i += 1
     max0_ = 0
     for kp in lines_count_stat.items(): 
         if (kp[1] > max0_): 
             max0_ = kp[1]
             min_newlines_count = kp[0]
     end_char = (lines[cou - 1].end_char if cou > 0 else 0)
     if (max_char_pos > 0 and end_char > max_char_pos): 
         end_char = max_char_pos
     names = list()
     i = 0
     while i < cou: 
         if (i == 6): 
             pass
         j = i
         while (j < cou) and (j < (i + 5)): 
             if (i == 6 and j == 8): 
                 pass
             if (j > i): 
                 if (lines[j - 1].is_pure_en and lines[j].is_pure_ru): 
                     break
                 if (lines[j - 1].is_pure_ru and lines[j].is_pure_en): 
                     break
                 if (lines[j].newlines_before_count >= (min_newlines_count * 2)): 
                     break
             ttt = TitleNameToken.try_parse(lines[i].begin_token, lines[j].end_token, min_newlines_count)
             if (ttt is not None): 
                 if (lines[i].is_pure_en): 
                     ttt.morph.language = MorphLang.EN
                 elif (lines[i].is_pure_ru): 
                     ttt.morph.language = MorphLang.RU
                 names.append(ttt)
             j += 1
         i += 1
     TitleNameToken.sort(names)
     name_rt = None
     if (len(names) > 0): 
         i0 = 0
         if (names[i0].morph.language.is_en): 
             ii = 1
             while ii < len(names): 
                 if (names[ii].morph.language.is_ru and names[ii].rank > 0): 
                     i0 = ii
                     break
                 ii += 1
         term = res._add_name(names[i0].begin_name_token, names[i0].end_name_token)
         if (names[i0].type_value is not None): 
             res._add_type(names[i0].type_value)
         if (names[i0].speciality is not None): 
             res.speciality = names[i0].speciality
         rt = ReferentToken(res, names[i0].begin_token, names[i0].end_token)
         if (kit is not None): 
             kit.embed_token(rt)
         else: 
             res.add_occurence(TextAnnotation(rt.begin_token, rt.end_token))
         end_token.value = rt.end_token
         name_rt = rt
         if (begin.begin_char == rt.begin_char): 
             begin = (rt)
     if (term is not None and kit is not None): 
         t = kit.first_token
         first_pass3397 = True
         while True:
             if first_pass3397: first_pass3397 = False
             else: t = t.next0_
             if (not (t is not None)): break
             tok = term.try_parse(t, TerminParseAttr.NO)
             if (tok is None): 
                 continue
             t0 = t
             t1 = tok.end_token
             if (t1.next0_ is not None and t1.next0_.is_char('.')): 
                 t1 = t1.next0_
             if (BracketHelper.can_be_start_of_sequence(t0.previous, False, False) and BracketHelper.can_be_end_of_sequence(t1.next0_, False, None, False)): 
                 t0 = t0.previous
                 t1 = t1.next0_
             rt = ReferentToken(res, t0, t1)
             kit.embed_token(rt)
             t = (rt)
     pr = PersonRelations()
     pers_typ = TitleItemToken.Types.UNDEFINED
     pers_types = pr.rel_types
     t = begin
     first_pass3398 = True
     while True:
         if first_pass3398: first_pass3398 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (max_char_pos > 0 and t.begin_char > max_char_pos): 
             break
         if (t == name_rt): 
             continue
         tpt = TitleItemToken.try_attach(t)
         if (tpt is not None): 
             pers_typ = TitleItemToken.Types.UNDEFINED
             if (tpt.typ == TitleItemToken.Types.TYP): 
                 if (len(res.types) == 0): 
                     res._add_type(tpt.value)
                 elif (len(res.types) == 1): 
                     ty = res.types[0].upper()
                     if (ty == "РЕФЕРАТ"): 
                         res._add_type(tpt.value)
                     elif (ty == "АВТОРЕФЕРАТ"): 
                         if (tpt.value == "КАНДИДАТСКАЯ ДИССЕРТАЦИЯ"): 
                             res.add_slot(TitlePageReferent.ATTR_TYPE, "автореферат кандидатской диссертации", True, 0)
                         elif (tpt.value == "ДОКТОРСКАЯ ДИССЕРТАЦИЯ"): 
                             res.add_slot(TitlePageReferent.ATTR_TYPE, "автореферат докторской диссертации", True, 0)
                         elif (tpt.value == "МАГИСТЕРСКАЯ ДИССЕРТАЦИЯ"): 
                             res.add_slot(TitlePageReferent.ATTR_TYPE, "автореферат магистерской диссертации", True, 0)
                         elif (tpt.value == "КАНДИДАТСЬКА ДИСЕРТАЦІЯ"): 
                             res.add_slot(TitlePageReferent.ATTR_TYPE, "автореферат кандидатської дисертації", True, 0)
                         elif (tpt.value == "ДОКТОРСЬКА ДИСЕРТАЦІЯ"): 
                             res.add_slot(TitlePageReferent.ATTR_TYPE, "автореферат докторської дисертації", True, 0)
                         elif (tpt.value == "МАГІСТЕРСЬКА ДИСЕРТАЦІЯ"): 
                             res.add_slot(TitlePageReferent.ATTR_TYPE, "автореферат магістерської дисертації", True, 0)
                         else: 
                             res._add_type(tpt.value)
                     elif (tpt.value == "РЕФЕРАТ" or tpt.value == "АВТОРЕФЕРАТ"): 
                         if (not tpt.value in ty): 
                             res._add_type(tpt.value)
             elif (tpt.typ == TitleItemToken.Types.SPECIALITY): 
                 if (res.speciality is None): 
                     res.speciality = tpt.value
             elif (tpt.typ in pers_types): 
                 pers_typ = tpt.typ
             t = tpt.end_token
             if (t.end_char > end_token.value.end_char): 
                 end_token.value = t
             if (t.next0_ is not None and t.next0_.is_char_of(":-")): 
                 t = t.next0_
             continue
         if (t.end_char > end_char): 
             break
         rli = t.get_referents()
         if (rli is None): 
             continue
         if (not t.is_newline_before and (isinstance(t.previous, TextToken))): 
             s = t.previous.term
             if (s == "ИМЕНИ" or s == "ИМ"): 
                 continue
             if (s == "." and t.previous.previous is not None and t.previous.previous.is_value("ИМ", None)): 
                 continue
         for r in rli: 
             if (isinstance(r, PersonReferent)): 
                 if (r != rli[0]): 
                     continue
                 p = Utils.asObjectOrNull(r, PersonReferent)
                 if (pers_typ != TitleItemToken.Types.UNDEFINED): 
                     if (t.previous is not None and t.previous.is_char('.')): 
                         pers_typ = TitleItemToken.Types.UNDEFINED
                 typ = pr.calc_typ_from_attrs(p)
                 if (typ != TitleItemToken.Types.UNDEFINED): 
                     pr.add(p, typ, 1)
                     pers_typ = typ
                 elif (pers_typ != TitleItemToken.Types.UNDEFINED): 
                     pr.add(p, pers_typ, 1)
                 elif (t.previous is not None and t.previous.is_char('©')): 
                     pers_typ = TitleItemToken.Types.WORKER
                     pr.add(p, pers_typ, 1)
                 else: 
                     tt = t.next0_
                     first_pass3399 = True
                     while True:
                         if first_pass3399: first_pass3399 = False
                         else: tt = tt.next0_
                         if (not (tt is not None)): break
                         rr = tt.get_referent()
                         if (rr == res): 
                             pers_typ = TitleItemToken.Types.WORKER
                             break
                         if (isinstance(rr, PersonReferent)): 
                             if (pr.calc_typ_from_attrs(Utils.asObjectOrNull(r, PersonReferent)) != TitleItemToken.Types.UNDEFINED): 
                                 break
                             else: 
                                 continue
                         if (rr is not None): 
                             break
                         tpt = TitleItemToken.try_attach(tt)
                         if (tpt is not None): 
                             if (tpt.typ != TitleItemToken.Types.TYP and tpt.typ != TitleItemToken.Types.TYPANDTHEME): 
                                 break
                             tt = tpt.end_token
                             if (tt.end_char > end_token.value.end_char): 
                                 end_token.value = tt
                             continue
                     if (pers_typ == TitleItemToken.Types.UNDEFINED): 
                         tt = t.previous
                         while tt is not None: 
                             rr = tt.get_referent()
                             if (rr == res): 
                                 pers_typ = TitleItemToken.Types.WORKER
                                 break
                             if (rr is not None): 
                                 break
                             if ((tt.is_value("СТУДЕНТ", None) or tt.is_value("СТУДЕНТКА", None) or tt.is_value("СЛУШАТЕЛЬ", None)) or tt.is_value("ДИПЛОМНИК", None) or tt.is_value("ИСПОЛНИТЕЛЬ", None)): 
                                 pers_typ = TitleItemToken.Types.WORKER
                                 break
                             tpt = TitleItemToken.try_attach(tt)
                             if (tpt is not None and tpt.typ != TitleItemToken.Types.TYP): 
                                 break
                             tt = tt.previous
                     if (pers_typ != TitleItemToken.Types.UNDEFINED): 
                         pr.add(p, pers_typ, 1)
                     else: 
                         pr.add(p, pers_typ, 0.5)
                     if (t.end_char > end_token.value.end_char): 
                         end_token.value = t
                 continue
             if (r == rli[0]): 
                 pers_typ = TitleItemToken.Types.UNDEFINED
             if (isinstance(r, DateReferent)): 
                 if (res.date is None): 
                     res.date = Utils.asObjectOrNull(r, DateReferent)
                     if (t.end_char > end_token.value.end_char): 
                         end_token.value = t
             elif (isinstance(r, GeoReferent)): 
                 if (res.city is None and r.is_city): 
                     res.city = Utils.asObjectOrNull(r, GeoReferent)
                     if (t.end_char > end_token.value.end_char): 
                         end_token.value = t
             if (isinstance(r, OrganizationReferent)): 
                 org0_ = Utils.asObjectOrNull(r, OrganizationReferent)
                 if ("курс" in org0_.types and org0_.number is not None): 
                     i = 0
                     wrapi2673 = RefOutArgWrapper(0)
                     inoutres2674 = Utils.tryParseInt(org0_.number, wrapi2673)
                     i = wrapi2673.value
                     if (inoutres2674): 
                         if (i > 0 and (i < 8)): 
                             res.student_year = i
                 while org0_.higher is not None: 
                     if (org0_.kind != OrganizationKind.DEPARTMENT): 
                         break
                     org0_ = org0_.higher
                 if (org0_.kind != OrganizationKind.DEPARTMENT): 
                     if (res.org0_ is None): 
                         res.org0_ = org0_
                     elif (OrganizationReferent.can_be_higher(res.org0_, org0_)): 
                         res.org0_ = org0_
                 if (t.end_char > end_token.value.end_char): 
                     end_token.value = t
             if ((isinstance(r, UriReferent)) or (isinstance(r, GeoReferent))): 
                 if (t.end_char > end_token.value.end_char): 
                     end_token.value = t
     for ty in pers_types: 
         for p in pr.get_persons(ty): 
             if (pr.get_attr_name_for_type(ty) is not None): 
                 res.add_slot(pr.get_attr_name_for_type(ty), p, False, 0)
     if (res.get_slot_value(TitlePageReferent.ATTR_AUTHOR) is None): 
         for p in pr.get_persons(TitleItemToken.Types.UNDEFINED): 
             res.add_slot(TitlePageReferent.ATTR_AUTHOR, p, False, 0)
             break
     if (res.city is None and res.org0_ is not None): 
         s = res.org0_.find_slot(OrganizationReferent.ATTR_GEO, None, True)
         if (s is not None and (isinstance(s.value, GeoReferent))): 
             if (s.value.is_city): 
                 res.city = Utils.asObjectOrNull(s.value, GeoReferent)
     if (res.date is None): 
         t = begin
         first_pass3400 = True
         while True:
             if first_pass3400: first_pass3400 = False
             else: t = t.next0_
             if (not (t is not None and t.end_char <= end_char)): break
             city = Utils.asObjectOrNull(t.get_referent(), GeoReferent)
             if (city is None): 
                 continue
             if (isinstance(t.next0_, TextToken)): 
                 if (t.next0_.is_char_of(":,") or t.next0_.is_hiphen): 
                     t = t.next0_
             rt = t.kit.process_referent(DateAnalyzer.ANALYZER_NAME, t.next0_)
             if (rt is not None): 
                 rt.save_to_local_ontology()
                 res.date = Utils.asObjectOrNull(rt.referent, DateReferent)
                 if (kit is not None): 
                     kit.embed_token(rt)
                 break
     if (len(res.slots) == 0): 
         return None
     else: 
         return res
Beispiel #12
0
 def try_attach_requisites(t : 'Token', cur : 'InstrumentParticipantReferent', other : 'InstrumentParticipantReferent', cant_be_empty : bool=False) -> 'ReferentToken':
     if (t is None or cur is None): 
         return None
     if (t.is_table_control_char): 
         return None
     err = 0
     spec_chars = 0
     rt = None
     t0 = t
     is_in_tab_cell = False
     cou = 0
     tt = t.next0_
     while tt is not None and (cou < 300): 
         if (tt.is_table_control_char): 
             is_in_tab_cell = True
             break
         tt = tt.next0_; cou += 1
     first_pass3286 = True
     while True:
         if first_pass3286: first_pass3286 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (t.begin_char == 8923): 
             pass
         if (t.is_table_control_char): 
             if (t != t0): 
                 if (rt is not None): 
                     rt.end_token = t.previous
                 elif (not cant_be_empty): 
                     rt = ReferentToken(cur, t0, t.previous)
                 break
             else: 
                 continue
         if ((t.is_char_of(":.") or t.is_value("М", None) or t.is_value("M", None)) or t.is_value("П", None)): 
             if (rt is not None): 
                 rt.end_token = t
             continue
         pp = ParticipantToken.try_attach_to_exist(t, cur, other)
         if (pp is not None): 
             if (pp.referent != cur): 
                 break
             if (rt is None): 
                 rt = ReferentToken(cur, t, t)
             rt.end_token = pp.end_token
             err = 0
             continue
         if (t.is_newline_before): 
             iii = InstrToken.parse(t, 0, None)
             if (iii is not None): 
                 if (iii.typ == ILTypes.APPENDIX): 
                     break
         if (t.whitespaces_before_count > 25 and not is_in_tab_cell): 
             if (t != t0): 
                 if (t.previous is not None and t.previous.is_char_of(",;")): 
                     pass
                 elif (t.newlines_before_count > 1): 
                     break
             if ((isinstance(t.get_referent(), PersonReferent)) or (isinstance(t.get_referent(), OrganizationReferent))): 
                 if (not cur._contains_ref(t.get_referent())): 
                     break
         if ((t.is_char_of(";:,.") or t.is_hiphen or t.morph.class0_.is_preposition) or t.morph.class0_.is_conjunction): 
             continue
         if (t.is_char_of("_/\\")): 
             spec_chars += 1
             if (spec_chars > 10 and rt is None): 
                 rt = ReferentToken(cur, t0, t)
             if (rt is not None): 
                 rt.end_token = t
             continue
         if (t.is_newline_before and (isinstance(t, NumberToken))): 
             break
         if (t.is_value("ОФИС", None)): 
             if (BracketHelper.can_be_start_of_sequence(t.next0_, True, False)): 
                 br = BracketHelper.try_parse(t.next0_, BracketParseAttr.NO, 100)
                 if (br is not None): 
                     t = br.end_token
                     continue
             if ((isinstance(t.next0_, TextToken)) and not t.next0_.chars.is_all_lower): 
                 t = t.next0_
             continue
         r = t.get_referent()
         if ((((isinstance(r, PersonReferent)) or (isinstance(r, AddressReferent)) or (isinstance(r, UriReferent))) or (isinstance(r, OrganizationReferent)) or (isinstance(r, PhoneReferent))) or (isinstance(r, PersonIdentityReferent)) or (isinstance(r, BankDataReferent))): 
             if (other is not None and other.find_slot(None, r, True) is not None): 
                 if (not (isinstance(r, UriReferent))): 
                     break
             if (rt is None): 
                 rt = ReferentToken(cur, t, t)
             if (cur.find_slot(InstrumentParticipantReferent.ATTR_DELEGATE, r, True) is not None): 
                 pass
             else: 
                 cur.add_slot(InstrumentParticipantReferent.ATTR_REF, r, False, 0)
             rt.end_token = t
             err = 0
         else: 
             if ((isinstance(t, TextToken)) and t.length_char > 1): 
                 err += 1
             if (is_in_tab_cell and rt is not None): 
                 if (err > 300): 
                     break
             elif (err > 4): 
                 break
     return rt
Beispiel #13
0
 def __try_parse(t: 'Token',
                 is_in_lit: bool,
                 max_char: int = 0) -> typing.List['ReferentToken']:
     if (t is None):
         return None
     is_bracket_regime = False
     if (t.previous is not None and t.previous.is_char('(')):
         is_bracket_regime = True
     blt = BookLinkToken.try_parse(t, 0)
     if (blt is None):
         blt = BookLinkToken.try_parse_author(t, FioTemplateType.UNDEFINED)
     if (blt is None and not is_bracket_regime):
         return None
     t0 = t
     coef = 0
     is_electr_res = False
     decree = None
     regtyp = BookLinkAnalyzer.RegionTyp.UNDEFINED
     num = None
     spec_see = None
     book_prev = None
     if (is_bracket_regime):
         regtyp = BookLinkAnalyzer.RegionTyp.AUTHORS
     elif (blt.typ == BookLinkTyp.PERSON):
         if (not is_in_lit):
             return None
         regtyp = BookLinkAnalyzer.RegionTyp.AUTHORS
     elif (blt.typ == BookLinkTyp.NUMBER):
         num = blt.value
         t = blt.end_token.next0_
         if (t is None or t.is_newline_before):
             return None
         if (not t.is_whitespace_before):
             if (isinstance(t, NumberToken)):
                 n = t.value
                 if ((((n == "3" or n == "0")) and not t.is_whitespace_after
                      and (isinstance(t.next0_, TextToken)))
                         and t.next0_.chars.is_all_lower):
                     pass
                 else:
                     return None
             elif (not (isinstance(t, TextToken)) or t.chars.is_all_lower):
                 r = t.get_referent()
                 if (isinstance(r, PersonReferent)):
                     pass
                 elif (is_in_lit and r is not None
                       and r.type_name == "DECREE"):
                     pass
                 else:
                     return None
         first_pass3025 = True
         while True:
             if first_pass3025: first_pass3025 = False
             else: t = t.next0_
             if (not (t is not None)): break
             if (isinstance(t, NumberToken)):
                 break
             if (not (isinstance(t, TextToken))):
                 break
             if (BracketHelper.can_be_start_of_sequence(t, True, False)):
                 break
             if (not t.chars.is_letter):
                 continue
             bbb = BookLinkToken.try_parse(t, 0)
             if (bbb is not None):
                 if (bbb.typ == BookLinkTyp.TAMZE):
                     spec_see = bbb
                     t = bbb.end_token.next0_
                     break
                 if (bbb.typ == BookLinkTyp.SEE):
                     t = bbb.end_token
                     continue
             break
         if (spec_see is not None and spec_see.typ == BookLinkTyp.TAMZE):
             coef += 1
             max0_ = 1000
             tt = t0
             while tt is not None and max0_ > 0:
                 if (isinstance(tt.get_referent(), BookLinkRefReferent)):
                     book_prev = tt.get_referent().book
                     break
                 tt = tt.previous
                 max0_ -= 1
         blt1 = BookLinkToken.try_parse_author(t, FioTemplateType.UNDEFINED)
         if (blt1 is not None and blt1.typ == BookLinkTyp.PERSON):
             regtyp = BookLinkAnalyzer.RegionTyp.AUTHORS
         else:
             ok = False
             tt = t
             first_pass3026 = True
             while True:
                 if first_pass3026: first_pass3026 = False
                 else: tt = (None if tt is None else tt.next0_)
                 if (not (tt is not None)): break
                 if (tt.is_newline_before):
                     break
                 if (is_in_lit and tt.get_referent() is not None
                         and tt.get_referent().type_name == "DECREE"):
                     ok = True
                     decree = tt
                     break
                 bbb = BookLinkToken.try_parse(tt, 0)
                 if (bbb is None):
                     continue
                 if (bbb.typ == BookLinkTyp.ELECTRONRES):
                     is_electr_res = True
                     ok = True
                     break
                 if (bbb.typ == BookLinkTyp.DELIMETER):
                     tt = bbb.end_token.next0_
                     if (BookLinkToken.try_parse_author(
                             tt, FioTemplateType.UNDEFINED) is not None):
                         ok = True
                         break
                     bbb = BookLinkToken.try_parse(tt, 0)
                     if (bbb is not None):
                         if (bbb.typ == BookLinkTyp.EDITORS
                                 or bbb.typ == BookLinkTyp.TRANSLATE
                                 or bbb.typ == BookLinkTyp.SOSTAVITEL):
                             ok = True
                             break
             if (not ok and not is_in_lit):
                 if (BookLinkToken.check_link_before(t0, num)):
                     pass
                 else:
                     return None
             regtyp = BookLinkAnalyzer.RegionTyp.NAME
     else:
         return None
     res = BookLinkReferent()
     corr_authors = list()
     t00 = t
     blt00 = None
     start_of_name = None
     prev_pers_templ = FioTemplateType.UNDEFINED
     if (regtyp == BookLinkAnalyzer.RegionTyp.AUTHORS):
         first_pass3027 = True
         while True:
             if first_pass3027: first_pass3027 = False
             else: t = t.next0_
             if (not (t is not None)): break
             if (max_char > 0 and t.begin_char >= max_char):
                 break
             if (t.is_char_of(".;") or t.is_comma_and):
                 continue
             if (t.is_char('/')):
                 break
             if ((t.is_char('(') and t.next0_ is not None
                  and t.next0_.is_value("EDS", None))
                     and t.next0_.next0_ is not None
                     and t.next0_.next0_.is_char(')')):
                 t = t.next0_.next0_.next0_
                 break
             blt = BookLinkToken.try_parse_author(t, prev_pers_templ)
             if (blt is None and t.previous is not None
                     and t.previous.is_and):
                 blt = BookLinkToken.try_parse_author(
                     t.previous, FioTemplateType.UNDEFINED)
             if (blt is None):
                 if ((isinstance(t.get_referent(), OrganizationReferent))
                         and blt00 is not None):
                     bbb2 = BookLinkToken.try_parse(t.next0_, 0)
                     if (bbb2 is not None):
                         if (bbb2.typ == BookLinkTyp.YEAR):
                             res.add_slot(BookLinkReferent.ATTR_AUTHOR,
                                          t.get_referent(), False, 0)
                             res.year = int(bbb2.value)
                             coef += 0.5
                             t = bbb2.end_token.next0_
                 break
             if (blt.typ == BookLinkTyp.PERSON):
                 tt2 = blt.end_token.next0_
                 bbb2 = BookLinkToken.try_parse(tt2, 0)
                 if (bbb2 is not None):
                     if (bbb2.typ == BookLinkTyp.YEAR):
                         res.year = int(bbb2.value)
                         coef += 0.5
                         blt.end_token = bbb2.end_token
                         blt00 = (None)
                 if (blt00 is not None
                         and ((blt00.end_token.next0_ == blt.begin_token
                               or blt.begin_token.previous.is_char('.')))):
                     tt11 = blt.end_token.next0_
                     nex = BookLinkToken.try_parse(tt11, 0)
                     if (nex is not None
                             and nex.typ == BookLinkTyp.ANDOTHERS):
                         pass
                     else:
                         if (tt11 is None):
                             break
                         if (tt11.is_char('/') and tt11.next0_ is not None
                                 and tt11.next0_.is_char('/')):
                             break
                         if (tt11.is_char(':')):
                             break
                         if ((str(blt).find('.') < 0)
                                 and str(blt00).find('.') > 0):
                             break
                         if ((isinstance(tt11, TextToken))
                                 and tt11.chars.is_all_lower):
                             break
                         if (tt11.is_char_of(",.;")
                                 and tt11.next0_ is not None):
                             tt11 = tt11.next0_
                         nex = BookLinkToken.try_parse(tt11, 0)
                         if (nex is not None
                                 and nex.typ != BookLinkTyp.PERSON
                                 and nex.typ != BookLinkTyp.ANDOTHERS):
                             break
                 elif (
                     (blt00 is not None
                      and blt00.person_template != FioTemplateType.UNDEFINED
                      and blt.person_template != blt00.person_template)
                         and blt.person_template
                         == FioTemplateType.NAMESURNAME):
                     if (blt.end_token.next0_ is None
                             or not blt.end_token.next0_.is_comma_and):
                         break
                     if (BookLinkToken.try_parse_author(
                             blt.end_token.next0_.next0_,
                             FioTemplateType.UNDEFINED) is not None):
                         pass
                     else:
                         break
                 if (blt00 is None and blt.person_template
                         == FioTemplateType.NAMESURNAME):
                     tt = blt.end_token.next0_
                     if (tt is not None and tt.is_hiphen):
                         tt = tt.next0_
                     if (isinstance(tt, NumberToken)):
                         break
                 BookLinkAnalyzer.__add_author(res, blt)
                 coef += 1
                 t = blt.end_token
                 if (isinstance(t.get_referent(), PersonReferent)):
                     corr_authors.append(
                         Utils.asObjectOrNull(t, ReferentToken))
                 blt00 = blt
                 prev_pers_templ = blt.person_template
                 start_of_name = blt.start_of_name
                 if ((start_of_name) is not None):
                     t = t.next0_
                     break
                 continue
             if (blt.typ == BookLinkTyp.ANDOTHERS):
                 coef += 0.5
                 t = blt.end_token.next0_
                 res.authors_and_other = True
                 break
             break
     if (t is None):
         return None
     if ((t.is_newline_before and t != t0 and num is None)
             and res.find_slot(BookLinkReferent.ATTR_AUTHOR, None,
                               True) is None):
         return None
     if (start_of_name is None):
         if (t.chars.is_all_lower):
             coef -= (1)
         if (t.chars.is_latin_letter and not is_electr_res and num is None):
             if (res.get_slot_value(BookLinkReferent.ATTR_AUTHOR) is None):
                 return None
     tn0 = t
     tn1 = None
     uri = None
     next_num = None
     nn = 0
     wrapnn376 = RefOutArgWrapper(0)
     inoutres377 = Utils.tryParseInt(Utils.ifNotNull(num, ""), wrapnn376)
     nn = wrapnn376.value
     if (inoutres377):
         next_num = str((nn + 1))
     br = (BracketHelper.try_parse(
         t,
         Utils.valToEnum(
             (BracketParseAttr.CANCONTAINSVERBS) |
             (BracketParseAttr.CANBEMANYLINES), BracketParseAttr), 100) if
           BracketHelper.can_be_start_of_sequence(t, True, False) else None)
     if (br is not None):
         t = t.next0_
     pages = None
     first_pass3028 = True
     while True:
         if first_pass3028: first_pass3028 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (max_char > 0 and t.begin_char >= max_char):
             break
         if (br is not None and br.end_token == t):
             tn1 = t
             break
         tit = TitleItemToken.try_attach(t)
         if (tit is not None):
             if ((tit.typ == TitleItemToken.Types.TYP and tn0 == t
                  and br is None)
                     and BracketHelper.can_be_start_of_sequence(
                         tit.end_token.next0_, True, False)):
                 br = BracketHelper.try_parse(tit.end_token.next0_,
                                              BracketParseAttr.NO, 100)
                 if (br is not None):
                     coef += (1)
                     if (num is not None):
                         coef += 1
                     tn0 = br.begin_token
                     tn1 = br.end_token
                     res.typ = tit.value.lower()
                     t = br.end_token.next0_
                     break
         if (t.is_newline_before and t != tn0):
             if (br is not None and (t.end_char < br.end_char)):
                 pass
             elif (not MiscHelper.can_be_start_of_sentence(t)):
                 pass
             else:
                 if (t.newlines_before_count > 1):
                     break
                 if ((isinstance(t, NumberToken)) and num is not None
                         and t.int_value is not None):
                     if (num == str((t.int_value - 1))):
                         break
                 elif (num is not None):
                     pass
                 else:
                     nnn = NounPhraseHelper.try_parse(
                         t.previous,
                         Utils.valToEnum(
                             ((NounPhraseParseAttr.PARSEPREPOSITION) |
                              (NounPhraseParseAttr.PARSEADVERBS) |
                              (NounPhraseParseAttr.PARSENUMERICASADJECTIVE))
                             | (NounPhraseParseAttr.MULTILINES),
                             NounPhraseParseAttr), 0, None)
                     if (nnn is not None and nnn.end_char >= t.end_char):
                         pass
                     else:
                         break
         if (t.is_char_of(".;") and t.whitespaces_after_count > 0):
             tit = TitleItemToken.try_attach(t.next0_)
             if ((tit) is not None):
                 if (tit.typ == TitleItemToken.Types.TYP):
                     break
             stop = True
             words = 0
             notwords = 0
             tt = t.next0_
             first_pass3029 = True
             while True:
                 if first_pass3029: first_pass3029 = False
                 else: tt = tt.next0_
                 if (not (tt is not None)): break
                 blt0 = BookLinkToken.try_parse(tt, 0)
                 if (blt0 is None):
                     if (tt.is_newline_before):
                         break
                     if ((isinstance(tt, TextToken)) and not tt.
                             get_morph_class_in_dictionary().is_undefined):
                         words += 1
                     else:
                         notwords += 1
                     if (words > 6 and words > (notwords * 4)):
                         stop = False
                         break
                     continue
                 if ((blt0.typ == BookLinkTyp.DELIMETER
                      or blt0.typ == BookLinkTyp.TRANSLATE
                      or blt0.typ == BookLinkTyp.TYPE)
                         or blt0.typ == BookLinkTyp.GEO
                         or blt0.typ == BookLinkTyp.PRESS):
                     stop = False
                 break
             if (br is not None
                     and br.end_token.previous.end_char > t.end_char):
                 stop = False
             if (stop):
                 break
         if (t == decree):
             t = t.next0_
             break
         blt = BookLinkToken.try_parse(t, 0)
         if (blt is None):
             tn1 = t
             continue
         if (blt.typ == BookLinkTyp.DELIMETER):
             break
         if (((blt.typ == BookLinkTyp.MISC or blt.typ
               == BookLinkTyp.TRANSLATE or blt.typ == BookLinkTyp.NAMETAIL)
              or blt.typ == BookLinkTyp.TYPE
              or blt.typ == BookLinkTyp.VOLUME)
                 or blt.typ == BookLinkTyp.PAGERANGE
                 or blt.typ == BookLinkTyp.PAGES):
             coef += 1
             break
         if (blt.typ == BookLinkTyp.GEO or blt.typ == BookLinkTyp.PRESS):
             if (t.previous.is_hiphen or t.previous.is_char_of(".;")
                     or blt.add_coef > 0):
                 break
         if (blt.typ == BookLinkTyp.YEAR):
             if (t.previous is not None and t.previous.is_comma):
                 break
         if (blt.typ == BookLinkTyp.ELECTRONRES):
             is_electr_res = True
             break
         if (blt.typ == BookLinkTyp.URL):
             if (t == tn0 or t.previous.is_char_of(":.")):
                 is_electr_res = True
                 break
         tn1 = t
     if (tn1 is None and start_of_name is None):
         if (is_electr_res):
             uri_re = BookLinkReferent()
             rt0 = ReferentToken(uri_re, t00, t)
             rts0 = list()
             bref0 = BookLinkRefReferent._new372(uri_re)
             if (num is not None):
                 bref0.number = num
             rt01 = ReferentToken(bref0, t0, rt0.end_token)
             ok = False
             while t is not None:
                 if (t.is_newline_before):
                     break
                 blt0 = BookLinkToken.try_parse(t, 0)
                 if (blt0 is not None):
                     if (isinstance(blt0.ref, UriReferent)):
                         uri_re.add_slot(
                             BookLinkReferent.ATTR_URL,
                             Utils.asObjectOrNull(blt0.ref, UriReferent),
                             False, 0)
                         ok = True
                     t = blt0.end_token
                 rt0.end_token = rt01.end_token = t
                 t = t.next0_
             if (ok):
                 rts0.append(rt01)
                 rts0.append(rt0)
                 return rts0
         if (decree is not None and num is not None):
             rts0 = list()
             bref0 = BookLinkRefReferent._new372(decree.get_referent())
             if (num is not None):
                 bref0.number = num
             rt01 = ReferentToken(bref0, t0, decree)
             t = decree.next0_
             while t is not None:
                 if (t.is_newline_before):
                     break
                 if (isinstance(t, TextToken)):
                     if (t.is_pure_verb):
                         return None
                 rt01.end_token = t
                 t = t.next0_
             rts0.append(rt01)
             return rts0
         if (book_prev is not None):
             tt = t
             while tt is not None and ((tt.is_char_of(",.")
                                        or tt.is_hiphen)):
                 tt = tt.next0_
             blt0 = BookLinkToken.try_parse(tt, 0)
             if (blt0 is not None and blt0.typ == BookLinkTyp.PAGERANGE):
                 rts0 = list()
                 bref0 = BookLinkRefReferent._new372(book_prev)
                 if (num is not None):
                     bref0.number = num
                 bref0.pages = blt0.value
                 rt00 = ReferentToken(bref0, t0, blt0.end_token)
                 rts0.append(rt00)
                 return rts0
         return None
     if (br is not None
             and ((tn1 == br.end_token or tn1 == br.end_token.previous))):
         tn0 = tn0.next0_
         tn1 = tn1.previous
     if (start_of_name is None):
         while tn0 is not None:
             if (tn0.is_char_of(":,~")):
                 tn0 = tn0.next0_
             else:
                 break
     while tn1 is not None and tn1.begin_char > tn0.begin_char:
         if (tn1.is_char_of(".;,:(~") or tn1.is_hiphen
                 or tn1.is_value("РЕД", None)):
             pass
         else:
             break
         tn1 = tn1.previous
     nam = MiscHelper.get_text_value(
         tn0, tn1,
         Utils.valToEnum(
             (GetTextAttr.KEEPQUOTES) | (GetTextAttr.KEEPREGISTER),
             GetTextAttr))
     if (start_of_name is not None):
         if (nam is None or (len(nam) < 3)):
             nam = start_of_name
         else:
             nam = "{0}{1}{2}".format(
                 start_of_name, (" " if tn0.is_whitespace_before else ""),
                 nam)
     if (nam is None):
         return None
     res.name = nam
     if (num is None and not is_in_lit):
         if (len(nam) < 20):
             return None
         coef -= (2)
     if (len(nam) > 500):
         coef -= (math.floor(len(nam) / 500))
     if (is_bracket_regime):
         coef -= 1
     if (len(nam) > 200):
         if (num is None):
             return None
         if (res.find_slot(BookLinkReferent.ATTR_AUTHOR, None, True) is None
                 and not BookLinkToken.check_link_before(t0, num)):
             return None
     en = 0
     ru = 0
     ua = 0
     cha = 0
     nocha = 0
     chalen = 0
     lt0 = tn0
     lt1 = tn1
     if (tn1 is None):
         if (t is None):
             return None
         lt0 = t0
         lt1 = t
         tn1 = t.previous
     tt = lt0
     while tt is not None and tt.end_char <= lt1.end_char:
         if ((isinstance(tt, TextToken)) and tt.chars.is_letter):
             if (tt.chars.is_latin_letter):
                 en += 1
             elif (tt.morph.language.is_ua):
                 ua += 1
             elif (tt.morph.language.is_ru):
                 ru += 1
             if (tt.length_char > 2):
                 cha += 1
                 chalen += tt.length_char
         elif (not (isinstance(tt, ReferentToken))):
             nocha += 1
         tt = tt.next0_
     if (ru > (ua + en)):
         res.lang = "RU"
     elif (ua > (ru + en)):
         res.lang = "UA"
     elif (en > (ru + ua)):
         res.lang = "EN"
     if (nocha > 3 and nocha > cha and start_of_name is None):
         if (nocha > (math.floor(chalen / 3))):
             coef -= (2)
     if (res.lang == "EN"):
         tt = tn0.next0_
         first_pass3030 = True
         while True:
             if first_pass3030: first_pass3030 = False
             else: tt = tt.next0_
             if (not (tt is not None and (tt.end_char < tn1.end_char))):
                 break
             if (tt.is_comma and tt.next0_ is not None
                     and ((not tt.next0_.chars.is_all_lower or
                           (isinstance(tt.next0_, ReferentToken))))):
                 if (tt.next0_.next0_ is not None
                         and tt.next0_.next0_.is_comma_and):
                     if (isinstance(tt.next0_, ReferentToken)):
                         pass
                     else:
                         continue
                 nam = MiscHelper.get_text_value(
                     tn0, tt.previous,
                     Utils.valToEnum((GetTextAttr.KEEPQUOTES) |
                                     (GetTextAttr.KEEPREGISTER),
                                     GetTextAttr))
                 if (nam is not None and len(nam) > 15):
                     res.name = nam
                     break
     rt = ReferentToken(res, t00, tn1)
     authors = True
     edits = False
     br = (None)
     first_pass3031 = True
     while True:
         if first_pass3031: first_pass3031 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (max_char > 0 and t.begin_char >= max_char):
             break
         if (BracketHelper.can_be_start_of_sequence(t, False, False)):
             br = BracketHelper.try_parse(t,
                                          BracketParseAttr.CANBEMANYLINES,
                                          100)
             if (br is not None and br.length_char > 300):
                 br = (None)
         blt = BookLinkToken.try_parse(t, 0)
         if (t.is_newline_before and not t.is_char('/')
                 and not t.previous.is_char('/')):
             if (blt is not None and blt.typ == BookLinkTyp.NUMBER):
                 break
             if (t.previous.is_char_of(":")):
                 pass
             elif (blt is not None and ((
                 ((blt.typ == BookLinkTyp.DELIMETER or blt.typ
                   == BookLinkTyp.PAGERANGE or blt.typ == BookLinkTyp.PAGES)
                  or blt.typ == BookLinkTyp.GEO or blt.typ
                  == BookLinkTyp.PRESS) or blt.typ == BookLinkTyp.N))):
                 pass
             elif (num is not None and BookLinkToken.try_parse_author(
                     t, FioTemplateType.UNDEFINED) is not None):
                 pass
             elif (num is not None and blt is not None
                   and blt.typ != BookLinkTyp.NUMBER):
                 pass
             elif (br is not None and (t.end_char < br.end_char)
                   and t.begin_char > br.begin_char):
                 pass
             else:
                 ok = False
                 mmm = 50
                 tt = t.next0_
                 while tt is not None and mmm > 0:
                     if (tt.is_newline_before):
                         blt2 = BookLinkToken.try_parse(tt, 0)
                         if (blt2 is not None
                                 and blt2.typ == BookLinkTyp.NUMBER
                                 and blt2.value == next_num):
                             ok = True
                             break
                         if (blt2 is not None):
                             if (blt2.typ == BookLinkTyp.PAGES
                                     or blt2.typ == BookLinkTyp.GEO
                                     or blt2.typ == BookLinkTyp.PRESS):
                                 ok = True
                                 break
                     tt = tt.next0_
                     mmm -= 1
                 if (not ok):
                     npt = NounPhraseHelper.try_parse(
                         t.previous,
                         Utils.valToEnum(
                             ((NounPhraseParseAttr.MULTILINES) |
                              (NounPhraseParseAttr.PARSEADVERBS) |
                              (NounPhraseParseAttr.PARSEPREPOSITION)) |
                             (NounPhraseParseAttr.PARSEVERBS) |
                             (NounPhraseParseAttr.PARSEPRONOUNS),
                             NounPhraseParseAttr), 0, None)
                     if (npt is not None and npt.end_char >= t.end_char):
                         ok = True
                 if (not ok):
                     break
         rt.end_token = t
         if (blt is not None):
             rt.end_token = blt.end_token
         if (t.is_char_of(".,") or t.is_hiphen):
             continue
         if (t.is_value("С", None)):
             pass
         if (regtyp == BookLinkAnalyzer.RegionTyp.FIRST and blt is not None
                 and blt.typ == BookLinkTyp.EDITORS):
             edits = True
             t = blt.end_token
             coef += 1
             continue
         if (regtyp == BookLinkAnalyzer.RegionTyp.FIRST and blt is not None
                 and blt.typ == BookLinkTyp.SOSTAVITEL):
             edits = False
             t = blt.end_token
             coef += 1
             continue
         if (regtyp == BookLinkAnalyzer.RegionTyp.FIRST and authors):
             blt2 = BookLinkToken.try_parse_author(t, prev_pers_templ)
             if (blt2 is not None and blt2.typ == BookLinkTyp.PERSON):
                 prev_pers_templ = blt2.person_template
                 if (not edits):
                     BookLinkAnalyzer.__add_author(res, blt2)
                 coef += 1
                 t = blt2.end_token
                 continue
             if (blt2 is not None and blt2.typ == BookLinkTyp.ANDOTHERS):
                 if (not edits):
                     res.authors_and_other = True
                 coef += 1
                 t = blt2.end_token
                 continue
             authors = False
         if (blt is None):
             continue
         if (blt.typ == BookLinkTyp.ELECTRONRES
                 or blt.typ == BookLinkTyp.URL):
             is_electr_res = True
             if (blt.typ == BookLinkTyp.ELECTRONRES):
                 coef += 1.5
             else:
                 coef += 0.5
             if (isinstance(blt.ref, UriReferent)):
                 res.add_slot(BookLinkReferent.ATTR_URL,
                              Utils.asObjectOrNull(blt.ref, UriReferent),
                              False, 0)
         elif (blt.typ == BookLinkTyp.YEAR):
             if (res.year == 0):
                 res.year = int(blt.value)
                 coef += 0.5
         elif (blt.typ == BookLinkTyp.DELIMETER):
             coef += 1
             if (blt.length_char == 2):
                 regtyp = BookLinkAnalyzer.RegionTyp.SECOND
             else:
                 regtyp = BookLinkAnalyzer.RegionTyp.FIRST
         elif (
             (((blt.typ == BookLinkTyp.MISC or blt.typ == BookLinkTyp.TYPE
                or blt.typ == BookLinkTyp.PAGES) or blt.typ
               == BookLinkTyp.NAMETAIL or blt.typ == BookLinkTyp.TRANSLATE)
              or blt.typ == BookLinkTyp.PRESS
              or blt.typ == BookLinkTyp.VOLUME)
                 or blt.typ == BookLinkTyp.N):
             coef += 1
         elif (blt.typ == BookLinkTyp.PAGERANGE):
             pages = blt
             coef += 1
             if (is_bracket_regime and blt.end_token.next0_ is not None
                     and blt.end_token.next0_.is_char(')')):
                 coef += (2)
                 if (res.name is not None
                         and res.find_slot(BookLinkReferent.ATTR_AUTHOR,
                                           None, True) is not None):
                     coef = (10)
         elif (blt.typ == BookLinkTyp.GEO
               and ((regtyp == BookLinkAnalyzer.RegionTyp.SECOND
                     or regtyp == BookLinkAnalyzer.RegionTyp.FIRST))):
             coef += 1
         elif (blt.typ == BookLinkTyp.GEO and t.previous is not None
               and t.previous.is_char('.')):
             coef += 1
         elif (blt.typ == BookLinkTyp.ANDOTHERS):
             coef += 1
             if (authors):
                 res.authors_and_other = True
         coef += blt.add_coef
         t = blt.end_token
     if ((coef < 2.5) and num is not None):
         if (BookLinkToken.check_link_before(t0, num)):
             coef += (2)
         elif (BookLinkToken.check_link_after(rt.end_token, num)):
             coef += (1)
     if (rt.length_char > 500):
         return None
     if (is_in_lit):
         coef += 1
     if (coef < 2.5):
         if (is_electr_res and uri is not None):
             pass
         elif (coef >= 2 and is_in_lit):
             pass
         else:
             return None
     for rr in corr_authors:
         pits0 = PersonItemToken.try_attach_list(
             rr.begin_token, None,
             PersonItemToken.ParseAttr.CANINITIALBEDIGIT, 10)
         if (pits0 is None or (len(pits0) < 2)):
             continue
         if (pits0[0].typ == PersonItemToken.ItemType.VALUE):
             exi = False
             for i in range(len(rr.referent.slots) - 1, -1, -1):
                 s = rr.referent.slots[i]
                 if (s.type_name == PersonReferent.ATTR_LASTNAME):
                     ln = Utils.asObjectOrNull(s.value, str)
                     if (ln is None):
                         continue
                     if (ln == pits0[0].value):
                         exi = True
                         continue
                     if (ln.find('-') > 0):
                         ln = ln[0:0 + ln.find('-')]
                     if (pits0[0].begin_token.is_value(ln, None)):
                         del rr.referent.slots[i]
             if (not exi):
                 rr.referent.add_slot(PersonReferent.ATTR_LASTNAME,
                                      pits0[0].value, False, 0)
     rts = list()
     bref = BookLinkRefReferent._new372(res)
     if (num is not None):
         bref.number = num
     rt1 = ReferentToken(bref, t0, rt.end_token)
     if (pages is not None):
         if (pages.value is not None):
             bref.pages = pages.value
         rt.end_token = pages.begin_token.previous
     rts.append(rt1)
     rts.append(rt)
     return rts
Beispiel #14
0
 def __try_parse_thesis(t: 'Token') -> 'ReferentToken':
     if (t is None):
         return None
     t0 = t
     tt = t
     mc = tt.get_morph_class_in_dictionary()
     preamb = None
     if (mc.is_conjunction):
         return None
     if (t.is_value("LET", None)):
         return None
     if (mc.is_preposition or mc.is_misc or mc.is_adverb):
         if (not MiscHelper.is_eng_article(tt)):
             tt = tt.next0_
             first_pass3131 = True
             while True:
                 if first_pass3131: first_pass3131 = False
                 else: tt = tt.next0_
                 if (not (tt is not None)): break
                 if (tt.is_comma):
                     break
                 if (tt.is_char('(')):
                     br = BracketHelper.try_parse(tt, BracketParseAttr.NO,
                                                  100)
                     if (br is not None):
                         tt = br.end_token
                         continue
                 if (MiscHelper.can_be_start_of_sentence(tt)):
                     break
                 npt0 = NounPhraseHelper.try_parse(
                     tt,
                     Utils.valToEnum(
                         (NounPhraseParseAttr.PARSENUMERICASADJECTIVE) |
                         (NounPhraseParseAttr.REFERENTCANBENOUN),
                         NounPhraseParseAttr), 0, None)
                 if (npt0 is not None):
                     tt = npt0.end_token
                     continue
                 if (tt.get_morph_class_in_dictionary().is_verb):
                     break
             if (tt is None or not tt.is_comma or tt.next0_ is None):
                 return None
             preamb = MetaToken(t0, tt.previous)
             tt = tt.next0_
     t1 = tt
     mc = tt.get_morph_class_in_dictionary()
     npt = NounPhraseHelper.try_parse(
         tt,
         Utils.valToEnum((NounPhraseParseAttr.PARSENUMERICASADJECTIVE) |
                         (NounPhraseParseAttr.REFERENTCANBENOUN) |
                         (NounPhraseParseAttr.PARSEADVERBS),
                         NounPhraseParseAttr), 0, None)
     if (npt is None and (isinstance(tt, TextToken))):
         if (tt.chars.is_all_upper):
             npt = NounPhraseToken(tt, tt)
         elif (not tt.chars.is_all_lower):
             if (mc.is_proper or preamb is not None):
                 npt = NounPhraseToken(tt, tt)
     if (npt is None):
         return None
     if (mc.is_personal_pronoun):
         return None
     t2 = npt.end_token.next0_
     if (t2 is None or MiscHelper.can_be_start_of_sentence(t2)
             or not (isinstance(t2, TextToken))):
         return None
     if (not t2.get_morph_class_in_dictionary().is_verb):
         return None
     t3 = t2
     tt = t2.next0_
     while tt is not None:
         if (not tt.get_morph_class_in_dictionary().is_verb):
             break
         tt = tt.next0_
     first_pass3132 = True
     while True:
         if first_pass3132: first_pass3132 = False
         else: tt = tt.next0_
         if (not (tt is not None)): break
         if (tt.next0_ is None):
             t3 = tt
             break
         if (tt.is_char_of(".;!?")):
             if (MiscHelper.can_be_start_of_sentence(tt.next0_)):
                 t3 = tt
                 break
         if (not (isinstance(tt, TextToken))):
             continue
         if (BracketHelper.can_be_start_of_sequence(tt, False, False)):
             br = BracketHelper.try_parse(tt, BracketParseAttr.NO, 100)
             if (br is not None):
                 tt = br.end_token
                 continue
     tt = t3
     if (t3.is_char_of(";.!?")):
         tt = tt.previous
     txt = MiscHelper.get_text_value(
         t2, tt,
         Utils.valToEnum(
             (GetTextAttr.KEEPREGISTER) | (GetTextAttr.KEEPQUOTES),
             GetTextAttr))
     if (txt is None or (len(txt) < 15)):
         return None
     if (t0 != t1):
         tt = t1.previous
         if (tt.is_comma):
             tt = tt.previous
         txt0 = MiscHelper.get_text_value(
             t0, tt,
             Utils.valToEnum(
                 (GetTextAttr.KEEPREGISTER) | (GetTextAttr.KEEPQUOTES),
                 GetTextAttr))
         if (txt0 is not None and len(txt0) > 10):
             if (t0.chars.is_capital_upper):
                 txt0 = ((str.lower(txt0[0])) + txt0[1:])
             txt = "{0}, {1}".format(txt, txt0)
     tt = t1
     if (MiscHelper.is_eng_article(tt)):
         tt = tt.next0_
     nam = MiscHelper.get_text_value(tt, t2.previous,
                                     GetTextAttr.KEEPQUOTES)
     if (nam.startswith("SO-CALLED")):
         nam = nam[9:].strip()
     dr = DefinitionReferent()
     dr.kind = DefinitionKind.ASSERTATION
     dr.add_slot(DefinitionReferent.ATTR_TERMIN, nam, False, 0)
     dr.add_slot(DefinitionReferent.ATTR_VALUE, txt, False, 0)
     return ReferentToken(dr, t0, t3)
 def __try_parse(t : 'Token', prev : 'WeaponItemToken', after_conj : bool, attach_high : bool=False) -> 'WeaponItemToken':
     if (t is None): 
         return None
     if (BracketHelper.is_bracket(t, True)): 
         wit = WeaponItemToken.__try_parse(t.next0_, prev, after_conj, attach_high)
         if (wit is not None): 
             if (wit.end_token.next0_ is None): 
                 wit.begin_token = t
                 return wit
             if (BracketHelper.is_bracket(wit.end_token.next0_, True)): 
                 wit.begin_token = t
                 wit.end_token = wit.end_token.next0_
                 return wit
     tok = WeaponItemToken.M_ONTOLOGY.try_parse(t, TerminParseAttr.NO)
     if (tok is not None): 
         res = WeaponItemToken(t, tok.end_token)
         res.typ = (Utils.valToEnum(tok.termin.tag, WeaponItemToken.Typs))
         if (res.typ == WeaponItemToken.Typs.NOUN): 
             res.value = tok.termin.canonic_text
             if (tok.termin.tag2 is not None): 
                 res.is_doubt = True
             tt = res.end_token.next0_
             first_pass3426 = True
             while True:
                 if first_pass3426: first_pass3426 = False
                 else: tt = tt.next0_
                 if (not (tt is not None)): break
                 if (tt.whitespaces_before_count > 2): 
                     break
                 wit = WeaponItemToken.__try_parse(tt, None, False, False)
                 if (wit is not None): 
                     if (wit.typ == WeaponItemToken.Typs.BRAND): 
                         res.__inner_tokens.append(wit)
                         tt = wit.end_token
                         res.end_token = tt
                         continue
                     break
                 if (not (isinstance(tt, TextToken))): 
                     break
                 mc = tt.get_morph_class_in_dictionary()
                 if (mc == MorphClass.ADJECTIVE): 
                     if (res.alt_value is None): 
                         res.alt_value = res.value
                     if (res.alt_value.endswith(res.value)): 
                         res.alt_value = res.alt_value[0:0+len(res.alt_value) - len(res.value)]
                     res.alt_value = "{0}{1} {2}".format(res.alt_value, tt.term, res.value)
                     res.end_token = tt
                     continue
                 break
             return res
         if (res.typ == WeaponItemToken.Typs.BRAND or res.typ == WeaponItemToken.Typs.NAME): 
             res.value = tok.termin.canonic_text
             return res
         if (res.typ == WeaponItemToken.Typs.MODEL): 
             res.value = tok.termin.canonic_text
             if (isinstance(tok.termin.tag2, list)): 
                 li = Utils.asObjectOrNull(tok.termin.tag2, list)
                 for to in li: 
                     wit = WeaponItemToken._new2758(t, tok.end_token, Utils.valToEnum(to.tag, WeaponItemToken.Typs), to.canonic_text, tok.begin_token == tok.end_token)
                     res.__inner_tokens.append(wit)
                     if (to.additional_vars is not None and len(to.additional_vars) > 0): 
                         wit.alt_value = to.additional_vars[0].canonic_text
             res.__correct_model()
             return res
     nnn = MiscHelper.check_number_prefix(t)
     if (nnn is not None): 
         tit = TransItemToken._attach_number(nnn, True)
         if (tit is not None): 
             res = WeaponItemToken._new2759(t, tit.end_token, WeaponItemToken.Typs.NUMBER)
             res.value = tit.value
             res.alt_value = tit.alt_value
             return res
     if (((isinstance(t, TextToken)) and t.chars.is_letter and t.chars.is_all_upper) and (t.length_char < 4)): 
         if ((t.next0_ is not None and ((t.next0_.is_hiphen or t.next0_.is_char('.'))) and (t.next0_.whitespaces_after_count < 2)) and (isinstance(t.next0_.next0_, NumberToken))): 
             res = WeaponItemToken._new2760(t, t.next0_, WeaponItemToken.Typs.MODEL, True)
             res.value = t.term
             res.__correct_model()
             return res
         if ((isinstance(t.next0_, NumberToken)) and not t.is_whitespace_after): 
             res = WeaponItemToken._new2760(t, t, WeaponItemToken.Typs.MODEL, True)
             res.value = t.term
             res.__correct_model()
             return res
         if (t.term == "СП" and (t.whitespaces_after_count < 3) and (isinstance(t.next0_, TextToken))): 
             pp = WeaponItemToken.__try_parse(t.next0_, None, False, False)
             if (pp is not None and ((pp.typ == WeaponItemToken.Typs.MODEL or pp.typ == WeaponItemToken.Typs.BRAND))): 
                 res = WeaponItemToken._new2759(t, t, WeaponItemToken.Typs.NOUN)
                 res.value = "ПИСТОЛЕТ"
                 res.alt_value = "СЛУЖЕБНЫЙ ПИСТОЛЕТ"
                 return res
     if (((isinstance(t, TextToken)) and t.chars.is_letter and not t.chars.is_all_lower) and t.length_char > 2): 
         ok = False
         if (prev is not None and ((prev.typ == WeaponItemToken.Typs.NOUN or prev.typ == WeaponItemToken.Typs.MODEL or prev.typ == WeaponItemToken.Typs.BRAND))): 
             ok = True
         elif (prev is None and t.previous is not None and t.previous.is_comma_and): 
             ok = True
         if (ok): 
             res = WeaponItemToken._new2760(t, t, WeaponItemToken.Typs.NAME, True)
             res.value = t.term
             if ((t.next0_ is not None and t.next0_.is_hiphen and (isinstance(t.next0_.next0_, TextToken))) and t.next0_.next0_.chars == t.chars): 
                 res.value = "{0}-{1}".format(res.value, t.next0_.next0_.term)
                 res.end_token = t.next0_.next0_
             if (prev is not None and prev.typ == WeaponItemToken.Typs.NOUN): 
                 res.typ = WeaponItemToken.Typs.BRAND
             if (res.end_token.next0_ is not None and res.end_token.next0_.is_hiphen and (isinstance(res.end_token.next0_.next0_, NumberToken))): 
                 res.typ = WeaponItemToken.Typs.MODEL
                 res.__correct_model()
             elif (not res.end_token.is_whitespace_after and (isinstance(res.end_token.next0_, NumberToken))): 
                 res.typ = WeaponItemToken.Typs.MODEL
                 res.__correct_model()
             return res
     if (t.is_value("МАРКА", None)): 
         res = WeaponItemToken.__try_parse(t.next0_, prev, after_conj, False)
         if (res is not None and res.typ == WeaponItemToken.Typs.BRAND): 
             res.begin_token = t
             return res
         if (BracketHelper.can_be_start_of_sequence(t.next0_, True, False)): 
             br = BracketHelper.try_parse(t.next0_, BracketParseAttr.NO, 100)
             if (br is not None): 
                 return WeaponItemToken._new2764(t, br.end_token, WeaponItemToken.Typs.BRAND, MiscHelper.get_text_value(br.begin_token, br.end_token, GetTextAttr.NO))
         if (((isinstance(t, TextToken)) and (isinstance(t.next0_, TextToken)) and t.next0_.length_char > 1) and not t.next0_.chars.is_all_lower): 
             return WeaponItemToken._new2764(t, t.next0_, WeaponItemToken.Typs.BRAND, t.term)
     if (t.is_value("КАЛИБР", "КАЛІБР")): 
         tt1 = t.next0_
         if (tt1 is not None and ((tt1.is_hiphen or tt1.is_char(':')))): 
             tt1 = tt1.next0_
         num = NumbersWithUnitToken.try_parse(tt1, None, False, False, False, False)
         if (num is not None and num.single_val is not None): 
             return WeaponItemToken._new2764(t, num.end_token, WeaponItemToken.Typs.CALIBER, NumberHelper.double_to_string(num.single_val))
     if (isinstance(t, NumberToken)): 
         num = NumbersWithUnitToken.try_parse(t, None, False, False, False, False)
         if (num is not None and num.single_val is not None): 
             if (len(num.units) == 1 and num.units[0].unit is not None and num.units[0].unit.name_cyr == "мм"): 
                 return WeaponItemToken._new2764(t, num.end_token, WeaponItemToken.Typs.CALIBER, NumberHelper.double_to_string(num.single_val))
             if (num.end_token.next0_ is not None and num.end_token.next0_.is_value("КАЛИБР", "КАЛІБР")): 
                 return WeaponItemToken._new2764(t, num.end_token.next0_, WeaponItemToken.Typs.CALIBER, NumberHelper.double_to_string(num.single_val))
     if (t.is_value("ПРОИЗВОДСТВО", "ВИРОБНИЦТВО")): 
         tt1 = t.next0_
         if (tt1 is not None and ((tt1.is_hiphen or tt1.is_char(':')))): 
             tt1 = tt1.next0_
         if (isinstance(tt1, ReferentToken)): 
             if ((isinstance(tt1.get_referent(), OrganizationReferent)) or (isinstance(tt1.get_referent(), GeoReferent))): 
                 return WeaponItemToken._new2769(t, tt1, WeaponItemToken.Typs.DEVELOPER, tt1.get_referent())
     return None
 def __get_name_without_brackets(begin: 'Token',
                                 end: 'Token',
                                 normalize_first_noun_group: bool = False,
                                 normal_first_group_single: bool = False,
                                 ignore_geo_referent: bool = False) -> str:
     res = None
     if (BracketHelper.can_be_start_of_sequence(begin, False, False)
             and BracketHelper.can_be_end_of_sequence(
                 end, False, begin, False)):
         begin = begin.next0_
         end = end.previous
     if (normalize_first_noun_group
             and not begin.morph.class0_.is_preposition):
         npt = NounPhraseHelper.try_parse(
             begin, NounPhraseParseAttr.REFERENTCANBENOUN, 0, None)
         if (npt is not None):
             if (npt.noun.get_morph_class_in_dictionary().is_undefined
                     and len(npt.adjectives) == 0):
                 npt = (None)
         if (npt is not None and npt.end_token.end_char > end.end_char):
             npt = (None)
         if (npt is not None):
             res = npt.get_normal_case_text(
                 None, (MorphNumber.SINGULAR if normal_first_group_single
                        else MorphNumber.UNDEFINED), MorphGender.UNDEFINED,
                 False)
             te = npt.end_token.next0_
             if (((te is not None and te.next0_ is not None and te.is_comma)
                  and (isinstance(te.next0_, TextToken))
                  and te.next0_.end_char <= end.end_char)
                     and te.next0_.morph.class0_.is_verb
                     and te.next0_.morph.class0_.is_adjective):
                 for it in te.next0_.morph.items:
                     if (it.gender == npt.morph.gender
                             or ((it.gender) & (npt.morph.gender)) !=
                         (MorphGender.UNDEFINED)):
                         if (not (
                             (it.case_) & npt.morph.case_).is_undefined):
                             if (it.number == npt.morph.number or
                                 ((it.number) & (npt.morph.number)) !=
                                 (MorphNumber.UNDEFINED)):
                                 var = te.next0_.term
                                 if (isinstance(it, MorphWordForm)):
                                     var = it.normal_case
                                 bi = MorphBaseInfo._new492(
                                     MorphClass.ADJECTIVE, npt.morph.gender,
                                     npt.morph.number, npt.morph.language)
                                 var = MorphologyService.get_wordform(
                                     var, bi)
                                 if (var is not None):
                                     res = "{0}, {1}".format(res, var)
                                     te = te.next0_.next0_
                                 break
             if (te is not None and te.end_char <= end.end_char):
                 s = ProperNameHelper.get_name_ex(te, end,
                                                  MorphClass.UNDEFINED,
                                                  MorphCase.UNDEFINED,
                                                  MorphGender.UNDEFINED,
                                                  True, ignore_geo_referent)
                 if (not Utils.isNullOrEmpty(s)):
                     if (not str.isalnum(s[0])):
                         res = "{0}{1}".format(res, s)
                     else:
                         res = "{0} {1}".format(res, s)
         elif ((isinstance(begin, TextToken))
               and begin.chars.is_cyrillic_letter):
             mm = begin.get_morph_class_in_dictionary()
             if (not mm.is_undefined):
                 res = begin.get_normal_case_text(mm, MorphNumber.UNDEFINED,
                                                  MorphGender.UNDEFINED,
                                                  False)
                 if (begin.end_char < end.end_char):
                     res = "{0} {1}".format(
                         res,
                         ProperNameHelper.get_name_ex(
                             begin.next0_, end, MorphClass.UNDEFINED,
                             MorphCase.UNDEFINED, MorphGender.UNDEFINED,
                             True, False))
     if (res is None):
         res = ProperNameHelper.get_name_ex(begin, end,
                                            MorphClass.UNDEFINED,
                                            MorphCase.UNDEFINED,
                                            MorphGender.UNDEFINED, True,
                                            ignore_geo_referent)
     if (not Utils.isNullOrEmpty(res)):
         k = 0
         i = len(res) - 1
         while i >= 0:
             if (res[i] == '*' or Utils.isWhitespace(res[i])):
                 pass
             else:
                 break
             i -= 1
             k += 1
         if (k > 0):
             if (k == len(res)):
                 return None
             res = res[0:0 + len(res) - k]
     return res
 def get_name_ex(begin: 'Token',
                 end: 'Token',
                 cla: 'MorphClass',
                 mc: 'MorphCase',
                 gender: 'MorphGender' = MorphGender.UNDEFINED,
                 ignore_brackets_and_hiphens: bool = False,
                 ignore_geo_referent: bool = False) -> str:
     if (end is None or begin is None):
         return None
     if (begin.end_char > end.begin_char and begin != end):
         return None
     res = io.StringIO()
     prefix = None
     t = begin
     first_pass3064 = True
     while True:
         if first_pass3064: first_pass3064 = False
         else: t = t.next0_
         if (not (t is not None and t.end_char <= end.end_char)): break
         if (res.tell() > 1000):
             break
         if (t.is_table_control_char):
             continue
         if (ignore_brackets_and_hiphens):
             if (BracketHelper.is_bracket(t, False)):
                 if (t == end):
                     break
                 if (t.is_char_of("(<[")):
                     br = BracketHelper.try_parse(t, BracketParseAttr.NO,
                                                  100)
                     if (br is not None and br.end_char <= end.end_char):
                         tmp = ProperNameHelper.get_name_ex(
                             br.begin_token.next0_, br.end_token.previous,
                             MorphClass.UNDEFINED, MorphCase.UNDEFINED,
                             MorphGender.UNDEFINED,
                             ignore_brackets_and_hiphens, False)
                         if (tmp is not None):
                             if ((br.end_char == end.end_char
                                  and br.begin_token.next0_
                                  == br.end_token.previous and
                                  not br.begin_token.next0_.chars.is_letter)
                                     and not (isinstance(
                                         br.begin_token.next0_,
                                         ReferentToken))):
                                 pass
                             else:
                                 print(" {0}{1}{2}".format(
                                     t.get_source_text(), tmp,
                                     br.end_token.get_source_text()),
                                       end="",
                                       file=res,
                                       flush=True)
                         t = br.end_token
                 continue
             if (t.is_hiphen):
                 if (t == end):
                     break
                 elif (t.is_whitespace_before or t.is_whitespace_after):
                     continue
         tt = Utils.asObjectOrNull(t, TextToken)
         if (tt is not None):
             if (not ignore_brackets_and_hiphens):
                 if ((tt.next0_ is not None and tt.next0_.is_hiphen and
                      (isinstance(tt.next0_.next0_, TextToken)))
                         and tt != end and tt.next0_ != end):
                     if (prefix is None):
                         prefix = tt.term
                     else:
                         prefix = "{0}-{1}".format(prefix, tt.term)
                     t = tt.next0_
                     if (t == end):
                         break
                     else:
                         continue
             s = None
             if (cla.value != (0) or not mc.is_undefined
                     or gender != MorphGender.UNDEFINED):
                 for wff in tt.morph.items:
                     wf = Utils.asObjectOrNull(wff, MorphWordForm)
                     if (wf is None):
                         continue
                     if (cla.value != (0)):
                         if ((((wf.class0_.value) & (cla.value))) == 0):
                             continue
                     if (not mc.is_undefined):
                         if (((wf.case_) & mc).is_undefined):
                             continue
                     if (gender != MorphGender.UNDEFINED):
                         if (((wf.gender) &
                              (gender)) == (MorphGender.UNDEFINED)):
                             continue
                     if (s is None or wf.normal_case == tt.term):
                         s = wf.normal_case
                 if (s is None and gender != MorphGender.UNDEFINED):
                     for wff in tt.morph.items:
                         wf = Utils.asObjectOrNull(wff, MorphWordForm)
                         if (wf is None):
                             continue
                         if (cla.value != (0)):
                             if ((((wf.class0_.value) & (cla.value))) == 0):
                                 continue
                         if (not mc.is_undefined):
                             if (((wf.case_) & mc).is_undefined):
                                 continue
                         if (s is None or wf.normal_case == tt.term):
                             s = wf.normal_case
             if (s is None):
                 s = tt.term
                 if (tt.chars.is_last_lower and tt.length_char > 2):
                     s = tt.get_source_text()
                     for i in range(len(s) - 1, -1, -1):
                         if (str.isupper(s[i])):
                             s = s[0:0 + i + 1]
                             break
             if (prefix is not None):
                 delim = "-"
                 if (ignore_brackets_and_hiphens):
                     delim = " "
                 s = "{0}{1}{2}".format(prefix, delim, s)
             prefix = (None)
             if (res.tell() > 0 and len(s) > 0):
                 if (str.isalnum(s[0])):
                     ch0 = Utils.getCharAtStringIO(res, res.tell() - 1)
                     if (ch0 == '-'):
                         pass
                     else:
                         print(' ', end="", file=res)
                 elif (not ignore_brackets_and_hiphens
                       and BracketHelper.can_be_start_of_sequence(
                           tt, False, False)):
                     print(' ', end="", file=res)
             print(s, end="", file=res)
         elif (isinstance(t, NumberToken)):
             if (res.tell() > 0):
                 if (not t.is_whitespace_before and Utils.getCharAtStringIO(
                         res,
                         res.tell() - 1) == '-'):
                     pass
                 else:
                     print(' ', end="", file=res)
             nt = Utils.asObjectOrNull(t, NumberToken)
             if ((t.morph.class0_.is_adjective
                  and nt.typ == NumberSpellingType.WORDS
                  and nt.begin_token == nt.end_token)
                     and (isinstance(nt.begin_token, TextToken))):
                 print(nt.begin_token.term, end="", file=res)
             else:
                 print(nt.value, end="", file=res)
         elif (isinstance(t, MetaToken)):
             if ((ignore_geo_referent and t != begin
                  and t.get_referent() is not None)
                     and t.get_referent().type_name == "GEO"):
                 continue
             s = ProperNameHelper.get_name_ex(t.begin_token, t.end_token,
                                              cla, mc, gender,
                                              ignore_brackets_and_hiphens,
                                              ignore_geo_referent)
             if (not Utils.isNullOrEmpty(s)):
                 if (res.tell() > 0):
                     if (not t.is_whitespace_before
                             and Utils.getCharAtStringIO(
                                 res,
                                 res.tell() - 1) == '-'):
                         pass
                     else:
                         print(' ', end="", file=res)
                 print(s, end="", file=res)
         if (t == end):
             break
     if (res.tell() == 0):
         return None
     return Utils.toStringStringIO(res)
 def try_attach(t: 'Token') -> 'TitleItemToken':
     tt = Utils.asObjectOrNull(t, TextToken)
     if (tt is not None):
         t1 = tt
         if (tt.term == "ТЕМА"):
             tit = TitleItemToken.try_attach(tt.next0_)
             if (tit is not None and tit.typ == TitleItemToken.Types.TYP):
                 t1 = tit.end_token
                 if (t1.next0_ is not None and t1.next0_.is_char(':')):
                     t1 = t1.next0_
                 return TitleItemToken._new2655(
                     t, t1, TitleItemToken.Types.TYPANDTHEME, tit.value)
             if (tt.next0_ is not None and tt.next0_.is_char(':')):
                 t1 = tt.next0_
             return TitleItemToken(tt, t1, TitleItemToken.Types.THEME)
         if (tt.term == "ПО" or tt.term == "НА"):
             if (tt.next0_ is not None
                     and tt.next0_.is_value("ТЕМА", None)):
                 t1 = tt.next0_
                 if (t1.next0_ is not None and t1.next0_.is_char(':')):
                     t1 = t1.next0_
                 return TitleItemToken(tt, t1, TitleItemToken.Types.THEME)
         if (tt.term == "ПЕРЕВОД" or tt.term == "ПЕР"):
             tt2 = tt.next0_
             if (tt2 is not None and tt2.is_char('.')):
                 tt2 = tt2.next0_
             if (isinstance(tt2, TextToken)):
                 if (tt2.term == "C" or tt2.term == "С"):
                     tt2 = tt2.next0_
                     if (isinstance(tt2, TextToken)):
                         return TitleItemToken(
                             t, tt2, TitleItemToken.Types.TRANSLATE)
         if (tt.term == "СЕКЦИЯ" or tt.term == "SECTION"
                 or tt.term == "СЕКЦІЯ"):
             t1 = tt.next0_
             if (t1 is not None and t1.is_char(':')):
                 t1 = t1.next0_
             br = BracketHelper.try_parse(t1, BracketParseAttr.NO, 100)
             if (br is not None):
                 t1 = br.end_token
             elif (t1 != tt.next0_):
                 while t1 is not None:
                     if (t1.is_newline_after):
                         break
                     t1 = t1.next0_
                 if (t1 is None):
                     return None
             if (t1 != tt.next0_):
                 return TitleItemToken(tt, t1, TitleItemToken.Types.DUST)
         t1 = (None)
         if (tt.is_value("СПЕЦИАЛЬНОСТЬ", "СПЕЦІАЛЬНІСТЬ")):
             t1 = tt.next0_
         elif (tt.morph.class0_.is_preposition and tt.next0_ is not None
               and tt.next0_.is_value("СПЕЦИАЛЬНОСТЬ", "СПЕЦІАЛЬНІСТЬ")):
             t1 = tt.next0_.next0_
         elif (tt.is_char('/') and tt.is_newline_before):
             t1 = tt.next0_
         if (t1 is not None):
             if (t1.is_char_of(":") or t1.is_hiphen):
                 t1 = t1.next0_
             spec = TitleItemToken.__try_attach_speciality(t1, True)
             if (spec is not None):
                 spec.begin_token = t
                 return spec
     sss = TitleItemToken.__try_attach_speciality(t, False)
     if (sss is not None):
         return sss
     if (isinstance(t, ReferentToken)):
         return None
     npt = NounPhraseHelper.try_parse(t, NounPhraseParseAttr.NO, 0, None)
     if (npt is not None):
         s = npt.get_normal_case_text(None, MorphNumber.UNDEFINED,
                                      MorphGender.UNDEFINED, False)
         tok = TitleItemToken.M_TERMINS.try_parse(npt.end_token,
                                                  TerminParseAttr.NO)
         if (tok is not None):
             ty = Utils.valToEnum(tok.termin.tag, TitleItemToken.Types)
             if (ty == TitleItemToken.Types.TYP):
                 tit = TitleItemToken.try_attach(tok.end_token.next0_)
                 if (tit is not None
                         and tit.typ == TitleItemToken.Types.THEME):
                     return TitleItemToken._new2655(
                         npt.begin_token, tit.end_token,
                         TitleItemToken.Types.TYPANDTHEME, s)
                 if (s == "РАБОТА" or s == "РОБОТА" or s == "ПРОЕКТ"):
                     return None
                 t1 = tok.end_token
                 if (s == "ДИССЕРТАЦИЯ" or s == "ДИСЕРТАЦІЯ"):
                     err = 0
                     ttt = t1.next0_
                     first_pass3394 = True
                     while True:
                         if first_pass3394: first_pass3394 = False
                         else: ttt = ttt.next0_
                         if (not (ttt is not None)): break
                         if (ttt.morph.class0_.is_preposition):
                             continue
                         if (ttt.is_value("СОИСКАНИЕ", "")):
                             continue
                         npt1 = NounPhraseHelper.try_parse(
                             ttt, NounPhraseParseAttr.NO, 0, None)
                         if (npt1 is not None and npt1.noun.is_value(
                                 "СТЕПЕНЬ", "СТУПІНЬ")):
                             ttt = npt1.end_token
                             t1 = ttt
                             continue
                         rt = t1.kit.process_referent("PERSON", ttt)
                         if (rt is not None and (isinstance(
                                 rt.referent, PersonPropertyReferent))):
                             ppr = Utils.asObjectOrNull(
                                 rt.referent, PersonPropertyReferent)
                             if (ppr.name == "доктор наук"):
                                 t1 = rt.end_token
                                 s = "ДОКТОРСКАЯ ДИССЕРТАЦИЯ"
                                 break
                             elif (ppr.name == "кандидат наук"):
                                 t1 = rt.end_token
                                 s = "КАНДИДАТСКАЯ ДИССЕРТАЦИЯ"
                                 break
                             elif (ppr.name == "магистр"):
                                 t1 = rt.end_token
                                 s = "МАГИСТЕРСКАЯ ДИССЕРТАЦИЯ"
                                 break
                         if (ttt.is_value("ДОКТОР", None)
                                 or ttt.is_value("КАНДИДАТ", None)
                                 or ttt.is_value("МАГИСТР", "МАГІСТР")):
                             t1 = ttt
                             npt1 = NounPhraseHelper.try_parse(
                                 ttt.next0_, NounPhraseParseAttr.NO, 0,
                                 None)
                             if (npt1 is not None
                                     and npt1.end_token.is_value(
                                         "НАУК", None)):
                                 t1 = npt1.end_token
                             s = ("МАГИСТЕРСКАЯ ДИССЕРТАЦИЯ"
                                  if ttt.is_value("МАГИСТР", "МАГІСТР") else
                                  ("ДОКТОРСКАЯ ДИССЕРТАЦИЯ" if ttt.is_value(
                                      "ДОКТОР", None) else
                                   "КАНДИДАТСКАЯ ДИССЕРТАЦИЯ"))
                             break
                         err += 1
                         if (err > 3):
                             break
                 if (t1.next0_ is not None and t1.next0_.is_char('.')):
                     t1 = t1.next0_
                 if (s.endswith("ОТЧЕТ") and t1.next0_ is not None
                         and t1.next0_.is_value("О", None)):
                     npt1 = NounPhraseHelper.try_parse(
                         t1.next0_, NounPhraseParseAttr.PARSEPREPOSITION, 0,
                         None)
                     if (npt1 is not None
                             and npt1.morph.case_.is_prepositional):
                         t1 = npt1.end_token
                 return TitleItemToken._new2655(npt.begin_token, t1, ty, s)
     tok1 = TitleItemToken.M_TERMINS.try_parse(t, TerminParseAttr.NO)
     if (tok1 is not None):
         t1 = tok1.end_token
         re = TitleItemToken(
             tok1.begin_token, t1,
             Utils.valToEnum(tok1.termin.tag, TitleItemToken.Types))
         return re
     if (BracketHelper.can_be_start_of_sequence(t, False, False)):
         tok1 = TitleItemToken.M_TERMINS.try_parse(t.next0_,
                                                   TerminParseAttr.NO)
         if (tok1 is not None and BracketHelper.can_be_end_of_sequence(
                 tok1.end_token.next0_, False, None, False)):
             t1 = tok1.end_token.next0_
             return TitleItemToken(
                 tok1.begin_token, t1,
                 Utils.valToEnum(tok1.termin.tag, TitleItemToken.Types))
     return None
Beispiel #19
0
 def parse(t : 'Token', max_char : int=0, prev : 'InstrToken'=None) -> 'InstrToken':
     from pullenti.ner.instrument.internal.InstrToken1 import InstrToken1
     is_start_of_line = False
     t00 = t
     if (t is not None): 
         is_start_of_line = t00.is_newline_before
         while t is not None:
             if (t.is_table_control_char and not t.is_char(chr(0x1F))): 
                 if (t.is_newline_after and not is_start_of_line): 
                     is_start_of_line = True
                 t = t.next0_
             else: 
                 break
     if (t is None): 
         return None
     if (t.is_newline_before): 
         is_start_of_line = True
     if (is_start_of_line): 
         if ((t.is_value("СОДЕРЖИМОЕ", "ВМІСТ") or t.is_value("СОДЕРЖАНИЕ", "ЗМІСТ") or t.is_value("ОГЛАВЛЕНИЕ", "ЗМІСТ")) or ((t.is_value("СПИСОК", None) and t.next0_ is not None and t.next0_.is_value("РАЗДЕЛ", None)))): 
             cont = InstrToken1.parse(t, True, None, 0, None, False, 0, False, False)
             if (cont is not None and cont.typ == InstrToken1.Types.INDEX): 
                 return InstrToken(t, cont.end_token)
     t0 = t
     t1 = None
     has_word = False
     first_pass3255 = True
     while True:
         if first_pass3255: first_pass3255 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (t.is_newline_before and t != t0): 
             break
         if (max_char > 0 and t.begin_char > max_char): 
             break
         if (is_start_of_line and t == t0): 
             if (t.is_value("ГЛАВА", None)): 
                 next0__ = InstrToken.parse(t.next0_, 0, None)
                 if (next0__ is not None and next0__.typ == ILTypes.PERSON): 
                     next0__.begin_token = t
                     return next0__
             tt = None
             if ((isinstance(t.get_referent(), PersonReferent)) or (isinstance(t.get_referent(), PersonPropertyReferent)) or (isinstance(t.get_referent(), InstrumentParticipantReferent))): 
                 return InstrToken.__correct_person(InstrToken._new1511(t00, t, ILTypes.PERSON, t))
             is_ref = False
             if (isinstance(t.get_referent(), PersonPropertyReferent)): 
                 tt = t.next0_
                 is_ref = True
             elif (prev is not None and prev.typ == ILTypes.PERSON): 
                 rt = t.kit.process_referent(PersonAnalyzer.ANALYZER_NAME, t)
                 if (rt is not None): 
                     if (isinstance(rt.referent, PersonReferent)): 
                         return InstrToken._new1512(t00, rt.end_token, ILTypes.PERSON)
                     tt = rt.end_token.next0_
             cou = 0
             t11 = (None if tt is None else tt.previous)
             first_pass3256 = True
             while True:
                 if first_pass3256: first_pass3256 = False
                 else: tt = tt.next0_
                 if (not (tt is not None)): break
                 if (tt.is_table_control_char): 
                     continue
                 re = tt.get_referent()
                 if (isinstance(re, PersonReferent)): 
                     return InstrToken._new1511(t00, tt, ILTypes.PERSON, tt)
                 if (isinstance(re, GeoReferent)): 
                     t11 = tt
                     continue
                 if (re is not None): 
                     break
                 if (DecreeToken.is_keyword(tt, False) is not None): 
                     break
                 if (tt.is_newline_before): 
                     cou += 1
                     if (cou > 4): 
                         break
             if (tt is None and is_ref): 
                 return InstrToken._new1511(t00, Utils.ifNotNull(t11, t), ILTypes.PERSON, t)
         dt = DecreeToken.try_attach(t, None, False)
         if (dt is not None): 
             if (dt.typ == DecreeToken.ItemType.TYP and not t.chars.is_all_lower): 
                 if (t != t0): 
                     break
                 has_verb_ = False
                 tt = dt.end_token
                 while tt is not None: 
                     if (tt.is_newline_before): 
                         break
                     elif ((isinstance(tt, TextToken)) and tt.is_pure_verb): 
                         has_verb_ = True
                         break
                     tt = tt.next0_
                 if (not has_verb_): 
                     res2 = InstrToken._new1515(t0, dt.end_token, ILTypes.TYP, Utils.ifNotNull(dt.full_value, dt.value))
                     if (res2.value == "ДОПОЛНИТЕЛЬНОЕ СОГЛАШЕНИЕ" or res2.value == "ДОДАТКОВА УГОДА"): 
                         if (res2.begin_char > 500 and res2.newlines_before_count > 1): 
                             res2.typ = ILTypes.APPENDIX
                     return res2
             if (dt.typ == DecreeToken.ItemType.NUMBER): 
                 if (t != t0): 
                     break
                 return InstrToken._new1515(t0, dt.end_token, ILTypes.REGNUMBER, dt.value)
             if (dt.typ == DecreeToken.ItemType.ORG): 
                 if (t != t0): 
                     break
                 return InstrToken._new1517(t0, dt.end_token, ILTypes.ORGANIZATION, dt.ref, dt.value)
             if (dt.typ == DecreeToken.ItemType.TERR): 
                 if (t != t0): 
                     break
                 re = InstrToken._new1517(t0, dt.end_token, ILTypes.GEO, dt.ref, dt.value)
                 t1 = re.end_token.next0_
                 if (t1 is not None and t1.is_char(',')): 
                     t1 = t1.next0_
                 if (t1 is not None and t1.is_value("КРЕМЛЬ", None)): 
                     re.end_token = t1
                 elif ((t1 is not None and t1.is_value("ДОМ", "БУДИНОК") and t1.next0_ is not None) and t1.next0_.is_value("СОВЕТ", "РАД")): 
                     re.end_token = t1.next0_
                     if (t1.next0_.next0_ is not None and (isinstance(t1.next0_.next0_.get_referent(), GeoReferent))): 
                         re.end_token = t1.next0_.next0_
                 return re
             if (dt.typ == DecreeToken.ItemType.OWNER): 
                 if (t != t0): 
                     break
                 if (dt.ref is not None and str(dt.ref.referent).startswith("агент")): 
                     dt = (None)
                 if (dt is not None): 
                     res1 = InstrToken._new1517(t0, dt.end_token, ILTypes.PERSON, dt.ref, dt.value)
                     return InstrToken.__correct_person(res1)
         if (BracketHelper.can_be_start_of_sequence(t, False, False)): 
             br = BracketHelper.try_parse(t, BracketParseAttr.NO, 100)
             if (br is not None): 
                 t1 = br.end_token
                 t = t1
                 continue
             if (t.next0_ is not None and BracketHelper.can_be_end_of_sequence(t.next0_, False, None, False)): 
                 t1 = t.next0_
                 t = t1
                 continue
         if (isinstance(t, TextToken)): 
             if (t.is_char('_')): 
                 t1 = t
                 continue
         r = t.get_referent()
         if (isinstance(r, DateReferent)): 
             tt = t
             if (tt.next0_ is not None and tt.next0_.is_char_of(",;")): 
                 tt = tt.next0_
             if (not t.is_newline_before and not tt.is_newline_after): 
                 t1 = tt
                 continue
             if (not has_word): 
                 return InstrToken._new1511(t, tt, ILTypes.DATE, t)
             if (t != t0): 
                 break
         has_word = True
         if (isinstance(r, InstrumentParticipantReferent)): 
             tt = t.begin_token
             first_pass3257 = True
             while True:
                 if first_pass3257: first_pass3257 = False
                 else: tt = tt.next0_
                 if (not (tt is not None and (tt.end_char < t.end_char))): break
                 rr = tt.get_referent()
                 if (rr is None): 
                     continue
                 if ((isinstance(rr, OrganizationReferent)) or (isinstance(rr, BankDataReferent)) or (isinstance(rr, UriReferent))): 
                     r = (None)
                     break
         if ((isinstance(r, PersonReferent)) or (isinstance(r, PersonPropertyReferent)) or (isinstance(r, InstrumentParticipantReferent))): 
             if (t != t0): 
                 break
             if (isinstance(r, InstrumentParticipantReferent)): 
                 pass
             res1 = InstrToken._new1511(t, t, ILTypes.PERSON, t)
             return InstrToken.__correct_person(res1)
         if (isinstance(r, OrganizationReferent)): 
             if (t != t0): 
                 break
             return InstrToken._new1511(t, t, ILTypes.ORGANIZATION, t)
         if (isinstance(r, DecreePartReferent)): 
             dpr = Utils.asObjectOrNull(r, DecreePartReferent)
             if (dpr.appendix is not None): 
                 if (t.is_newline_before or is_start_of_line): 
                     if (t.is_newline_after or t.whitespaces_before_count > 30): 
                         return InstrToken._new1515(t, t, ILTypes.APPENDIX, "ПРИЛОЖЕНИЕ")
                     ok = True
                     tt = t.next0_
                     first_pass3258 = True
                     while True:
                         if first_pass3258: first_pass3258 = False
                         else: tt = tt.next0_
                         if (not (tt is not None)): break
                         if (tt.is_newline_before): 
                             break
                         npt = NounPhraseHelper.try_parse(tt, NounPhraseParseAttr.NO, 0, None)
                         if (npt is not None): 
                             tt = npt.end_token
                             continue
                         ok = False
                         break
                     if (ok): 
                         return InstrToken._new1515(t, t, ILTypes.APPENDIX, "ПРИЛОЖЕНИЕ")
         if ((isinstance(r, DecreeReferent)) and r.kind == DecreeKind.PUBLISHER and t == t0): 
             res1 = InstrToken._new1512(t, t, ILTypes.APPROVED)
             tt = t.next0_
             first_pass3259 = True
             while True:
                 if first_pass3259: first_pass3259 = False
                 else: tt = tt.next0_
                 if (not (tt is not None)): break
                 if (tt.is_char_of(",;")): 
                     continue
                 if ((isinstance(tt.get_referent(), DecreeReferent)) and tt.get_referent().kind == DecreeKind.PUBLISHER): 
                     res1.end_token = t
                 else: 
                     break
             return res1
         if (t.is_value("ЗА", None) and t.next0_ is not None and t.is_newline_before): 
             rr = t.next0_.get_referent()
             if ((isinstance(rr, PersonReferent)) or (isinstance(rr, PersonPropertyReferent)) or (isinstance(rr, InstrumentParticipantReferent))): 
                 if (t != t0): 
                     break
                 res1 = InstrToken._new1511(t, t.next0_, ILTypes.PERSON, t.next0_)
                 t = t.next0_.next0_
                 if ((isinstance(rr, InstrumentParticipantReferent)) and t is not None): 
                     r = t.get_referent()
                     if ((r) is not None): 
                         if ((isinstance(r, PersonReferent)) or (isinstance(r, PersonPropertyReferent))): 
                             res1.end_token = t
                             res1.ref = (t)
                 return res1
         ii = 0
         while ii < len(InstrToken._m_directives): 
             if (t.is_value(InstrToken._m_directives[ii], None)): 
                 if (t.next0_ is not None and t.next0_.is_value("СЛЕДУЮЩЕЕ", "НАСТУПНЕ")): 
                     if (t != t0): 
                         break
                     t11 = t.next0_
                     ok = False
                     if (t11.next0_ is not None and t11.next0_.is_char_of(":.") and t11.next0_.is_newline_after): 
                         ok = True
                         t11 = t11.next0_
                     if (ok): 
                         return InstrToken._new1515(t, t11, ILTypes.DIRECTIVE, InstrToken._m_directives_norm[ii])
                 if (t.is_newline_after or ((t.next0_ is not None and t.next0_.is_char(':') and t.next0_.is_newline_after))): 
                     if (t != t0): 
                         break
                     if (not t.is_newline_before): 
                         if ((InstrToken._m_directives_norm[ii] != "ПРИКАЗ" and InstrToken._m_directives_norm[ii] != "ПОСТАНОВЛЕНИЕ" and InstrToken._m_directives_norm[ii] != "НАКАЗ") and InstrToken._m_directives_norm[ii] != "ПОСТАНОВУ"): 
                             break
                     return InstrToken._new1515(t, (t if t.is_newline_after else t.next0_), ILTypes.DIRECTIVE, InstrToken._m_directives_norm[ii])
                 break
             ii += 1
         if (t.is_newline_before and t.chars.is_letter and t.length_char == 1): 
             for d in InstrToken._m_directives: 
                 t11 = MiscHelper.try_attach_word_by_letters(d, t, True)
                 if (t11 is not None): 
                     if (t11.next0_ is not None and t11.next0_.is_char(':')): 
                         t11 = t11.next0_
                     return InstrToken._new1512(t, t11, ILTypes.DIRECTIVE)
         tte = (t.begin_token if isinstance(t, MetaToken) else t)
         term = (tte.term if isinstance(tte, TextToken) else None)
         if (is_start_of_line and not tte.chars.is_all_lower and t == t0): 
             npt = NounPhraseHelper.try_parse(tte, NounPhraseParseAttr.NO, 0, None)
             if (npt is not None and ((term == "ПРИЛОЖЕНИЯ" or term == "ДОДАТКИ"))): 
                 # if (tte.Next != null && tte.Next.IsChar(':'))
                 npt = (None)
             if (npt is not None and npt.morph.case_.is_nominative and (isinstance(npt.end_token, TextToken))): 
                 term1 = npt.end_token.term
                 if (((term1 == "ПРИЛОЖЕНИЕ" or term1 == "ДОДАТОК" or term1 == "МНЕНИЕ") or term1 == "ДУМКА" or term1 == "АКТ") or term1 == "ФОРМА" or term == "ЗАЯВКА"): 
                     tt1 = npt.end_token.next0_
                     dt1 = DecreeToken.try_attach(tt1, None, False)
                     if (dt1 is not None and dt1.typ == DecreeToken.ItemType.NUMBER): 
                         tt1 = dt1.end_token.next0_
                     elif (isinstance(tt1, NumberToken)): 
                         tt1 = tt1.next0_
                     elif ((isinstance(tt1, TextToken)) and tt1.length_char == 1 and tt1.chars.is_letter): 
                         tt1 = tt1.next0_
                     ok = True
                     if (tt1 is None): 
                         ok = False
                     elif (tt1.is_value("В", "У")): 
                         ok = False
                     elif (tt1.is_value("К", None) and tt1.is_newline_before): 
                         return InstrToken._new1515(t, t, ILTypes.APPENDIX, term1)
                     elif (not tt1.is_newline_before and InstrToken._check_entered(tt1) is not None): 
                         ok = False
                     elif (tt1 == t.next0_ and ((tt1.is_char(':') or ((tt1.is_value("НА", None) and term1 != "ЗАЯВКА"))))): 
                         ok = False
                     if (ok): 
                         br = BracketHelper.try_parse(tt1, BracketParseAttr.NO, 100)
                         if (br is not None): 
                             tt1 = br.end_token.next0_
                             if (br.end_token.next0_ is None or not br.end_token.is_newline_after or br.end_token.next0_.is_char_of(";,")): 
                                 ok = False
                             if (tt1 is not None and tt1.is_value("ПРИЛОЖЕНИЕ", "ДОДАТОК")): 
                                 ok = False
                     if (prev is not None and prev.typ == ILTypes.APPENDIX): 
                         ok = False
                     if (ok): 
                         cou = 0
                         ttt = tte.previous
                         while ttt is not None and (cou < 300): 
                             if (ttt.is_table_control_char): 
                                 if (not ttt.is_char(chr(0x1F))): 
                                     if (ttt == tte.previous and ttt.is_char(chr(0x1E))): 
                                         pass
                                     else: 
                                         ok = False
                                 break
                             ttt = ttt.previous; cou += 1
                     if (ok): 
                         it1 = InstrToken1.parse(t, True, None, 0, None, False, 0, False, False)
                         if (it1 is not None): 
                             if (it1.has_verb): 
                                 ok = False
                     if (ok and t.previous is not None): 
                         ttp = t.previous
                         first_pass3260 = True
                         while True:
                             if first_pass3260: first_pass3260 = False
                             else: ttp = ttp.previous
                             if (not (ttp is not None)): break
                             if (ttp.is_table_control_char and not ttp.is_char(chr(0x1F))): 
                                 continue
                             if (BracketHelper.is_bracket(ttp, False) and not BracketHelper.can_be_end_of_sequence(ttp, False, None, False)): 
                                 continue
                             if (ttp.is_char_of(";:")): 
                                 ok = False
                             break
                     if ((ok and t.previous is not None and (t.newlines_before_count < 3)) and not t.is_newline_after): 
                         lines = 0
                         ttp = t.previous
                         first_pass3261 = True
                         while True:
                             if first_pass3261: first_pass3261 = False
                             else: ttp = ttp.previous
                             if (not (ttp is not None)): break
                             if (not ttp.is_newline_before): 
                                 continue
                             while ttp is not None and (ttp.end_char < t.begin_char): 
                                 if (isinstance(ttp, NumberToken)): 
                                     pass
                                 elif ((isinstance(ttp, TextToken)) and ttp.length_char > 1): 
                                     if (ttp.is_value("ПРИЛОЖЕНИЕ", "ДОДАТОК")): 
                                         ok = False
                                     break
                                 else: 
                                     break
                                 ttp = ttp.next0_
                             lines += 1
                             if (lines > 1): 
                                 break
                     if (ok and ((term1 != "ПРИЛОЖЕНИЕ" and term1 != "ДОДАТОК" and term1 != "МНЕНИЕ"))): 
                         if (t.newlines_before_count < 3): 
                             ok = False
                     if (ok): 
                         return InstrToken._new1515(t, t, ILTypes.APPENDIX, term1)
         app = False
         if ((((term == "ОСОБОЕ" or term == "ОСОБЛИВЕ")) and t.next0_ is not None and t.next0_.is_value("МНЕНИЕ", "ДУМКА")) and t == t0 and is_start_of_line): 
             app = True
         if ((((term == "ДОПОЛНИТЕЛЬНОЕ" or term == "ДОДАТКОВА")) and t.next0_ is not None and t.next0_.is_value("СОГЛАШЕНИЕ", "УГОДА")) and t == t0 and is_start_of_line): 
             app = True
         if (app): 
             tt = t.next0_
             while tt is not None: 
                 if (tt.is_newline_before): 
                     break
                 elif (tt.get_morph_class_in_dictionary() == MorphClass.VERB): 
                     app = False
                     break
                 tt = tt.next0_
             if (app): 
                 return InstrToken._new1512(t, t.next0_, ILTypes.APPENDIX)
         if (not t.chars.is_all_lower and t == t0): 
             tt = InstrToken._check_approved(t)
             if (tt is not None): 
                 if (tt.next0_ is not None and (isinstance(tt.next0_.get_referent(), DecreeReferent))): 
                     return InstrToken._new1511(t, tt, ILTypes.APPROVED, tt.next0_.get_referent())
                 dt1 = DecreeToken.try_attach(tt.next0_, None, False)
                 if (dt1 is not None and dt1.typ == DecreeToken.ItemType.TYP): 
                     return InstrToken._new1512(t, tt, ILTypes.APPROVED)
         t1 = t
         is_start_of_line = False
     if (t1 is None): 
         return None
     res = InstrToken._new1512(t00, t1, ILTypes.UNDEFINED)
     res.no_words = True
     t = t0
     first_pass3262 = True
     while True:
         if first_pass3262: first_pass3262 = False
         else: t = t.next0_
         if (not (t is not None and t.end_char <= t1.end_char)): break
         if (not (isinstance(t, TextToken))): 
             if (isinstance(t, ReferentToken)): 
                 res.no_words = False
             continue
         if (not t.chars.is_letter): 
             continue
         res.no_words = False
         if (t.is_pure_verb): 
             res.has_verb = True
     if (t0.is_value("ВОПРОС", "ПИТАННЯ") and t0.next0_ is not None and t0.next0_.is_char_of(":.")): 
         res.typ = ILTypes.QUESTION
     return res
Beispiel #20
0
 def try_attach(t: 'Token') -> 'ParenthesisToken':
     if (t is None):
         return None
     tok = ParenthesisToken.__m_termins.try_parse(t, TerminParseAttr.NO)
     if (tok is not None):
         res = ParenthesisToken(t, tok.end_token)
         return res
     if (not (isinstance(t, TextToken))):
         return None
     mc = t.get_morph_class_in_dictionary()
     ok = False
     t1 = None
     if (mc.is_adverb):
         ok = True
     elif (mc.is_adjective):
         if (t.morph.contains_attr("сравн.", None)
                 and t.morph.contains_attr("кач.прил.", None)):
             ok = True
     if (ok and t.next0_ is not None):
         if (t.next0_.is_char(',')):
             return ParenthesisToken(t, t)
         t1 = t.next0_
         if (t1.get_morph_class_in_dictionary() == MorphClass.VERB):
             if (t1.morph.contains_attr("н.вр.", None)
                     and t1.morph.contains_attr("нес.в.", None)
                     and t1.morph.contains_attr("дейст.з.", None)):
                 return ParenthesisToken(t, t1)
     t1 = (None)
     if ((t.is_value("В", None) and t.next0_ is not None
          and t.next0_.is_value("СООТВЕТСТВИЕ", None))
             and t.next0_.next0_ is not None
             and t.next0_.next0_.morph.class0_.is_preposition):
         t1 = t.next0_.next0_.next0_
     elif (t.is_value("СОГЛАСНО", None)):
         t1 = t.next0_
     elif (t.is_value("В", None) and t.next0_ is not None):
         if (t.next0_.is_value("СИЛА", None)):
             t1 = t.next0_.next0_
         elif (t.next0_.morph.class0_.is_adjective
               or t.next0_.morph.class0_.is_pronoun):
             npt = NounPhraseHelper.try_parse(t.next0_,
                                              NounPhraseParseAttr.NO, 0,
                                              None)
             if (npt is not None):
                 if (npt.noun.is_value("ВИД", None)
                         or npt.noun.is_value("СЛУЧАЙ", None)
                         or npt.noun.is_value("СФЕРА", None)):
                     return ParenthesisToken(t, npt.end_token)
     if (t1 is not None):
         if (t1.next0_ is not None):
             npt1 = NounPhraseHelper.try_parse(t1, NounPhraseParseAttr.NO,
                                               0, None)
             if (npt1 is not None):
                 if (npt1.noun.is_value("НОРМА", None)
                         or npt1.noun.is_value("ПОЛОЖЕНИЕ", None)
                         or npt1.noun.is_value("УКАЗАНИЕ", None)):
                     t1 = npt1.end_token.next0_
         r = t1.get_referent()
         if (r is not None):
             res = ParenthesisToken._new1115(t, t1, r)
             if (t1.next0_ is not None and t1.next0_.is_comma):
                 sila = False
                 ttt = t1.next0_.next0_
                 first_pass3133 = True
                 while True:
                     if first_pass3133: first_pass3133 = False
                     else: ttt = ttt.next0_
                     if (not (ttt is not None)): break
                     if (ttt.is_value("СИЛА", None)
                             or ttt.is_value("ДЕЙСТВИЕ", None)):
                         sila = True
                         continue
                     if (ttt.is_comma):
                         if (sila):
                             res.end_token = ttt.previous
                         break
                     if (BracketHelper.can_be_start_of_sequence(
                             ttt, False, False)):
                         break
             return res
         npt = NounPhraseHelper.try_parse(t1, NounPhraseParseAttr.NO, 0,
                                          None)
         if (npt is not None):
             return ParenthesisToken(t, npt.end_token)
     tt = t
     if (tt.is_value("НЕ", None) and t is not None):
         tt = tt.next0_
     if (tt.morph.class0_.is_preposition and tt is not None):
         tt = tt.next0_
         npt1 = NounPhraseHelper.try_parse(tt, NounPhraseParseAttr.NO, 0,
                                           None)
         if (npt1 is not None):
             tt = npt1.end_token
             if (tt.next0_ is not None and tt.next0_.is_comma):
                 return ParenthesisToken(t, tt.next0_)
             if (npt1.noun.is_value("ОЧЕРЕДЬ", None)):
                 return ParenthesisToken(t, tt)
     if (t.is_value("ВЕДЬ", None)):
         return ParenthesisToken(t, t)
     return None
Beispiel #21
0
 def try_create_canonic_decree_ref_uri(t: 'Token') -> 'CanonicDecreeRefUri':
     if (not (isinstance(t, ReferentToken))):
         return None
     dr = Utils.asObjectOrNull(t.get_referent(), DecreeReferent)
     res = None
     if (dr is not None):
         if (dr.kind == DecreeKind.PUBLISHER):
             return None
         res = CanonicDecreeRefUri._new833(t.kit.sofa.text, dr,
                                           t.begin_char, t.end_char)
         if ((t.previous is not None and t.previous.is_char('(')
              and t.next0_ is not None) and t.next0_.is_char(')')):
             return res
         if (t.misc_attrs != 0):
             return res
         rt = Utils.asObjectOrNull(t, ReferentToken)
         if (rt.begin_token.is_char('(') and rt.end_token.is_char(')')):
             res = CanonicDecreeRefUri._new833(
                 t.kit.sofa.text, dr, rt.begin_token.next0_.begin_char,
                 rt.end_token.previous.end_char)
             return res
         next_decree_items = None
         if ((t.next0_ is not None and t.next0_.is_comma_and and
              (isinstance(t.next0_.next0_, ReferentToken))) and
             (isinstance(t.next0_.next0_.get_referent(), DecreeReferent))):
             next_decree_items = DecreeToken.try_attach_list(
                 t.next0_.next0_.begin_token, None, 10, False)
             if (next_decree_items is not None
                     and len(next_decree_items) > 1):
                 i = 0
                 while i < (len(next_decree_items) - 1):
                     if (next_decree_items[i].is_newline_after):
                         del next_decree_items[i + 1:i + 1 +
                                               len(next_decree_items) - i -
                                               1]
                         break
                     i += 1
         was_typ = False
         was_num = False
         tt = t.begin_token
         first_pass3090 = True
         while True:
             if first_pass3090: first_pass3090 = False
             else: tt = tt.next0_
             if (not (tt is not None and tt.end_char <= t.end_char)): break
             if (tt.begin_char == t.begin_char and tt.is_char('(')
                     and tt.next0_ is not None):
                 res.begin_char = tt.next0_.begin_char
             if (tt.is_char('(') and tt.next0_ is not None
                     and tt.next0_.is_value("ДАЛЕЕ", None)):
                 if (res.end_char >= tt.begin_char):
                     res.end_char = tt.previous.end_char
                 break
             if (tt.end_char == t.end_char and tt.is_char(')')):
                 res.end_char = tt.previous.end_char
                 tt1 = tt.previous
                 while tt1 is not None and tt1.begin_char >= res.begin_char:
                     if (tt1.is_char('(') and tt1.previous is not None):
                         if (res.begin_char < tt1.previous.begin_char):
                             res.end_char = tt1.previous.end_char
                     tt1 = tt1.previous
             li = DecreeToken.try_attach_list(tt, None, 10, False)
             if (li is not None and len(li) > 0):
                 ii = 0
                 while ii < (len(li) - 1):
                     if (li[ii].typ == DecreeToken.ItemType.TYP and
                             li[ii + 1].typ == DecreeToken.ItemType.TERR):
                         res.type_with_geo = MiscHelper.get_text_value(
                             li[ii].begin_token, li[ii + 1].end_token,
                             GetTextAttr.FIRSTNOUNGROUPTONOMINATIVESINGLE)
                     ii += 1
                 if ((next_decree_items is not None
                      and len(next_decree_items) > 1 and
                      (len(next_decree_items) < len(li)))
                         and next_decree_items[0].typ !=
                         DecreeToken.ItemType.TYP):
                     d = len(li) - len(next_decree_items)
                     j = 0
                     j = 0
                     while j < len(next_decree_items):
                         if (next_decree_items[j].typ != li[d + j].typ):
                             break
                         j += 1
                     if (j >= len(next_decree_items)):
                         del li[0:0 + d]
                         res.begin_char = li[0].begin_char
                 elif (
                     (next_decree_items is not None
                      and len(next_decree_items) == 1 and
                      next_decree_items[0].typ == DecreeToken.ItemType.NAME)
                         and len(li) == 2
                         and li[1].typ == DecreeToken.ItemType.NAME):
                     res.begin_char = li[1].begin_char
                     res.end_char = li[1].end_char
                     break
                 elif ((next_decree_items is not None
                        and len(next_decree_items) == 1
                        and next_decree_items[0].typ
                        == DecreeToken.ItemType.NUMBER) and
                       li[len(li) - 1].typ == DecreeToken.ItemType.NUMBER):
                     res.begin_char = li[len(li) - 1].begin_char
                     res.end_char = li[len(li) - 1].end_char
                 i = 0
                 first_pass3091 = True
                 while True:
                     if first_pass3091: first_pass3091 = False
                     else: i += 1
                     if (not (i < len(li))): break
                     l_ = li[i]
                     if (l_.begin_char > t.end_char):
                         del li[i:i + len(li) - i]
                         break
                     if (l_.typ == DecreeToken.ItemType.NAME):
                         if (not was_num):
                             if (dr.kind == DecreeKind.CONTRACT):
                                 continue
                             if (((i + 1) < len(li)) and (
                                 (li[i + 1].typ == DecreeToken.ItemType.DATE
                                  or li[i + 1].typ
                                  == DecreeToken.ItemType.NUMBER))):
                                 continue
                         ee = l_.begin_token.previous.end_char
                         if (ee > res.begin_char and (ee < res.end_char)):
                             res.end_char = ee
                         break
                     if (l_.typ == DecreeToken.ItemType.NUMBER):
                         was_num = True
                     if (i == 0):
                         if (l_.typ == DecreeToken.ItemType.TYP):
                             was_typ = True
                         elif (l_.typ == DecreeToken.ItemType.OWNER
                               or l_.typ == DecreeToken.ItemType.ORG):
                             if (((i + 1) < len(li)) and
                                 ((li[1].typ == DecreeToken.ItemType.DATE
                                   or li[1].typ
                                   == DecreeToken.ItemType.NUMBER))):
                                 was_typ = True
                         if (was_typ):
                             tt0 = l_.begin_token.previous
                             if (tt0 is not None and tt0.is_char('.')):
                                 tt0 = tt0.previous
                             if (tt0 is not None and
                                 ((tt0.is_value("УТВЕРЖДЕННЫЙ", None)
                                   or tt0.is_value("УТВЕРДИТЬ", None)
                                   or tt0.is_value("УТВ", None)))):
                                 if (l_.begin_char > res.begin_char):
                                     res.begin_char = l_.begin_char
                                     if (res.end_char < res.begin_char):
                                         res.end_char = t.end_char
                                     res.is_adopted = True
                 if (len(li) > 0):
                     tt = li[len(li) - 1].end_token
                     if (tt.is_char(')')):
                         tt = tt.previous
                     continue
             if (was_typ):
                 na = DecreeToken.try_attach_name(tt, dr.typ0, True, False)
                 if (na is not None and tt.begin_char > t.begin_char):
                     tt1 = na.end_token.next0_
                     if (tt1 is not None and tt1.is_char_of(",()")):
                         tt1 = tt1.next0_
                     if (tt1 is not None and (tt1.end_char < t.end_char)):
                         if (tt1.is_value("УТВЕРЖДЕННЫЙ", None)
                                 or tt1.is_value("УТВЕРДИТЬ", None)
                                 or tt1.is_value("УТВ", None)):
                             tt = tt1
                             continue
                     if (tt.previous is not None
                             and tt.previous.is_char(':')
                             and na.end_char <= res.end_char):
                         res.begin_char = tt.begin_char
                         break
                     if (tt.previous.end_char > res.begin_char):
                         res.end_char = tt.previous.end_char
                         break
         return res
     dpr = Utils.asObjectOrNull(t.get_referent(), DecreePartReferent)
     if (dpr is None):
         return None
     if ((t.previous is not None and t.previous.is_hiphen and
          (isinstance(t.previous.previous, ReferentToken))) and (isinstance(
              t.previous.previous.get_referent(), DecreePartReferent))):
         if (DecreePartReferent.create_range_referent(
                 Utils.asObjectOrNull(t.previous.previous.get_referent(),
                                      DecreePartReferent), dpr)
                 is not None):
             return None
     t1 = t
     has_diap = False
     diap_ref = None
     if ((t.next0_ is not None and t.next0_.is_hiphen and
          (isinstance(t.next0_.next0_, ReferentToken))) and
         (isinstance(t.next0_.next0_.get_referent(), DecreePartReferent))):
         diap = DecreePartReferent.create_range_referent(
             Utils.asObjectOrNull(dpr, DecreePartReferent),
             Utils.asObjectOrNull(t.next0_.next0_.get_referent(),
                                  DecreePartReferent))
         if (diap is not None):
             dpr = diap
             has_diap = True
             t1 = t.next0_.next0_
             diap_ref = (Utils.asObjectOrNull(t1, ReferentToken))
     res = CanonicDecreeRefUri._new835(t.kit.sofa.text, dpr, t.begin_char,
                                       t1.end_char, has_diap)
     if ((t.previous is not None and t.previous.is_char('(')
          and t1.next0_ is not None) and t1.next0_.is_char(')')):
         return res
     tt = t.begin_token
     while tt is not None and tt.end_char <= t.end_char:
         if (isinstance(tt.get_referent(), DecreeReferent)):
             if (tt.begin_char > t.begin_char):
                 res.end_char = tt.previous.end_char
                 if (tt.previous.morph.class0_.is_preposition
                         and tt.previous.previous is not None):
                     res.end_char = tt.previous.previous.end_char
             elif (tt.end_char < t.end_char):
                 res.begin_char = tt.begin_char
             break
         tt = tt.next0_
     has_same_before = DecreeHelper.__has_same_decree(t, dpr, True)
     has_same_after = DecreeHelper.__has_same_decree(t, dpr, False)
     ptmin = PartToken.ItemType.PREFIX
     ptmin2 = PartToken.ItemType.PREFIX
     max0_ = 0
     max2 = 0
     for s in dpr.slots:
         pt = PartToken._get_type_by_attr_name(s.type_name)
         if (pt == PartToken.ItemType.PREFIX):
             continue
         co = PartToken._get_rank(pt)
         if (co < 1):
             if (pt == PartToken.ItemType.PART
                     and dpr.find_slot(DecreePartReferent.ATTR_CLAUSE, None,
                                       True) is not None):
                 co = PartToken._get_rank(PartToken.ItemType.PARAGRAPH)
             else:
                 continue
         if (co > max0_):
             max2 = max0_
             ptmin2 = ptmin
             max0_ = co
             ptmin = pt
         elif (co > max2):
             max2 = co
             ptmin2 = pt
     if (ptmin != PartToken.ItemType.PREFIX):
         tt = t.begin_token
         while tt is not None and tt.end_char <= res.end_char:
             if (tt.begin_char >= res.begin_char):
                 pt = PartToken.try_attach(tt, None, False, False)
                 if (pt is not None and pt.typ == ptmin):
                     res.begin_char = pt.begin_char
                     res.end_char = pt.end_char
                     if (pt.typ == PartToken.ItemType.APPENDIX
                             and pt.end_token.is_value("К", None)
                             and pt.begin_token != pt.end_token):
                         res.end_char = pt.end_token.previous.end_char
                     if (pt.end_char == t.end_char):
                         if ((t.next0_ is not None and t.next0_.is_comma_and
                              and
                              (isinstance(t.next0_.next0_, ReferentToken)))
                                 and
                             (isinstance(t.next0_.next0_.get_referent(),
                                         DecreePartReferent))):
                             tt1 = t.next0_.next0_.begin_token
                             ok = True
                             if (tt1.chars.is_letter):
                                 ok = False
                             if (ok):
                                 for v in pt.values:
                                     res.begin_char = v.begin_char
                                     res.end_char = v.end_char
                                     break
                     if (not has_diap):
                         return res
                     break
             tt = tt.next0_
         if (has_diap and diap_ref is not None):
             tt = diap_ref.begin_token
             while tt is not None and tt.end_char <= diap_ref.end_char:
                 if (tt.is_char(',')):
                     break
                 if (tt != diap_ref.begin_token
                         and tt.is_whitespace_before):
                     break
                 res.end_char = tt.end_char
                 tt = tt.next0_
             return res
     if (((has_same_before or has_same_after))
             and ptmin != PartToken.ItemType.PREFIX):
         tt = t.begin_token
         first_pass3092 = True
         while True:
             if first_pass3092: first_pass3092 = False
             else: tt = tt.next0_
             if (not (tt is not None and tt.end_char <= res.end_char)):
                 break
             if (tt.begin_char >= res.begin_char):
                 pt = (PartToken.try_attach(tt, None, False, False)
                       if not has_same_before else None)
                 if (pt is not None):
                     if (pt.typ == ptmin):
                         for v in pt.values:
                             res.begin_char = v.begin_char
                             res.end_char = v.end_char
                             return res
                     tt = pt.end_token
                     continue
                 if ((isinstance(tt, NumberToken))
                         and tt.begin_char == res.begin_char):
                     res.end_char = tt.end_char
                     while tt is not None and tt.next0_ is not None:
                         if (not tt.next0_.is_char('.')
                                 or tt.is_whitespace_after
                                 or tt.next0_.is_whitespace_after):
                             break
                         if (not (isinstance(tt.next0_.next0_,
                                             NumberToken))):
                             break
                         tt = tt.next0_.next0_
                         res.end_char = tt.end_char
                     if (tt.next0_ is not None and tt.next0_.is_hiphen):
                         if (isinstance(tt.next0_.next0_, NumberToken)):
                             tt = tt.next0_.next0_
                             res.end_char = tt.end_char
                             while tt is not None and tt.next0_ is not None:
                                 if (not tt.next0_.is_char('.')
                                         or tt.is_whitespace_after
                                         or tt.next0_.is_whitespace_after):
                                     break
                                 if (not (isinstance(
                                         tt.next0_.next0_, NumberToken))):
                                     break
                                 tt = tt.next0_.next0_
                                 res.end_char = tt.end_char
                         elif (tt.next0_.next0_ is not None and
                               (isinstance(tt.next0_.next0_.get_referent(),
                                           DecreePartReferent))
                               and has_diap):
                             res.end_char = tt.next0_.next0_.begin_token.end_char
                     return res
                 if (BracketHelper.can_be_start_of_sequence(
                         tt, True, False)
                         and tt.begin_char == res.begin_char
                         and has_same_before):
                     br = BracketHelper.try_parse(tt, BracketParseAttr.NO,
                                                  100)
                     if (br is not None
                             and br.end_token.previous == tt.next0_):
                         res.end_char = br.end_char
                         return res
         return res
     if (not has_same_before and not has_same_after
             and ptmin != PartToken.ItemType.PREFIX):
         tt = t.begin_token
         while tt is not None and tt.end_char <= res.end_char:
             if (tt.begin_char >= res.begin_char):
                 pts = PartToken.try_attach_list(tt, False, 40)
                 if (pts is None or len(pts) == 0):
                     break
                 i = 0
                 while i < len(pts):
                     if (pts[i].typ == ptmin):
                         res.begin_char = pts[i].begin_char
                         res.end_char = pts[i].end_char
                         tt = pts[i].end_token
                         if (tt.next0_ is not None and tt.next0_.is_hiphen):
                             if (isinstance(tt.next0_.next0_, NumberToken)):
                                 res.end_char = tt.next0_.next0_.end_char
                             elif (tt.next0_.next0_ is not None
                                   and (isinstance(
                                       tt.next0_.next0_.get_referent(),
                                       DecreePartReferent)) and has_diap):
                                 res.end_char = tt.next0_.next0_.begin_token.end_char
                         return res
                     i += 1
             tt = tt.next0_
     return res