def __getNextPhone(self, t: 'Token', lev: int) -> 'PhoneReferent': if (t is not None and t.isChar(',')): t = t.next0_ if (t is None or lev > 3): return None its = PhoneItemToken.tryAttachAll(t) if (its is None): return None rt = self.__TryAttach_(its, 0, False, None, lev + 1) if (rt is None): return None return Utils.asObjectOrNull(rt.referent, PhoneReferent)
def _processReferent(self, begin: 'Token', end: 'Token') -> 'ReferentToken': pli = PhoneItemToken.tryAttachAll(begin) if (pli is None or len(pli) == 0): return None i = 0 while i < len(pli): if (pli[i].item_type != PhoneItemToken.PhoneItemType.PREFIX): break i += 1 rt = self.__TryAttach_(pli, i, True, None, 0) if (rt is not None): rt.begin_token = begin return rt return None
def process(self, kit: 'AnalysisKit') -> None: """ Основная функция выделения телефонов Args: cnt: stage: """ ad = Utils.asObjectOrNull(kit.getAnalyzerData(self), PhoneAnalyzer.PhoneAnalizerData) t = kit.first_token first_pass3118 = True while True: if first_pass3118: first_pass3118 = False else: t = t.next0_ if (not (t is not None)): break pli = PhoneItemToken.tryAttachAll(t) if (pli is None or len(pli) == 0): continue prev_phone = None tt = t.previous while tt is not None: if (isinstance(tt.getReferent(), PhoneReferent)): prev_phone = (Utils.asObjectOrNull(tt.getReferent(), PhoneReferent)) break elif (tt.isChar(')')): ttt = tt.previous cou = 0 while ttt is not None: if (ttt.isChar('(')): break else: cou += 1 if ((cou) > 100): break ttt = ttt.previous if (ttt is None or not ttt.isChar('(')): break tt = ttt elif (not tt.isCharOf(",;/\\") and not tt.is_and): break tt = tt.previous j = 0 is_phone_before = False is_pref = False ki = PhoneKind.UNDEFINED while j < len(pli): if (pli[j].item_type == PhoneItemToken.PhoneItemType.PREFIX): if (ki == PhoneKind.UNDEFINED): ki = pli[j].kind is_pref = True is_phone_before = True j += 1 elif (((j + 1) < len(pli)) and pli[j + 1].item_type == PhoneItemToken.PhoneItemType.PREFIX and j == 0): if (ki == PhoneKind.UNDEFINED): ki = pli[0].kind is_pref = True del pli[0] else: break if (prev_phone is not None): is_phone_before = True rts = self.__tryAttach(pli, j, is_phone_before, prev_phone) if (rts is None): j = 1 while j < len(pli): if (pli[j].item_type == PhoneItemToken.PhoneItemType.PREFIX ): del pli[0:0 + j] rts = self.__tryAttach(pli, 1, True, prev_phone) break j += 1 if (rts is None): t = pli[len(pli) - 1].end_token else: if ((ki == PhoneKind.UNDEFINED and prev_phone is not None and not is_pref) and prev_phone.kind != PhoneKind.MOBILE): ki = prev_phone.kind for rt in rts: ph = Utils.asObjectOrNull(rt.referent, PhoneReferent) if (ki != PhoneKind.UNDEFINED): ph.kind = ki else: if (rt == rts[0] and (rt.whitespaces_before_count < 3)): tt1 = rt.begin_token.previous if (tt1 is not None and tt1.is_table_control_char): tt1 = tt1.previous if ((isinstance(tt1, TextToken)) and ((tt1.is_newline_before or ((tt1.previous is not None and tt1.previous.is_table_control_char))))): term = (tt1).term if (term == "T" or term == "Т"): rt.begin_token = tt1 elif (term == "Ф" or term == "F"): ki = PhoneKind.FAX ph.kind = ki rt.begin_token = tt1 elif (term == "M" or term == "М"): ki = PhoneKind.MOBILE ph.kind = ki rt.begin_token = tt1 ph._correct() rt.referent = ad.registerReferent(rt.referent) kit.embedToken(rt) t = (rt)