示例#1
0
 def __get_next_phone(self, t : 'Token', lev : int) -> 'PhoneReferent':
     if (t is not None and t.is_char(',')): 
         t = t.next0_
     if (t is None or lev > 3): 
         return None
     its = PhoneItemToken.try_attach_all(t, 15)
     if (its is None): 
         return None
     rt = self.__try_attach_(its, 0, False, None, lev + 1)
     if (rt is None): 
         return None
     return Utils.asObjectOrNull(rt.referent, PhoneReferent)
示例#2
0
 def process_referent(self, begin : 'Token', end : 'Token') -> 'ReferentToken':
     pli = PhoneItemToken.try_attach_all(begin, 15)
     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.__try_attach_(pli, i, True, None, 0)
     if (rt is not None): 
         rt.begin_token = begin
         return rt
     return None
示例#3
0
 def process(self, kit : 'AnalysisKit') -> None:
     ad = Utils.asObjectOrNull(kit.get_analyzer_data(self), PhoneAnalyzer.PhoneAnalizerData)
     t = kit.first_token
     first_pass3390 = True
     while True:
         if first_pass3390: first_pass3390 = False
         else: t = t.next0_
         if (not (t is not None)): break
         pli = PhoneItemToken.try_attach_all(t, 15)
         if (pli is None or len(pli) == 0): 
             continue
         prev_phone = None
         kkk = 0
         tt = t.previous
         while tt is not None: 
             if (isinstance(tt.get_referent(), PhoneReferent)): 
                 prev_phone = (Utils.asObjectOrNull(tt.get_referent(), PhoneReferent))
                 break
             elif (isinstance(tt, ReferentToken)): 
                 pass
             elif (tt.is_char(')')): 
                 ttt = tt.previous
                 cou = 0
                 while ttt is not None: 
                     if (ttt.is_char('(')): 
                         break
                     else: 
                         cou += 1
                         if (cou > 100): 
                             break
                     ttt = ttt.previous
                 if (ttt is None or not ttt.is_char('(')): 
                     break
                 tt = ttt
             elif (not tt.is_char_of(",;/\\") and not tt.is_and): 
                 kkk += 1
                 if (kkk > 5): 
                     break
                 if (tt.is_newline_before or tt.is_newline_after): 
                     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
                 if ((j < len(pli)) and pli[j].item_type == PhoneItemToken.PhoneItemType.DELIM): 
                     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
         if (len(pli) == 1 and pli[0].item_type == PhoneItemToken.PhoneItemType.NUMBER): 
             tt = t.previous
             if ((isinstance(tt, TextToken)) and not tt.chars.is_letter): 
                 tt = tt.previous
             if (isinstance(tt, TextToken)): 
                 if (UriAnalyzer._m_schemes.try_parse(tt, TerminParseAttr.NO) is not None): 
                     continue
         rts = self.__try_attach(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.__try_attach(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 and kkk == 0): 
                 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.register_referent(rt.referent)
                 kit.embed_token(rt)
                 t = (rt)