Example #1
0
 def tryAttachToExist(t: 'Token', p1: 'InstrumentParticipant',
                      p2: 'InstrumentParticipant') -> 'ReferentToken':
     if (t is None):
         return None
     if (t.begin_char >= 7674 and (t.begin_char < 7680)):
         pass
     pp = ParticipantToken.tryAttach(t, p1, p2, False)
     p = None
     rt = None
     if (pp is None or pp.kind != ParticipantToken.Kinds.PURE):
         pers = t.getReferent()
         if ((isinstance(pers, PersonReferent))
                 or (isinstance(pers, GeoReferent))
                 or (isinstance(pers, OrganizationReferent))):
             if (p1 is not None and p1._containsRef(pers)):
                 p = p1
             elif (p2 is not None and p2._containsRef(pers)):
                 p = p2
             if (p is not None):
                 rt = ReferentToken(p, t, t)
     else:
         if (p1 is not None
                 and ParticipantToken.__isTypesEqual(pp.typ, p1.typ)):
             p = p1
         elif (p2 is not None
               and ParticipantToken.__isTypesEqual(pp.typ, p2.typ)):
             p = p2
         if (p is not None):
             rt = ReferentToken(p, pp.begin_token, pp.end_token)
             if (rt.begin_token.previous is not None
                     and rt.begin_token.previous.isValue("ОТ", None)):
                 rt.begin_token = rt.begin_token.previous
     if (rt is None):
         return None
     if (rt.end_token.next0_ is not None
             and rt.end_token.next0_.isChar(':')):
         rt1 = ParticipantToken.tryAttachRequisites(
             rt.end_token.next0_.next0_, p, (p2 if p == p1 else p1), False)
         if (rt1 is not None):
             rt1.begin_token = rt.begin_token
             return rt1
         rt.end_token = rt.end_token.next0_
     while rt.end_token.next0_ is not None and (isinstance(
             rt.end_token.next0_.getReferent(), OrganizationReferent)):
         org0_ = Utils.asObjectOrNull(rt.end_token.next0_.getReferent(),
                                      OrganizationReferent)
         if (rt.referent.findSlot(None, org0_, True) is not None):
             rt.end_token = rt.end_token.next0_
             continue
         break
     return rt
Example #2
0
 def __try_attach_(self, pli : typing.List['PhoneItemToken'], ind : int, is_phone_before : bool, prev_phone : 'PhoneReferent', lev : int=0) -> 'ReferentToken':
     if (ind >= len(pli) or lev > 4): 
         return None
     country_code = None
     city_code = None
     j = ind
     if (prev_phone is not None and prev_phone._m_template is not None and pli[j].item_type == PhoneItemToken.PhoneItemType.NUMBER): 
         tmp = io.StringIO()
         jj = j
         first_pass3391 = True
         while True:
             if first_pass3391: first_pass3391 = False
             else: jj += 1
             if (not (jj < len(pli))): break
             if (pli[jj].item_type == PhoneItemToken.PhoneItemType.NUMBER): 
                 print(len(pli[jj].value), end="", file=tmp)
             elif (pli[jj].item_type == PhoneItemToken.PhoneItemType.DELIM): 
                 if (pli[jj].value == " "): 
                     break
                 print(pli[jj].value, end="", file=tmp)
                 continue
             else: 
                 break
             templ0 = Utils.toStringStringIO(tmp)
             if (templ0 == prev_phone._m_template): 
                 if ((jj + 1) < len(pli)): 
                     if (pli[jj + 1].item_type == PhoneItemToken.PhoneItemType.PREFIX and (jj + 2) == len(pli)): 
                         pass
                     else: 
                         del pli[jj + 1:jj + 1+len(pli) - jj - 1]
                 break
     if ((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.COUNTRYCODE): 
         country_code = pli[j].value
         if (country_code != "8"): 
             cc = PhoneHelper.get_country_prefix(country_code)
             if (cc is not None and (len(cc) < len(country_code))): 
                 city_code = country_code[len(cc):]
                 country_code = cc
         j += 1
     elif ((j < len(pli)) and pli[j].can_be_country_prefix): 
         k = j + 1
         if ((k < len(pli)) and pli[k].item_type == PhoneItemToken.PhoneItemType.DELIM): 
             k += 1
         rrt = self.__try_attach_(pli, k, is_phone_before, None, lev + 1)
         if (rrt is not None): 
             if ((((is_phone_before and pli[j + 1].item_type == PhoneItemToken.PhoneItemType.DELIM and pli[j + 1].begin_token.is_hiphen) and pli[j].item_type == PhoneItemToken.PhoneItemType.NUMBER and len(pli[j].value) == 3) and ((j + 2) < len(pli)) and pli[j + 2].item_type == PhoneItemToken.PhoneItemType.NUMBER) and len(pli[j + 2].value) == 3): 
                 pass
             else: 
                 country_code = pli[j].value
                 j += 1
     if (((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.NUMBER and ((pli[j].value[0] == '8' or pli[j].value[0] == '7'))) and country_code is None): 
         if (len(pli[j].value) == 1): 
             country_code = pli[j].value
             j += 1
         elif (len(pli[j].value) == 4): 
             country_code = pli[j].value[0:0+1]
             if (city_code is None): 
                 city_code = pli[j].value[1:]
             else: 
                 city_code += pli[j].value[1:]
             j += 1
         elif (len(pli[j].value) == 11 and j == (len(pli) - 1) and is_phone_before): 
             ph0 = PhoneReferent()
             if (pli[j].value[0] != '8'): 
                 ph0.country_code = pli[j].value[0:0+1]
             ph0.number = pli[j].value[1:1+3] + pli[j].value[4:]
             return ReferentToken(ph0, pli[0].begin_token, pli[j].end_token)
         elif (city_code is None and len(pli[j].value) > 3 and ((j + 1) < len(pli))): 
             sum0_ = 0
             for it in pli: 
                 if (it.item_type == PhoneItemToken.PhoneItemType.NUMBER): 
                     sum0_ += len(it.value)
             if (sum0_ == 11): 
                 city_code = pli[j].value[1:]
                 j += 1
     if ((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.CITYCODE): 
         if (city_code is None): 
             city_code = pli[j].value
         else: 
             city_code += pli[j].value
         j += 1
     if ((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.DELIM): 
         j += 1
     if ((country_code == "8" and city_code is None and ((j + 3) < len(pli))) and pli[j].item_type == PhoneItemToken.PhoneItemType.NUMBER): 
         if (len(pli[j].value) == 3 or len(pli[j].value) == 4): 
             city_code = pli[j].value
             j += 1
             if ((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.DELIM): 
                 j += 1
     normal_num_len = 0
     if (country_code == "421"): 
         normal_num_len = 9
     num = io.StringIO()
     templ = io.StringIO()
     part_length = list()
     delim = None
     ok = False
     additional = None
     std = False
     if (country_code is not None and ((j + 4) < len(pli)) and j > 0): 
         if (((((pli[j - 1].value == "-" or pli[j - 1].item_type == PhoneItemToken.PhoneItemType.COUNTRYCODE)) and pli[j].item_type == PhoneItemToken.PhoneItemType.NUMBER and pli[j + 1].item_type == PhoneItemToken.PhoneItemType.DELIM) and pli[j + 2].item_type == PhoneItemToken.PhoneItemType.NUMBER and pli[j + 3].item_type == PhoneItemToken.PhoneItemType.DELIM) and pli[j + 4].item_type == PhoneItemToken.PhoneItemType.NUMBER): 
             if ((((len(pli[j].value) + len(pli[j + 2].value)) == 6 or ((len(pli[j].value) == 4 and len(pli[j + 2].value) == 5)))) and ((len(pli[j + 4].value) == 4 or len(pli[j + 4].value) == 1))): 
                 print(pli[j].value, end="", file=num)
                 print(pli[j + 2].value, end="", file=num)
                 print(pli[j + 4].value, end="", file=num)
                 print("{0}{1}{2}{3}{4}".format(len(pli[j].value), pli[j + 1].value, len(pli[j + 2].value), pli[j + 3].value, len(pli[j + 4].value)), end="", file=templ, flush=True)
                 std = True
                 ok = True
                 j += 5
     first_pass3392 = True
     while True:
         if first_pass3392: first_pass3392 = False
         else: j += 1
         if (not (j < len(pli))): break
         if (std): 
             break
         if (pli[j].item_type == PhoneItemToken.PhoneItemType.DELIM): 
             if (pli[j].is_in_brackets): 
                 continue
             if (j > 0 and pli[j - 1].is_in_brackets): 
                 continue
             if (templ.tell() > 0): 
                 print(pli[j].value, end="", file=templ)
             if (delim is None): 
                 delim = pli[j].value
             elif (pli[j].value != delim): 
                 if ((len(part_length) == 2 and ((part_length[0] == 3 or part_length[0] == 4)) and city_code is None) and part_length[1] == 3): 
                     city_code = Utils.toStringStringIO(num)[0:0+part_length[0]]
                     Utils.removeStringIO(num, 0, part_length[0])
                     del part_length[0]
                     delim = pli[j].value
                     continue
                 if (is_phone_before and ((j + 1) < len(pli)) and pli[j + 1].item_type == PhoneItemToken.PhoneItemType.NUMBER): 
                     if (num.tell() < 6): 
                         continue
                     if (normal_num_len > 0 and (num.tell() + len(pli[j + 1].value)) == normal_num_len): 
                         continue
                 break
             else: 
                 continue
             ok = False
         elif (pli[j].item_type == PhoneItemToken.PhoneItemType.NUMBER): 
             if (num.tell() == 0 and pli[j].begin_token.previous is not None and pli[j].begin_token.previous.is_table_control_char): 
                 tt = pli[len(pli) - 1].end_token.next0_
                 if (tt is not None and tt.is_char_of(",.")): 
                     tt = tt.next0_
                 if (isinstance(tt, NumberToken)): 
                     return None
             if ((num.tell() + len(pli[j].value)) > 13): 
                 if (j > 0 and pli[j - 1].item_type == PhoneItemToken.PhoneItemType.DELIM): 
                     j -= 1
                 ok = True
                 break
             print(pli[j].value, end="", file=num)
             part_length.append(len(pli[j].value))
             print(len(pli[j].value), end="", file=templ)
             ok = True
             if (num.tell() > 10): 
                 j += 1
                 if ((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.ADDNUMBER): 
                     additional = pli[j].value
                     j += 1
                 break
         elif (pli[j].item_type == PhoneItemToken.PhoneItemType.ADDNUMBER): 
             additional = pli[j].value
             j += 1
             break
         else: 
             break
     if ((j == (len(pli) - 1) and pli[j].is_in_brackets and ((len(pli[j].value) == 3 or len(pli[j].value) == 4))) and additional is None): 
         additional = pli[j].value
         j += 1
     if ((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.PREFIX and pli[j].is_in_brackets): 
         is_phone_before = True
         j += 1
     if ((country_code is None and city_code is not None and len(city_code) > 3) and (num.tell() < 8) and city_code[0] != '8'): 
         if ((len(city_code) + num.tell()) == 10): 
             pass
         else: 
             cc = PhoneHelper.get_country_prefix(city_code)
             if (cc is not None): 
                 if (len(cc) > 1 and (len(city_code) - len(cc)) > 1): 
                     country_code = cc
                     city_code = city_code[len(cc):]
     if (country_code is None and city_code is not None and city_code.startswith("00")): 
         cc = PhoneHelper.get_country_prefix(city_code[2:])
         if (cc is not None): 
             if (len(city_code) > (len(cc) + 3)): 
                 country_code = cc
                 city_code = city_code[len(cc) + 2:]
     if (num.tell() == 0 and city_code is not None): 
         if (len(city_code) == 10): 
             print(city_code[3:], end="", file=num)
             part_length.append(num.tell())
             city_code = city_code[0:0+3]
             ok = True
         elif (((len(city_code) == 9 or len(city_code) == 11 or len(city_code) == 8)) and ((is_phone_before or country_code is not None))): 
             print(city_code, end="", file=num)
             part_length.append(num.tell())
             city_code = (None)
             ok = True
     if (num.tell() < 4): 
         ok = False
     if (num.tell() < 7): 
         if (city_code is not None and (len(city_code) + num.tell()) > 7): 
             if (not is_phone_before and len(city_code) == 3): 
                 ii = 0
                 ii = 0
                 while ii < len(part_length): 
                     if (part_length[ii] == 3): 
                         pass
                     elif (part_length[ii] > 3): 
                         break
                     elif ((ii < (len(part_length) - 1)) or (part_length[ii] < 2)): 
                         break
                     ii += 1
                 if (ii >= len(part_length)): 
                     if (country_code == "61"): 
                         pass
                     else: 
                         ok = False
         elif (((num.tell() == 6 or num.tell() == 5)) and ((len(part_length) >= 1 and len(part_length) <= 3)) and is_phone_before): 
             if (pli[0].item_type == PhoneItemToken.PhoneItemType.PREFIX and pli[0].kind == PhoneKind.HOME): 
                 ok = False
         elif (prev_phone is not None and prev_phone.number is not None and ((len(prev_phone.number) == num.tell() or len(prev_phone.number) == (num.tell() + 3) or len(prev_phone.number) == (num.tell() + 4)))): 
             pass
         elif (num.tell() > 4 and prev_phone is not None and Utils.toStringStringIO(templ) == prev_phone._m_template): 
             ok = True
         else: 
             ok = False
     if (delim == "." and country_code is None and city_code is None): 
         ok = False
     if ((is_phone_before and country_code is None and city_code is None) and num.tell() > 10): 
         cc = PhoneHelper.get_country_prefix(Utils.toStringStringIO(num))
         if (cc is not None): 
             if ((num.tell() - len(cc)) == 9): 
                 country_code = cc
                 Utils.removeStringIO(num, 0, len(cc))
                 ok = True
     if (ok): 
         if (std): 
             pass
         elif (prev_phone is not None and prev_phone.number is not None and (((len(prev_phone.number) == num.tell() or len(prev_phone.number) == (num.tell() + 3) or len(prev_phone.number) == (num.tell() + 4)) or prev_phone._m_template == Utils.toStringStringIO(templ)))): 
             pass
         elif ((len(part_length) == 3 and part_length[0] == 3 and part_length[1] == 2) and part_length[2] == 2): 
             pass
         elif (len(part_length) == 3 and is_phone_before): 
             pass
         elif ((len(part_length) == 4 and (((part_length[0] + part_length[1]) == 3)) and part_length[2] == 2) and part_length[3] == 2): 
             pass
         elif ((len(part_length) == 4 and part_length[0] == 3 and part_length[1] == 3) and part_length[2] == 2 and part_length[3] == 2): 
             pass
         elif (len(part_length) == 5 and (part_length[1] + part_length[2]) == 4 and (part_length[3] + part_length[4]) == 4): 
             pass
         elif (len(part_length) > 4): 
             ok = False
         elif (len(part_length) > 3 and city_code is not None): 
             ok = False
         elif ((is_phone_before or city_code is not None or country_code is not None) or additional is not None): 
             ok = True
         else: 
             ok = False
             if (((num.tell() == 6 or num.tell() == 7)) and (len(part_length) < 4) and j > 0): 
                 next_ph = self.__get_next_phone(pli[j - 1].end_token.next0_, lev + 1)
                 if (next_ph is not None): 
                     d = len(next_ph.number) - num.tell()
                     if (d == 0 or d == 3 or d == 4): 
                         ok = True
     end = (pli[j - 1].end_token if j > 0 else None)
     if (end is None): 
         ok = False
     if ((ok and city_code is None and country_code is None) and prev_phone is None and not is_phone_before): 
         if (not end.is_whitespace_after and end.next0_ is not None): 
             tt = end.next0_
             if (tt.is_char_of(".,)") and tt.next0_ is not None): 
                 tt = tt.next0_
             if (not tt.is_whitespace_before): 
                 ok = False
     if (not ok): 
         return None
     if (templ.tell() > 0 and not str.isdigit(Utils.getCharAtStringIO(templ, templ.tell() - 1))): 
         Utils.setLengthStringIO(templ, templ.tell() - 1)
     if ((country_code is None and city_code is not None and len(city_code) > 3) and num.tell() > 6): 
         cc = PhoneHelper.get_country_prefix(city_code)
         if (cc is not None and ((len(cc) + 1) < len(city_code))): 
             country_code = cc
             city_code = city_code[len(cc):]
     if (pli[0].begin_token.previous is not None): 
         if (pli[0].begin_token.previous.is_value("ГОСТ", None) or pli[0].begin_token.previous.is_value("ТУ", None)): 
             return None
     ph = PhoneReferent()
     if (country_code is not None): 
         ph.country_code = country_code
     number = Utils.toStringStringIO(num)
     if ((city_code is None and num.tell() > 7 and len(part_length) > 0) and (part_length[0] < 5)): 
         city_code = number[0:0+part_length[0]]
         number = number[part_length[0]:]
     if (city_code is None and num.tell() == 11 and Utils.getCharAtStringIO(num, 0) == '8'): 
         city_code = number[1:1+3]
         number = number[4:]
     if (city_code is None and num.tell() == 10): 
         city_code = number[0:0+3]
         number = number[3:]
     if (city_code is not None): 
         number = (city_code + number)
     elif (country_code is None and prev_phone is not None): 
         ok1 = False
         if (len(prev_phone.number) >= (len(number) + 2)): 
             ok1 = True
         elif (templ.tell() > 0 and prev_phone._m_template is not None and LanguageHelper.ends_with(prev_phone._m_template, Utils.toStringStringIO(templ))): 
             ok1 = True
         if (ok1 and len(prev_phone.number) > len(number)): 
             number = (prev_phone.number[0:0+len(prev_phone.number) - len(number)] + number)
     if (ph.country_code is None and prev_phone is not None and prev_phone.country_code is not None): 
         if (len(prev_phone.number) == len(number)): 
             ph.country_code = prev_phone.country_code
     ok = False
     for d in number: 
         if (d != '0'): 
             ok = True
             break
     if (not ok): 
         return None
     if (country_code is not None): 
         if (len(number) < 7): 
             return None
     else: 
         s = PhoneHelper.get_country_prefix(number)
         if (s is not None): 
             num2 = number[len(s):]
             if (len(num2) >= 10 and len(num2) <= 11): 
                 number = num2
                 if (s != "7"): 
                     ph.country_code = s
         if (len(number) == 8 and prev_phone is None): 
             return None
     if (len(number) > 11): 
         if ((len(number) < 14) and ((country_code == "1" or country_code == "43"))): 
             pass
         else: 
             return None
     ph.number = number
     if (additional is not None): 
         ph.add_slot(PhoneReferent.ATTR_ADDNUMBER, additional, True, 0)
     if (not is_phone_before and end.next0_ is not None and not end.is_newline_after): 
         if (end.next0_.is_char_of("+=") or end.next0_.is_hiphen): 
             return None
     if (country_code is not None and country_code == "7"): 
         if (len(number) != 10): 
             return None
     ph._m_template = Utils.toStringStringIO(templ)
     if (j == (len(pli) - 1) and pli[j].item_type == PhoneItemToken.PhoneItemType.PREFIX and not pli[j].is_newline_before): 
         end = pli[j].end_token
         if (pli[j].kind != PhoneKind.UNDEFINED): 
             ph.kind = pli[j].kind
     res = ReferentToken(ph, pli[0].begin_token, end)
     if (pli[0].item_type == PhoneItemToken.PhoneItemType.PREFIX and pli[0].end_token.next0_.is_table_control_char): 
         res.begin_token = pli[1].begin_token
     return res
Example #3
0
 def process(self, kit : 'AnalysisKit') -> None:
     """ Основная функция выделения объектов
     
     Args:
         container: 
         lastStage: 
     
     """
     ad = kit.getAnalyzerData(self)
     t = kit.first_token
     first_pass3149 = True
     while True:
         if first_pass3149: first_pass3149 = False
         else: t = t.next0_
         if (not (t is not None)): break
         tt = t
         tok = UriAnalyzer.__m_schemes.tryParse(t, TerminParseAttr.NO)
         if (tok is not None): 
             i = (tok.termin.tag)
             tt = tok.end_token
             if (tt.next0_ is not None and tt.next0_.isChar('(')): 
                 tok1 = UriAnalyzer.__m_schemes.tryParse(tt.next0_.next0_, TerminParseAttr.NO)
                 if ((tok1 is not None and tok1.termin.canonic_text == tok.termin.canonic_text and tok1.end_token.next0_ is not None) and tok1.end_token.next0_.isChar(')')): 
                     tt = tok1.end_token.next0_
             if (i == 0): 
                 if ((tt.next0_ is None or ((not tt.next0_.isCharOf(":|") and not tt.is_table_control_char)) or tt.next0_.is_whitespace_before) or tt.next0_.whitespaces_after_count > 2): 
                     continue
                 t1 = tt.next0_.next0_
                 while t1 is not None and t1.isCharOf("/\\"):
                     t1 = t1.next0_
                 if (t1 is None or t1.whitespaces_before_count > 2): 
                     continue
                 ut = UriItemToken.attachUriContent(t1, False)
                 if (ut is None): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2557(tok.termin.canonic_text.lower(), ut.value)), UriReferent)
                 rt = ReferentToken(ad.registerReferent(ur), t, ut.end_token)
                 rt.begin_token = Utils.ifNotNull(UriAnalyzer.__siteBefore(t.previous), t)
                 if (rt.end_token.next0_ is not None and rt.end_token.next0_.isCharOf("/\\")): 
                     rt.end_token = rt.end_token.next0_
                 kit.embedToken(rt)
                 t = (rt)
                 continue
             if (i == 10): 
                 tt = tt.next0_
                 if (tt is None or not tt.isChar(':')): 
                     continue
                 tt = tt.next0_
                 while tt is not None: 
                     if (tt.isCharOf("/\\")): 
                         pass
                     else: 
                         break
                     tt = tt.next0_
                 if (tt is None): 
                     continue
                 if (tt.isValue("WWW", None) and tt.next0_ is not None and tt.next0_.isChar('.')): 
                     tt = tt.next0_.next0_
                 if (tt is None or tt.is_newline_before): 
                     continue
                 ut = UriItemToken.attachUriContent(tt, True)
                 if (ut is None): 
                     continue
                 if (len(ut.value) < 4): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2557(tok.termin.canonic_text.lower(), ut.value)), UriReferent)
                 rt = ReferentToken(ad.registerReferent(ur), t, ut.end_token)
                 rt.begin_token = Utils.ifNotNull(UriAnalyzer.__siteBefore(t.previous), t)
                 if (rt.end_token.next0_ is not None and rt.end_token.next0_.isCharOf("/\\")): 
                     rt.end_token = rt.end_token.next0_
                 kit.embedToken(rt)
                 t = (rt)
                 continue
             if (i == 2): 
                 if (tt.next0_ is None or not tt.next0_.isChar('.') or tt.next0_.is_whitespace_before): 
                     continue
                 if (tt.next0_.is_whitespace_after and tok.termin.canonic_text != "WWW"): 
                     continue
                 ut = UriItemToken.attachUriContent(tt.next0_.next0_, True)
                 if (ut is None): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2557("http", ut.value)), UriReferent)
                 rt = ReferentToken(ur, t, ut.end_token)
                 rt.begin_token = Utils.ifNotNull(UriAnalyzer.__siteBefore(t.previous), t)
                 if (rt.end_token.next0_ is not None and rt.end_token.next0_.isCharOf("/\\")): 
                     rt.end_token = rt.end_token.next0_
                 kit.embedToken(rt)
                 t = (rt)
                 continue
             if (i == 1): 
                 sch = tok.termin.canonic_text
                 ut = None
                 if (sch == "ISBN"): 
                     ut = UriItemToken.attachISBN(tt.next0_)
                     if ((ut is None and t.previous is not None and t.previous.isChar('(')) and t.next0_ is not None and t.next0_.isChar(')')): 
                         tt0 = t.previous.previous
                         while tt0 is not None: 
                             if (tt0.whitespaces_after_count > 2): 
                                 break
                             if (tt0.is_whitespace_before): 
                                 ut = UriItemToken.attachISBN(tt0)
                                 if (ut is not None and ut.end_token.next0_ != t.previous): 
                                     ut = (None)
                                 break
                             tt0 = tt0.previous
                 elif ((sch == "RFC" or sch == "ISO" or sch == "ОКФС") or sch == "ОКОПФ"): 
                     ut = UriItemToken.attachISOContent(tt.next0_, ":")
                 elif (sch == "ГОСТ"): 
                     ut = UriItemToken.attachISOContent(tt.next0_, "-.")
                 elif (sch == "ТУ"): 
                     if (tok.chars.is_all_upper): 
                         ut = UriItemToken.attachISOContent(tt.next0_, "-.")
                         if (ut is not None and (ut.length_char < 10)): 
                             ut = (None)
                 else: 
                     ut = UriItemToken.attachBBK(tt.next0_)
                 if (ut is None): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2560(ut.value, sch)), UriReferent)
                 if (ut.begin_char < t.begin_char): 
                     rt = ReferentToken(ur, ut.begin_token, t)
                     if (t.next0_ is not None and t.next0_.isChar(')')): 
                         rt.end_token = t.next0_
                 else: 
                     rt = ReferentToken(ur, t, ut.end_token)
                 if (t.previous is not None and t.previous.isValue("КОД", None)): 
                     rt.begin_token = t.previous
                 if (ur.scheme.startswith("ОК")): 
                     UriAnalyzer.__checkDetail(rt)
                 kit.embedToken(rt)
                 t = (rt)
                 if (ur.scheme.startswith("ОК")): 
                     while t.next0_ is not None:
                         if (t.next0_.is_comma_and and (isinstance(t.next0_.next0_, NumberToken))): 
                             pass
                         else: 
                             break
                         ut = UriItemToken.attachBBK(t.next0_.next0_)
                         if (ut is None): 
                             break
                         ur = (Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2560(ut.value, sch)), UriReferent))
                         rt = ReferentToken(ur, t.next0_.next0_, ut.end_token)
                         UriAnalyzer.__checkDetail(rt)
                         kit.embedToken(rt)
                         t = (rt)
                 continue
             if (i == 3): 
                 t0 = tt.next0_
                 while t0 is not None:
                     if (t0.isCharOf(":|") or t0.is_table_control_char or t0.is_hiphen): 
                         t0 = t0.next0_
                     else: 
                         break
                 if (t0 is None): 
                     continue
                 ut = UriItemToken.attachSkype(t0)
                 if (ut is None): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2560(ut.value.lower(), ("skype" if tok.termin.canonic_text == "SKYPE" else tok.termin.canonic_text))), UriReferent)
                 rt = ReferentToken(ur, t, ut.end_token)
                 kit.embedToken(rt)
                 t = (rt)
                 continue
             if (i == 4): 
                 t0 = tt.next0_
                 if (t0 is not None and ((t0.isChar(':') or t0.is_hiphen))): 
                     t0 = t0.next0_
                 if (t0 is None): 
                     continue
                 ut = UriItemToken.attachIcqContent(t0)
                 if (ut is None): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2560(ut.value, "ICQ")), UriReferent)
                 rt = ReferentToken(ur, t, t0)
                 kit.embedToken(rt)
                 t = (rt)
                 continue
             if (i == 5 or i == 6): 
                 t0 = tt.next0_
                 has_tab_cel = False
                 is_iban = False
                 first_pass3150 = True
                 while True:
                     if first_pass3150: first_pass3150 = False
                     else: t0 = t0.next0_
                     if (not (t0 is not None)): break
                     if ((((t0.isValue("БАНК", None) or t0.morph.class0_.is_preposition or t0.is_hiphen) or t0.isCharOf(".:") or t0.isValue("РУБЛЬ", None)) or t0.isValue("РУБ", None) or t0.isValue("ДОЛЛАР", None)) or t0.isValue("№", None) or t0.isValue("N", None)): 
                         pass
                     elif (t0.is_table_control_char): 
                         has_tab_cel = True
                     elif (t0.isCharOf("\\/") and t0.next0_ is not None and t0.next0_.isValue("IBAN", None)): 
                         is_iban = True
                         t0 = t0.next0_
                     elif (t0.isValue("IBAN", None)): 
                         is_iban = True
                     elif (isinstance(t0, TextToken)): 
                         npt = NounPhraseHelper.tryParse(t0, NounPhraseParseAttr.NO, 0)
                         if (npt is not None and npt.morph.case_.is_genitive): 
                             t0 = npt.end_token
                             continue
                         break
                     else: 
                         break
                 if (t0 is None): 
                     continue
                 ur2 = None
                 ur2begin = None
                 ur2end = None
                 t00 = t0
                 val = t0.getSourceText()
                 if (str.isdigit(val[0]) and ((((i == 6 or tok.termin.canonic_text == "ИНН" or tok.termin.canonic_text == "БИК") or tok.termin.canonic_text == "ОГРН" or tok.termin.canonic_text == "СНИЛС") or tok.termin.canonic_text == "ОКПО"))): 
                     if (t0.chars.is_letter): 
                         continue
                     if (Utils.isNullOrEmpty(val) or not str.isdigit(val[0])): 
                         continue
                     if (t0.length_char < 9): 
                         tmp = io.StringIO()
                         print(val, end="", file=tmp)
                         ttt = t0.next0_
                         first_pass3151 = True
                         while True:
                             if first_pass3151: first_pass3151 = False
                             else: ttt = ttt.next0_
                             if (not (ttt is not None)): break
                             if (ttt.whitespaces_before_count > 1): 
                                 break
                             if (isinstance(ttt, NumberToken)): 
                                 print(ttt.getSourceText(), end="", file=tmp)
                                 t0 = ttt
                                 continue
                             if (ttt.is_hiphen or ttt.isChar('.')): 
                                 if (ttt.next0_ is None or not ((isinstance(ttt.next0_, NumberToken)))): 
                                     break
                                 if (ttt.is_whitespace_after or ttt.is_whitespace_before): 
                                     break
                                 continue
                             break
                         val = (None)
                         if (tmp.tell() == 20): 
                             val = Utils.toStringStringIO(tmp)
                         elif (tmp.tell() == 9 and tok.termin.canonic_text == "БИК"): 
                             val = Utils.toStringStringIO(tmp)
                         elif (((tmp.tell() == 10 or tmp.tell() == 12)) and tok.termin.canonic_text == "ИНН"): 
                             val = Utils.toStringStringIO(tmp)
                         elif (tmp.tell() >= 15 and tok.termin.canonic_text == "Л/С"): 
                             val = Utils.toStringStringIO(tmp)
                         elif (tmp.tell() >= 11 and ((tok.termin.canonic_text == "ОГРН" or tok.termin.canonic_text == "СНИЛС"))): 
                             val = Utils.toStringStringIO(tmp)
                         elif (tok.termin.canonic_text == "ОКПО"): 
                             val = Utils.toStringStringIO(tmp)
                     if (val is None): 
                         continue
                 elif (not ((isinstance(t0, NumberToken)))): 
                     if ((isinstance(t0, TextToken)) and is_iban): 
                         tmp1 = io.StringIO()
                         t1 = None
                         ttt = t0
                         first_pass3152 = True
                         while True:
                             if first_pass3152: first_pass3152 = False
                             else: ttt = ttt.next0_
                             if (not (ttt is not None)): break
                             if (ttt.is_newline_before and ttt != t0): 
                                 break
                             if (ttt.is_hiphen): 
                                 continue
                             if (not ((isinstance(ttt, NumberToken)))): 
                                 if (not ((isinstance(ttt, TextToken))) or not ttt.chars.is_latin_letter): 
                                     break
                             print(ttt.getSourceText(), end="", file=tmp1)
                             t1 = ttt
                             if (tmp1.tell() >= 34): 
                                 break
                         if (tmp1.tell() < 10): 
                             continue
                         ur1 = UriReferent._new2560(Utils.toStringStringIO(tmp1), tok.termin.canonic_text)
                         ur1.addSlot(UriReferent.ATTR_DETAIL, "IBAN", False, 0)
                         rt1 = ReferentToken(ad.registerReferent(ur1), t, t1)
                         kit.embedToken(rt1)
                         t = (rt1)
                         continue
                     if (not t0.isCharOf("/\\") or t0.next0_ is None): 
                         continue
                     tok2 = UriAnalyzer.__m_schemes.tryParse(t0.next0_, TerminParseAttr.NO)
                     if (tok2 is None or not ((isinstance(tok2.termin.tag, int))) or (tok2.termin.tag) != i): 
                         continue
                     t0 = tok2.end_token.next0_
                     while t0 is not None:
                         if (t0.isCharOf(":N№")): 
                             t0 = t0.next0_
                         elif (t0.is_table_control_char): 
                             t0 = t0.next0_
                             t00 = t0
                             has_tab_cel = True
                         else: 
                             break
                     if (not ((isinstance(t0, NumberToken)))): 
                         continue
                     tmp = io.StringIO()
                     while t0 is not None: 
                         if (not ((isinstance(t0, NumberToken)))): 
                             break
                         print(t0.getSourceText(), end="", file=tmp)
                         t0 = t0.next0_
                     if (t0 is None or not t0.isCharOf("/\\,") or not ((isinstance(t0.next0_, NumberToken)))): 
                         continue
                     val = Utils.toStringStringIO(tmp)
                     Utils.setLengthStringIO(tmp, 0)
                     ur2begin = t0.next0_
                     t0 = t0.next0_
                     while t0 is not None: 
                         if (not ((isinstance(t0, NumberToken)))): 
                             break
                         if (t0.whitespaces_before_count > 4 and tmp.tell() > 0): 
                             break
                         print(t0.getSourceText(), end="", file=tmp)
                         ur2end = t0
                         t0 = t0.next0_
                     ur2 = (Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2557(tok2.termin.canonic_text, Utils.toStringStringIO(tmp))), UriReferent))
                 if (len(val) < 5): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2560(val, tok.termin.canonic_text)), UriReferent)
                 rt = ReferentToken(ur, t, (t0 if ur2begin is None else ur2begin.previous))
                 if (has_tab_cel): 
                     rt.begin_token = t00
                 if (ur.scheme.startswith("ОК")): 
                     UriAnalyzer.__checkDetail(rt)
                 ttt = t.previous
                 first_pass3153 = True
                 while True:
                     if first_pass3153: first_pass3153 = False
                     else: ttt = ttt.previous
                     if (not (ttt is not None)): break
                     if (ttt.is_table_control_char): 
                         break
                     if (ttt.morph.class0_.is_preposition): 
                         continue
                     if (ttt.isValue("ОРГАНИЗАЦИЯ", None)): 
                         continue
                     if (ttt.isValue("НОМЕР", None) or ttt.isValue("КОД", None)): 
                         rt.begin_token = ttt
                         t = rt.begin_token
                     break
                 kit.embedToken(rt)
                 t = (rt)
                 if (ur2 is not None): 
                     rt2 = ReferentToken(ur2, ur2begin, ur2end)
                     kit.embedToken(rt2)
                     t = (rt2)
                 continue
             continue
         if (t.isChar('@')): 
             u1s = UriItemToken.attachMailUsers(t.previous)
             if (u1s is None): 
                 continue
             u2 = UriItemToken.attachDomainName(t.next0_, False, True)
             if (u2 is None): 
                 continue
             for ii in range(len(u1s) - 1, -1, -1):
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2560("{0}@{1}".format(u1s[ii].value, u2.value).lower(), "mailto")), UriReferent)
                 b = u1s[ii].begin_token
                 t0 = b.previous
                 if (t0 is not None and t0.isChar(':')): 
                     t0 = t0.previous
                 if (t0 is not None and ii == 0): 
                     br = False
                     ttt = t0
                     first_pass3154 = True
                     while True:
                         if first_pass3154: first_pass3154 = False
                         else: ttt = ttt.previous
                         if (not (ttt is not None)): break
                         if (not ((isinstance(ttt, TextToken)))): 
                             break
                         if (ttt != t0 and ttt.whitespaces_after_count > 1): 
                             break
                         if (ttt.isChar(')')): 
                             br = True
                             continue
                         if (ttt.isChar('(')): 
                             if (not br): 
                                 break
                             br = False
                             continue
                         if (ttt.isValue("EMAIL", None) or ttt.isValue("MAILTO", None)): 
                             b = ttt
                             break
                         if (ttt.isValue("MAIL", None)): 
                             b = ttt
                             if ((ttt.previous is not None and ttt.previous.is_hiphen and ttt.previous.previous is not None) and ((ttt.previous.previous.isValue("E", None) or ttt.previous.previous.isValue("Е", None)))): 
                                 b = ttt.previous.previous
                             break
                         if (ttt.isValue("ПОЧТА", None) or ttt.isValue("АДРЕС", None)): 
                             b = t0
                             ttt = ttt.previous
                             if (ttt is not None and ttt.isChar('.')): 
                                 ttt = ttt.previous
                             if (ttt is not None and ((t0.isValue("ЭЛ", None) or ttt.isValue("ЭЛЕКТРОННЫЙ", None)))): 
                                 b = ttt
                             if (b.previous is not None and b.previous.isValue("АДРЕС", None)): 
                                 b = b.previous
                             break
                         if (ttt.morph.class0_.is_preposition): 
                             continue
                 rt = ReferentToken(ur, b, (u2.end_token if ii == (len(u1s) - 1) else u1s[ii].end_token))
                 kit.embedToken(rt)
                 t = (rt)
             continue
         if (not t.morph.language.is_cyrillic): 
             if (t.is_whitespace_before or ((t.previous is not None and t.previous.isCharOf(",(")))): 
                 u1 = UriItemToken.attachUrl(t)
                 if (u1 is not None): 
                     if (u1.is_whitespace_after or u1.end_token.next0_ is None or not u1.end_token.next0_.isChar('@')): 
                         ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2557("http", u1.value)), UriReferent)
                         rt = ReferentToken(ur, u1.begin_token, u1.end_token)
                         rt.begin_token = Utils.ifNotNull(UriAnalyzer.__siteBefore(u1.begin_token.previous), u1.begin_token)
                         kit.embedToken(rt)
                         t = (rt)
                         continue
         if ((isinstance(t, TextToken)) and not t.is_whitespace_after and t.length_char > 2): 
             if (UriAnalyzer.__siteBefore(t.previous) is not None): 
                 ut = UriItemToken.attachUriContent(t, True)
                 if (ut is None or ut.value.find('.') <= 0 or ut.value.find('@') > 0): 
                     continue
                 ur = Utils.asObjectOrNull(ad.registerReferent(UriReferent._new2557("http", ut.value)), UriReferent)
                 rt = ReferentToken(ur, t, ut.end_token)
                 rt.begin_token = UriAnalyzer.__siteBefore(t.previous)
                 if (rt.end_token.next0_ is not None and rt.end_token.next0_.isCharOf("/\\")): 
                     rt.end_token = rt.end_token.next0_
                 kit.embedToken(rt)
                 t = (rt)
                 continue
         if ((t.chars.is_latin_letter and not t.chars.is_all_lower and t.next0_ is not None) and not t.is_whitespace_after): 
             if (t.next0_.isChar('/')): 
                 rt = UriAnalyzer.__TryAttachLotus(Utils.asObjectOrNull(t, TextToken))
                 if (rt is not None): 
                     rt.referent = ad.registerReferent(rt.referent)
                     kit.embedToken(rt)
                     t = (rt)
                     continue
Example #4
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
Example #5
0
 def attach_first(self, p : 'InstrumentParticipantReferent', min_char : int, max_char : int) -> 'ReferentToken':
     t = None
     tt0 = self.begin_token
     refs = list()
     t = tt0.previous
     first_pass3287 = True
     while True:
         if first_pass3287: first_pass3287 = False
         else: t = t.previous
         if (not (t is not None and t.begin_char >= min_char)): break
         if (t.is_newline_after): 
             if (t.newlines_after_count > 1): 
                 break
             if (isinstance(t.next0_, NumberToken)): 
                 break
         tt = ParticipantToken.__try_attach_contract_ground(t, p, False)
         if (tt is not None): 
             continue
         r = t.get_referent()
         if (((((isinstance(r, OrganizationReferent)) or (isinstance(r, PhoneReferent)) or (isinstance(r, PersonReferent))) or (isinstance(r, PersonPropertyReferent)) or (isinstance(r, AddressReferent))) or (isinstance(r, UriReferent)) or (isinstance(r, PersonIdentityReferent))) or (isinstance(r, BankDataReferent))): 
             if (not r in refs): 
                 refs.insert(0, r)
             tt0 = t
     if (len(refs) > 0): 
         for r in refs: 
             if (r != refs[0] and (isinstance(refs[0], OrganizationReferent)) and (((isinstance(r, PersonReferent)) or (isinstance(r, PersonPropertyReferent))))): 
                 p.add_slot(InstrumentParticipantReferent.ATTR_DELEGATE, r, False, 0)
             else: 
                 p.add_slot(InstrumentParticipantReferent.ATTR_REF, r, False, 0)
     rt = ReferentToken(p, tt0, self.end_token)
     t = self.end_token.next0_
     if (BracketHelper.is_bracket(t, False)): 
         t = t.next0_
     if (t is not None and t.is_char(',')): 
         t = t.next0_
     first_pass3288 = True
     while True:
         if first_pass3288: first_pass3288 = False
         else: t = t.next0_
         if (not (t is not None and ((max_char == 0 or t.begin_char <= max_char)))): break
         if (t.is_value("СТОРОНА", None)): 
             break
         r = t.get_referent()
         if (((((isinstance(r, OrganizationReferent)) or (isinstance(r, PhoneReferent)) or (isinstance(r, PersonReferent))) or (isinstance(r, PersonPropertyReferent)) or (isinstance(r, AddressReferent))) or (isinstance(r, UriReferent)) or (isinstance(r, PersonIdentityReferent))) or (isinstance(r, BankDataReferent))): 
             if ((((isinstance(r, PersonPropertyReferent)) and t.next0_ is not None and t.next0_.is_comma) and (isinstance(t.next0_.next0_, ReferentToken)) and (isinstance(t.next0_.next0_.get_referent(), PersonReferent))) and not t.next0_.is_newline_after): 
                 pe = Utils.asObjectOrNull(t.next0_.next0_.get_referent(), PersonReferent)
                 pe.add_slot(PersonReferent.ATTR_ATTR, r, False, 0)
                 r = (pe)
                 t = t.next0_.next0_
             is_delegate = False
             if (t.previous.is_value("ЛИЦО", None) or t.previous.is_value("ИМЯ", None)): 
                 is_delegate = True
             if (t.previous.is_value("КОТОРЫЙ", None) and t.previous.previous is not None and ((t.previous.previous.is_value("ИМЯ", None) or t.previous.previous.is_value("ЛИЦО", None)))): 
                 is_delegate = True
             p.add_slot((InstrumentParticipantReferent.ATTR_DELEGATE if (((isinstance(r, PersonReferent)) or (isinstance(r, PersonPropertyReferent)))) and is_delegate else InstrumentParticipantReferent.ATTR_REF), r, False, 0)
             rt.end_token = t
             continue
         tt = ParticipantToken.__try_attach_contract_ground(t, p, False)
         if (tt is not None): 
             rt.end_token = tt
             t = rt.end_token
             if (rt.begin_char == tt.begin_char): 
                 rt.begin_token = tt
             continue
         if (t.is_value("В", None) and t.next0_ is not None and t.next0_.is_value("ЛИЦО", None)): 
             t = t.next0_
             continue
         if (t.is_value("ОТ", None) and t.next0_ is not None and t.next0_.is_value("ИМЯ", None)): 
             t = t.next0_
             continue
         if (t.is_value("ПО", None) and t.next0_ is not None and t.next0_.is_value("ПОРУЧЕНИЕ", None)): 
             t = t.next0_
             continue
         if (t.is_newline_before): 
             break
         if (t.get_morph_class_in_dictionary() == MorphClass.VERB): 
             if ((not t.is_value("УДОСТОВЕРЯТЬ", None) and not t.is_value("ПРОЖИВАТЬ", None) and not t.is_value("ЗАРЕГИСТРИРОВАТЬ", None)) and not t.is_value("ДЕЙСТВОВАТЬ", None)): 
                 break
         if (t.is_and and t.previous is not None and t.previous.is_comma): 
             break
         if (t.is_and and t.next0_.get_referent() is not None): 
             if (isinstance(t.next0_.get_referent(), OrganizationReferent)): 
                 break
             pe = Utils.asObjectOrNull(t.next0_.get_referent(), PersonReferent)
             if (pe is not None): 
                 has_ip = False
                 for s in pe.slots: 
                     if (s.type_name == PersonReferent.ATTR_ATTR): 
                         if (str(s.value).startswith("индивидуальный предприниматель")): 
                             has_ip = True
                             break
                 if (has_ip): 
                     break
     t = rt.begin_token
     while t is not None and t.end_char <= rt.end_char: 
         tt = ParticipantToken.__try_attach_contract_ground(t, p, True)
         if (tt is not None): 
             if (tt.end_char > rt.end_char): 
                 rt.end_token = tt
             t = tt
         t = t.next0_
     return rt
Example #6
0
 def __try1(li: typing.List['CityItemToken'], oi: 'IntOntologyItem',
            ad: 'AnalyzerDataWithOntology') -> 'ReferentToken':
     oi.value = (None)
     if (li is None or (len(li) < 1)):
         return None
     elif (li[0].typ != CityItemToken.ItemType.CITY):
         if (len(li) != 2 or li[0].typ != CityItemToken.ItemType.PROPERNAME
                 or li[1].typ != CityItemToken.ItemType.NOUN):
             return None
     i = 1
     oi.value = li[0].onto_item
     ok = not li[0].doubtful
     if ((ok and li[0].onto_item is not None
          and li[0].onto_item.misc_attr is None) and ad is not None):
         if (li[0].onto_item.owner != ad.local_ontology
                 and not li[0].onto_item.owner.is_ext_ontology):
             if (li[0].begin_token.previous is not None
                     and li[0].begin_token.previous.isValue("В", None)):
                 pass
             else:
                 ok = False
     if (len(li) == 1 and li[0].begin_token.morph.class0_.is_adjective):
         sits = StreetItemToken.tryParseList(li[0].begin_token, None, 3)
         if (sits is not None and len(sits) == 2
                 and sits[1].typ == StreetItemType.NOUN):
             return None
     typ = None
     alttyp = None
     mc = li[0].morph
     if (i < len(li)):
         if (li[i].typ == CityItemToken.ItemType.NOUN):
             at = None
             if (not li[i].chars.is_all_lower
                     and (li[i].whitespaces_after_count < 2)):
                 sit = StreetItemToken.tryParse(li[i].end_token.next0_,
                                                None, False, None, False)
                 if (sit is not None and sit.typ == StreetItemType.NOUN):
                     at = AddressItemToken.tryParse(li[i].begin_token, None,
                                                    False, False, None)
                     if (at is not None):
                         at2 = AddressItemToken.tryParse(
                             li[i].end_token.next0_, None, False, False,
                             None)
                         if (at2 is not None and at2.typ
                                 == AddressItemToken.ItemType.STREET):
                             at = (None)
             if (at is None):
                 typ = li[i].value
                 alttyp = li[i].alt_value
                 if (li[i].begin_token.isValue("СТ", None)
                         and li[i].begin_token.chars.is_all_upper):
                     return None
                 if ((i + 1) == len(li)):
                     ok = True
                     if (not li[i].morph.case_.is_undefined):
                         mc = li[i].morph
                     i += 1
                 elif (ok):
                     i += 1
                 else:
                     tt0 = li[0].begin_token.previous
                     if ((isinstance(tt0, TextToken))
                             and (tt0.whitespaces_after_count < 3)):
                         if (tt0.isValue("МЭР", "МЕР")
                                 or tt0.isValue("ГЛАВА", None)
                                 or tt0.isValue("ГРАДОНАЧАЛЬНИК", None)):
                             ok = True
                             i += 1
     if (not ok and oi.value is not None
             and (len(oi.value.canonic_text) < 4)):
         return None
     if (not ok and li[0].begin_token.morph.class0_.is_proper_name):
         return None
     if (not ok):
         if (not MiscHelper.isExistsInDictionary(
                 li[0].begin_token, li[0].end_token, (MorphClass.ADJECTIVE)
                 | MorphClass.NOUN | MorphClass.PRONOUN)):
             ok = (li[0].geo_object_before or li[i - 1].geo_object_after)
             if (ok and li[0].begin_token == li[0].end_token):
                 mcc = li[0].begin_token.getMorphClassInDictionary()
                 if (mcc.is_proper_name or mcc.is_proper_surname):
                     ok = False
                 elif (li[0].geo_object_before
                       and (li[0].whitespaces_after_count < 2)):
                     ad1 = AddressItemToken.tryParse(
                         li[0].begin_token, None, False, False, None)
                     if (ad1 is not None and ad1.typ
                             == AddressItemToken.ItemType.STREET):
                         ad2 = AddressItemToken.tryParse(
                             li[0].end_token.next0_, None, False, False,
                             None)
                         if (ad2 is None or ad2.typ !=
                                 AddressItemToken.ItemType.STREET):
                             ok = False
                     elif (AddressItemToken.tryAttachOrg(li[0].begin_token)
                           is not None):
                         ok = False
         if (ok):
             if (li[0].kit.processReferent("PERSON", li[0].begin_token)
                     is not None):
                 ok = False
     if (not ok):
         ok = CityAttachHelper.checkYearAfter(li[0].end_token.next0_)
     if (not ok and ((not li[0].begin_token.morph.class0_.is_adjective
                      or li[0].begin_token != li[0].end_token))):
         ok = CityAttachHelper.checkCityAfter(li[0].end_token.next0_)
     if (not ok):
         return None
     if (i < len(li)):
         del li[i:i + len(li) - i]
     rt = None
     if (oi.value is None):
         if (li[0].value is not None and li[0].higher_geo is not None):
             cap = GeoReferent()
             cap._addName(li[0].value)
             cap._addTypCity(li[0].kit.base_language)
             cap.higher = li[0].higher_geo
             if (typ is not None):
                 cap._addTyp(typ)
             if (alttyp is not None):
                 cap._addTyp(alttyp)
             rt = ReferentToken(cap, li[0].begin_token, li[0].end_token)
         else:
             if (li[0].value is None):
                 return None
             if (typ is None):
                 if ((len(li) == 1
                      and li[0].begin_token.previous is not None
                      and li[0].begin_token.previous.is_hiphen) and
                     (isinstance(li[0].begin_token.previous.previous,
                                 ReferentToken)) and
                     (isinstance(
                         li[0].begin_token.previous.previous.getReferent(),
                         GeoReferent))):
                     pass
                 else:
                     return None
             else:
                 if (not LanguageHelper.endsWithEx(typ, "ПУНКТ",
                                                   "ПОСЕЛЕНИЕ", "ПОСЕЛЕННЯ",
                                                   "ПОСЕЛОК")):
                     if (not LanguageHelper.endsWith(typ, "CITY")):
                         if (typ == "СТАНЦИЯ" and
                             ((MiscLocationHelper.checkGeoObjectBefore(
                                 li[0].begin_token)))):
                             pass
                         elif (len(li) > 1
                               and li[1].typ == CityItemToken.ItemType.NOUN
                               and li[0].typ
                               == CityItemToken.ItemType.CITY):
                             pass
                         else:
                             return None
                 if (li[0].begin_token.morph.class0_.is_adjective):
                     li[0].value = ProperNameHelper.getNameEx(
                         li[0].begin_token, li[0].end_token,
                         MorphClass.ADJECTIVE, li[1].morph.case_,
                         li[1].morph.gender, False, False)
     elif (isinstance(oi.value.referent, GeoReferent)):
         rt = ReferentToken._new719(
             Utils.asObjectOrNull(oi.value.referent, GeoReferent),
             li[0].begin_token, li[len(li) - 1].end_token, mc)
     elif (typ is None):
         typ = oi.value.typ
     if (rt is None):
         city = GeoReferent()
         city._addName(
             (li[0].value if oi.value is None else oi.value.canonic_text))
         if (typ is not None):
             city._addTyp(typ)
         else:
             city._addTypCity(li[0].kit.base_language)
         if (alttyp is not None):
             city._addTyp(alttyp)
         rt = ReferentToken._new719(city, li[0].begin_token,
                                    li[len(li) - 1].end_token, mc)
     if ((isinstance(rt.referent, GeoReferent)) and len(li) == 1
             and (rt.referent).is_city):
         if (rt.begin_token.previous is not None
                 and rt.begin_token.previous.isValue("Г", None)):
             rt.begin_token = rt.begin_token.previous
         elif ((rt.begin_token.previous is not None
                and rt.begin_token.previous.isChar('.')
                and rt.begin_token.previous.previous is not None)
               and rt.begin_token.previous.previous.isValue("Г", None)):
             rt.begin_token = rt.begin_token.previous.previous
         elif (rt.end_token.next0_ is not None
               and (rt.whitespaces_after_count < 2)
               and rt.end_token.next0_.isValue("Г", None)):
             rt.end_token = rt.end_token.next0_
             if (rt.end_token.next0_ is not None
                     and rt.end_token.next0_.isChar('.')):
                 rt.end_token = rt.end_token.next0_
     return rt