def process(self, kit : 'AnalysisKit') -> None:
     # Основная функция выделения объектов
     ad = Utils.asObjectOrNull(kit.get_analyzer_data(self), AnalyzerDataWithOntology)
     for k in range(2):
         detect_new_denoms = False
         dt = datetime.datetime.now()
         t = kit.first_token
         first_pass3147 = True
         while True:
             if first_pass3147: first_pass3147 = False
             else: t = t.next0_
             if (not (t is not None)): break
             if (t.is_whitespace_before): 
                 pass
             elif (t.previous is not None and ((t.previous.is_char_of(",") or BracketHelper.can_be_start_of_sequence(t.previous, False, False)))): 
                 pass
             else: 
                 continue
             rt0 = self.__try_attach_spec(t)
             if (rt0 is not None): 
                 rt0.referent = ad.register_referent(rt0.referent)
                 kit.embed_token(rt0)
                 t = (rt0)
                 continue
             if (not t.chars.is_letter): 
                 continue
             if (not self.__can_be_start_of_denom(t)): 
                 continue
             ot = None
             ot = ad.local_ontology.try_attach(t, None, False)
             if (ot is not None and (isinstance(ot[0].item.referent, DenominationReferent))): 
                 if (self.__check_attach(ot[0].begin_token, ot[0].end_token)): 
                     cl = Utils.asObjectOrNull(ot[0].item.referent.clone(), DenominationReferent)
                     cl.occurrence.clear()
                     rt = ReferentToken(cl, ot[0].begin_token, ot[0].end_token)
                     kit.embed_token(rt)
                     t = (rt)
                     continue
             if (k > 0): 
                 continue
             if (t is not None and t.kit.ontology is not None): 
                 ot = t.kit.ontology.attach_token(DenominationReferent.OBJ_TYPENAME, t)
                 if ((ot) is not None): 
                     if (self.__check_attach(ot[0].begin_token, ot[0].end_token)): 
                         dr = DenominationReferent()
                         dr.merge_slots(ot[0].item.referent, True)
                         rt = ReferentToken(ad.register_referent(dr), ot[0].begin_token, ot[0].end_token)
                         kit.embed_token(rt)
                         t = (rt)
                         continue
             rt0 = self.try_attach(t, False)
             if (rt0 is not None): 
                 rt0.referent = ad.register_referent(rt0.referent)
                 kit.embed_token(rt0)
                 detect_new_denoms = True
                 t = (rt0)
                 if (len(ad.local_ontology.items) > 1000): 
                     break
         if (not detect_new_denoms): 
             break
Esempio n. 2
0
 def __tryAttachSpec(self, t: 'Token') -> 'ReferentToken':
     """ Некоторые специфические случаи
     
     Args:
         t(Token): 
     
     """
     if (t is None):
         return None
     t0 = t
     nt = Utils.asObjectOrNull(t, NumberToken)
     if (nt is not None and nt.typ == NumberSpellingType.DIGIT
             and nt.value == "1"):
         if (t.next0_ is not None and t.next0_.is_hiphen):
             t = t.next0_
         if ((isinstance(t.next0_, TextToken))
                 and not t.next0_.is_whitespace_before):
             if (t.next0_.isValue("C", None)
                     or t.next0_.isValue("С", None)):
                 dr = DenominationReferent()
                 dr.addSlot(DenominationReferent.ATTR_VALUE, "1С", False, 0)
                 dr.addSlot(DenominationReferent.ATTR_VALUE, "1C", False, 0)
                 return ReferentToken(dr, t0, t.next0_)
     if (((nt is not None and nt.typ == NumberSpellingType.DIGIT and
           (isinstance(t.next0_, TextToken))) and not t.is_whitespace_after
          and not t.next0_.chars.is_all_lower)
             and t.next0_.chars.is_letter):
         dr = DenominationReferent()
         dr.addSlot(DenominationReferent.ATTR_VALUE,
                    "{0}{1}".format(nt.getSourceText(),
                                    (t.next0_).term), False, 0)
         return ReferentToken(dr, t0, t.next0_)
     return None
Esempio n. 3
0
 def createRefenetsTokensWithRegister(
         self,
         ad: 'AnalyzerData',
         name: str,
         regist: bool = True) -> typing.List['ReferentToken']:
     res = list()
     for u in self.units:
         rt = ReferentToken(u.createReferentWithRegister(ad), u.begin_token,
                            u.end_token)
         res.append(rt)
     mr = MeasureReferent()
     templ = "1"
     if (self.single_val is not None):
         mr.addValue(self.single_val)
         if (self.plus_minus is not None):
             templ = "[1 ±2{0}]".format(
                 ("%" if self.plus_minus_percent else ""))
             mr.addValue(self.plus_minus)
         elif (self.about):
             templ = "~1"
     else:
         if (self.not0_
                 and ((self.from_val is None or self.to_val is None))):
             b = self.from_include
             self.from_include = self.to_include
             self.to_include = b
             v = self.from_val
             self.from_val = self.to_val
             self.to_val = v
         num = 1
         if (self.from_val is not None):
             mr.addValue(self.from_val)
             templ = ("[1" if self.from_include else "]1")
             num += 1
         else:
             templ = "]"
         if (self.to_val is not None):
             mr.addValue(self.to_val)
             templ = "{0} .. {1}{2}".format(
                 templ, num, (']' if self.to_include else '['))
         else:
             templ += " .. ["
     mr.template = templ
     for rt in res:
         mr.addSlot(MeasureReferent.ATTR_UNIT, rt.referent, False, 0)
     if (name is not None):
         mr.addSlot(MeasureReferent.ATTR_NAME, name, False, 0)
     if (self.div_num is not None):
         dn = self.div_num.createRefenetsTokensWithRegister(ad, None, True)
         res.extend(dn)
         mr.addSlot(MeasureReferent.ATTR_REF, dn[len(dn) - 1].referent,
                    False, 0)
     ki = UnitToken.calcKind(self.units)
     if (ki != MeasureKind.UNDEFINED):
         mr.kind = ki
     if (regist and ad is not None):
         mr = (Utils.asObjectOrNull(ad.registerReferent(mr),
                                    MeasureReferent))
     res.append(ReferentToken(mr, self.begin_token, self.end_token))
     return res
Esempio n. 4
0
 def process_ontology_item(self, begin: 'Token') -> 'ReferentToken':
     if (not (isinstance(begin, TextToken))):
         return None
     ut = UnitToken.try_parse(begin, None, None, False)
     if (ut is not None):
         return ReferentToken(ut.create_referent_with_register(None),
                              ut.begin_token, ut.end_token)
     u = UnitReferent()
     u.add_slot(UnitReferent.ATTR_NAME, begin.get_source_text(), False, 0)
     return ReferentToken(u, begin, begin)
Esempio n. 5
0
 def processOntologyItem(self, begin: 'Token') -> 'ReferentToken':
     if (not ((isinstance(begin, TextToken)))):
         return None
     ut = UnitToken.tryParse(begin, None, None, False)
     if (ut is not None):
         return ReferentToken(ut.createReferentWithRegister(None),
                              ut.begin_token, ut.end_token)
     u = UnitReferent()
     u.addSlot(UnitReferent.ATTR_NAME, begin.getSourceText(), False, 0)
     return ReferentToken(u, begin, begin)
Esempio n. 6
0
 def __try_parse_short_inline(t: 'Token') -> 'ReferentToken':
     if (t is None):
         return None
     re = None
     if (t.is_char('[') and not t.is_newline_before):
         bb = BookLinkToken.try_parse(t, 0)
         if (bb is not None and bb.typ == BookLinkTyp.NUMBER):
             re = BookLinkRefReferent()
             re.number = bb.value
             return ReferentToken(re, t, bb.end_token)
     if (t.is_char('(')):
         bbb = BookLinkToken.try_parse(t.next0_, 0)
         if (bbb is None):
             return None
         if (bbb.typ == BookLinkTyp.SEE):
             tt = bbb.end_token.next0_
             first_pass3024 = True
             while True:
                 if first_pass3024: first_pass3024 = False
                 else: tt = tt.next0_
                 if (not (tt is not None)): break
                 if (tt.is_char_of(",:.")):
                     continue
                 if (tt.is_char('[')):
                     if (((isinstance(tt.next0_, NumberToken))
                          and tt.next0_.next0_ is not None
                          and tt.next0_.next0_.is_char(']'))
                             and tt.next0_.next0_ is not None
                             and tt.next0_.next0_.next0_.is_char(')')):
                         re = BookLinkRefReferent()
                         re.number = str(tt.next0_.value)
                         return ReferentToken(re, t,
                                              tt.next0_.next0_.next0_)
                 if ((isinstance(tt, NumberToken)) and tt.next0_ is not None
                         and tt.next0_.is_char(')')):
                     re = BookLinkRefReferent()
                     re.number = str(tt.value)
                     return ReferentToken(re, t, tt.next0_)
                 break
             return None
         if (bbb.typ == BookLinkTyp.NUMBER):
             tt1 = bbb.end_token.next0_
             if (tt1 is not None and tt1.is_comma):
                 tt1 = tt1.next0_
             bbb2 = BookLinkToken.try_parse(tt1, 0)
             if ((bbb2 is not None and bbb2.typ == BookLinkTyp.PAGERANGE
                  and bbb2.end_token.next0_ is not None)
                     and bbb2.end_token.next0_.is_char(')')):
                 re = BookLinkRefReferent()
                 re.number = bbb.value
                 re.pages = bbb2.value
                 return ReferentToken(re, t, bbb2.end_token.next0_)
     return None
Esempio n. 7
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
Esempio n. 8
0
 def __analizeSubsidiary(self, bfi: 'BusinessFactItem') -> 'ReferentToken':
     t1 = bfi.end_token.next0_
     if (t1 is None
             or not ((isinstance(t1.getReferent(), OrganizationReferent)))):
         return None
     org0 = None
     t = bfi.begin_token.previous
     first_pass2777 = True
     while True:
         if first_pass2777: first_pass2777 = False
         else: t = t.previous
         if (not (t is not None)): break
         if (t.isChar('(') or t.isChar('%')):
             continue
         if (t.morph.class0_.is_verb):
             continue
         if (isinstance(t, NumberToken)):
             continue
         org0 = (Utils.asObjectOrNull(t.getReferent(),
                                      OrganizationReferent))
         if (org0 is not None):
             break
     if (org0 is None):
         return None
     bfr = BusinessFactReferent._new436(bfi.base_kind)
     bfr.who = org0
     bfr.whom = t1.getReferent()
     return ReferentToken(bfr, t, t1)
Esempio n. 9
0
 def __try_attach_moscowao(li: typing.List['TerrItemToken'],
                           ad: 'AnalyzerData') -> 'ReferentToken':
     if (li[0].termin_item is None
             or not li[0].termin_item.is_moscow_region):
         return None
     if (li[0].is_doubt):
         ok = False
         if (CityAttachHelper.check_city_after(li[0].end_token.next0_)):
             ok = True
         else:
             ali = AddressItemToken.try_parse_list(li[0].end_token.next0_,
                                                   None, 2)
             if (ali is not None and len(ali) > 0
                     and ali[0].typ == AddressItemToken.ItemType.STREET):
                 ok = True
         if (not ok):
             return None
     reg = GeoReferent()
     typ = "АДМИНИСТРАТИВНЫЙ ОКРУГ"
     reg._add_typ(typ)
     name = li[0].termin_item.canonic_text
     if (LanguageHelper.ends_with(name, typ)):
         name = name[0:0 + len(name) - len(typ) - 1].strip()
     reg._add_name(name)
     return ReferentToken(reg, li[0].begin_token, li[0].end_token)
Esempio n. 10
0
 def processReferent1(self, begin : 'Token', end : 'Token') -> 'ReferentToken':
     wrapet2517 = RefOutArgWrapper(None)
     tpr = TitlePageAnalyzer._process(begin, (0 if end is None else end.end_char), begin.kit, wrapet2517)
     et = wrapet2517.value
     if (tpr is None): 
         return None
     return ReferentToken(tpr, begin, et)
Esempio n. 11
0
 def __try_attach(self, pli : typing.List['PhoneItemToken'], ind : int, is_phone_before : bool, prev_phone : 'PhoneReferent') -> typing.List['ReferentToken']:
     rt = self.__try_attach_(pli, ind, is_phone_before, prev_phone, 0)
     if (rt is None): 
         return None
     res = list()
     res.append(rt)
     for i in range(5):
         ph0 = Utils.asObjectOrNull(rt.referent, PhoneReferent)
         if (ph0.add_number is not None): 
             return res
         alt = PhoneItemToken.try_attach_alternate(rt.end_token.next0_, ph0, pli)
         if (alt is None): 
             break
         ph = PhoneReferent()
         for s in rt.referent.slots: 
             ph.add_slot(s.type_name, s.value, False, 0)
         num = ph.number
         if (num is None or len(num) <= len(alt.value)): 
             break
         ph.number = num[0:0+len(num) - len(alt.value)] + alt.value
         ph._m_template = ph0._m_template
         rt2 = ReferentToken(ph, alt.begin_token, alt.end_token)
         res.append(rt2)
         rt = rt2
     add = PhoneItemToken.try_attach_additional(rt.end_token.next0_)
     if (add is not None): 
         for rr in res: 
             rr.referent.add_number = add.value
         res[len(res) - 1].end_token = add.end_token
     return res
Esempio n. 12
0
 def process(self, kit: 'AnalysisKit') -> None:
     ad = kit.get_analyzer_data(self)
     delta = 100000
     parts = math.floor((((len(kit.sofa.text) + delta) - 1)) / delta)
     if (parts == 0):
         parts = 1
     cur = 0
     next_pos = 0
     t = kit.first_token
     first_pass3182 = True
     while True:
         if first_pass3182: first_pass3182 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (t.begin_char > next_pos):
             next_pos += delta
             cur += 1
             if (not self._on_progress(cur, parts, kit)):
                 break
         at = GoodAttrToken.try_parse(t, None, True, True)
         if (at is None):
             continue
         attr = at._create_attr()
         if (attr is None):
             t = at.end_token
             continue
         rt = ReferentToken(attr, at.begin_token, at.end_token)
         rt.referent = ad.register_referent(attr)
         kit.embed_token(rt)
         t = (rt)
Esempio n. 13
0
 def __add_referents(self, ad : 'AnalyzerData', t : 'Token', cur : int, max0_ : int) -> 'Token':
     if (not (isinstance(t, ReferentToken))): 
         return t
     r = t.get_referent()
     if (r is None): 
         return t
     if (isinstance(r, DenominationReferent)): 
         dr = Utils.asObjectOrNull(r, DenominationReferent)
         kref0 = KeywordReferent._new1595(KeywordType.REFERENT)
         for s in dr.slots: 
             if (s.type_name == DenominationReferent.ATTR_VALUE): 
                 kref0.add_slot(KeywordReferent.ATTR_NORMAL, s.value, False, 0)
         kref0.add_slot(KeywordReferent.ATTR_REF, dr, False, 0)
         rt0 = ReferentToken(ad.register_referent(kref0), t, t)
         t.kit.embed_token(rt0)
         return rt0
     if ((isinstance(r, PhoneReferent)) or (isinstance(r, UriReferent)) or (isinstance(r, BankDataReferent))): 
         return t
     if (isinstance(r, MoneyReferent)): 
         mr = Utils.asObjectOrNull(r, MoneyReferent)
         kref0 = KeywordReferent._new1595(KeywordType.OBJECT)
         kref0.add_slot(KeywordReferent.ATTR_NORMAL, mr.currency, False, 0)
         rt0 = ReferentToken(ad.register_referent(kref0), t, t)
         t.kit.embed_token(rt0)
         return rt0
     if (r.type_name == "DATE" or r.type_name == "DATERANGE" or r.type_name == "BOOKLINKREF"): 
         return t
     tt = t.begin_token
     while tt is not None and tt.end_char <= t.end_char: 
         if (isinstance(tt, ReferentToken)): 
             self.__add_referents(ad, tt, cur, max0_)
         tt = tt.next0_
     kref = KeywordReferent._new1595(KeywordType.REFERENT)
     norm = None
     if (r.type_name == "GEO"): 
         norm = r.get_string_value("ALPHA2")
     if (norm is None): 
         norm = r.to_string(True, None, 0)
     if (norm is not None): 
         kref.add_slot(KeywordReferent.ATTR_NORMAL, norm.upper(), False, 0)
     kref.add_slot(KeywordReferent.ATTR_REF, t.get_referent(), False, 0)
     KeywordAnalyzer.__set_rank(kref, cur, max0_)
     rt1 = ReferentToken(ad.register_referent(kref), t, t)
     t.kit.embed_token(rt1)
     return rt1
Esempio n. 14
0
 def __try4(li: typing.List['CityItemToken']) -> 'ReferentToken':
     if ((len(li) > 0 and li[0].typ == CityItemToken.ItemType.NOUN and
          ((li[0].value != "ГОРОД" and li[0].value != "МІСТО"
            and li[0].value != "CITY")))
             and ((not li[0].doubtful or li[0].geo_object_before))):
         if (len(li) > 1 and li[1].org_ref is not None):
             geo_ = GeoReferent()
             geo_._addTyp(li[0].value)
             geo_._addOrgReferent(li[1].org_ref.referent)
             geo_.addExtReferent(li[1].org_ref)
             return ReferentToken(geo_, li[0].begin_token, li[1].end_token)
         else:
             aid = AddressItemToken.tryAttachOrg(li[0].end_token.next0_)
             if (aid is not None):
                 geo_ = GeoReferent()
                 geo_._addTyp(li[0].value)
                 geo_._addOrgReferent(aid.referent)
                 geo_.addExtReferent(aid.ref_token)
                 return ReferentToken(geo_, li[0].begin_token,
                                      aid.end_token)
     return None
Esempio n. 15
0
 def try_attach_stateusaterritory(t: 'Token') -> 'ReferentToken':
     if (t is None or not t.chars.is_latin_letter):
         return None
     tok = TerrItemToken._m_geo_abbrs.try_parse(t, TerminParseAttr.NO)
     if (tok is None):
         return None
     g = Utils.asObjectOrNull(tok.termin.tag, GeoReferent)
     if (g is None):
         return None
     if (tok.end_token.next0_ is not None
             and tok.end_token.next0_.is_char('.')):
         tok.end_token = tok.end_token.next0_
     gg = g.clone()
     gg.occurrence.clear()
     return ReferentToken(gg, tok.begin_token, tok.end_token)
Esempio n. 16
0
 def __create_refs(
         its: typing.List['DateExItemToken']
 ) -> typing.List['ReferentToken']:
     res = list()
     own = None
     i = 0
     first_pass3074 = True
     while True:
         if first_pass3074: first_pass3074 = False
         else: i += 1
         if (not (i < len(its))): break
         it = its[i]
         d = DateReferent()
         if (it.is_value_relate):
             d.is_relative = True
         if (own is not None):
             d.higher = own
         if (it.typ == DateExToken.DateExItemTokenType.DAY):
             d.day = it.value
         elif (it.typ == DateExToken.DateExItemTokenType.DAYOFWEEK):
             d.day_of_week = it.value
         elif (it.typ == DateExToken.DateExItemTokenType.HOUR):
             d.hour = it.value
             if (((i + 1) < len(its)) and its[i + 1].typ
                     == DateExToken.DateExItemTokenType.MINUTE
                     and not its[i + 1].is_value_relate):
                 d.minute = its[i + 1].value
                 i += 1
         elif (it.typ == DateExToken.DateExItemTokenType.MINUTE):
             d.minute = it.value
         elif (it.typ == DateExToken.DateExItemTokenType.MONTH):
             d.month = it.value
         elif (it.typ == DateExToken.DateExItemTokenType.QUARTAL):
             d.quartal = it.value
         elif (it.typ == DateExToken.DateExItemTokenType.WEEK):
             d.week = it.value
         elif (it.typ == DateExToken.DateExItemTokenType.YEAR):
             d.year = it.value
         else:
             continue
         res.append(ReferentToken(d, it.begin_token, it.end_token))
         own = d
         it.src = d
     if (len(res) > 0):
         res[0].tag = (own)
     return res
Esempio n. 17
0
 def process_ontology_item(self, begin: 'Token') -> 'ReferentToken':
     if (begin is None):
         return None
     ga = GoodAttributeReferent()
     if (begin.chars.is_latin_letter):
         if (begin.is_value("KEYWORD", None)):
             ga.typ = GoodAttrType.KEYWORD
             begin = begin.next0_
         elif (begin.is_value("CHARACTER", None)):
             ga.typ = GoodAttrType.CHARACTER
             begin = begin.next0_
         elif (begin.is_value("PROPER", None)):
             ga.typ = GoodAttrType.PROPER
             begin = begin.next0_
         elif (begin.is_value("MODEL", None)):
             ga.typ = GoodAttrType.MODEL
             begin = begin.next0_
         if (begin is None):
             return None
     res = ReferentToken(ga, begin, begin)
     t = begin
     first_pass3181 = True
     while True:
         if first_pass3181: first_pass3181 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (t.is_char(';')):
             ga.add_slot(
                 GoodAttributeReferent.ATTR_VALUE,
                 MiscHelper.get_text_value(begin, t.previous,
                                           GetTextAttr.NO), False, 0)
             begin = t.next0_
             continue
         res.end_token = t
     if (res.end_char > begin.begin_char):
         ga.add_slot(
             GoodAttributeReferent.ATTR_VALUE,
             MiscHelper.get_text_value(begin, res.end_token,
                                       GetTextAttr.NO), False, 0)
     if (ga.typ == GoodAttrType.UNDEFINED):
         if (not begin.chars.is_all_lower):
             ga.typ = GoodAttrType.PROPER
     return res
Esempio n. 18
0
 def __analizeGet2(self, t: 'Token') -> 'ReferentToken':
     if (t is None):
         return None
     tt = t.previous
     ts = t
     if (tt is not None and tt.is_comma):
         tt = tt.previous
     bef = self.__FindRefBefore(tt)
     master = None
     slave = None
     if (bef is not None and (isinstance(bef.referent, FundsReferent))):
         slave = bef.referent
         ts = bef.begin_token
     tt = t.next0_
     if (tt is None):
         return None
     te = tt
     r = tt.getReferent()
     if ((isinstance(r, PersonReferent))
             or (isinstance(r, OrganizationReferent))):
         master = r
         if (slave is None and tt.next0_ is not None):
             r = tt.next0_.getReferent()
             if ((r) is not None):
                 if ((isinstance(r, FundsReferent))
                         or (isinstance(r, OrganizationReferent))):
                     slave = (Utils.asObjectOrNull(r, FundsReferent))
                     te = tt.next0_
     if (master is not None and slave is not None):
         bfr = BusinessFactReferent._new436(BusinessFactKind.HAVE)
         bfr.who = master
         if (isinstance(slave, OrganizationReferent)):
             bfr._addWhat(slave)
             bfr.typ = "владение компанией"
         elif (isinstance(slave, FundsReferent)):
             bfr._addWhat(slave)
             bfr.typ = "владение ценными бумагами"
         else:
             return None
         return ReferentToken(bfr, ts, te)
     return None
Esempio n. 19
0
 def __analizeFinance(self, bfi: 'BusinessFactItem') -> 'ReferentToken':
     bef = self.__FindRefBefore(bfi.begin_token.previous)
     if (bef is None):
         return None
     if (not ((isinstance(bef.referent, OrganizationReferent)))
             and not ((isinstance(bef.referent, PersonReferent)))):
         return None
     whom = None
     sum0_ = None
     funds = None
     t = bfi.end_token.next0_
     while t is not None:
         if (t.is_newline_before or t.isChar('.')):
             break
         r = t.getReferent()
         if (isinstance(r, OrganizationReferent)):
             if (whom is None):
                 whom = (Utils.asObjectOrNull(t, ReferentToken))
         elif (isinstance(r, MoneyReferent)):
             if (sum0_ is None):
                 sum0_ = (Utils.asObjectOrNull(r, MoneyReferent))
         elif (isinstance(r, FundsReferent)):
             if (funds is None):
                 funds = (Utils.asObjectOrNull(r, FundsReferent))
         t = t.next0_
     if (whom is None):
         return None
     bfr = BusinessFactReferent()
     if (funds is None):
         bfr.kind = BusinessFactKind.FINANCE
     else:
         bfr.kind = BusinessFactKind.GET
         bfr.typ = "покупка ценных бумаг"
     bfr.who = bef.referent
     bfr.whom = whom.referent
     if (funds is not None):
         bfr._addWhat(funds)
     if (sum0_ is not None):
         bfr.addSlot(BusinessFactReferent.ATTR_MISC, sum0_, False, 0)
     self.__findDate(bfr, bef.begin_token)
     return ReferentToken(bfr, bef.begin_token, whom.end_token)
Esempio n. 20
0
 def process(self, kit: 'AnalysisKit') -> None:
     ad = kit.get_analyzer_data(self)
     delta = 100000
     parts = math.floor((((len(kit.sofa.text) + delta) - 1)) / delta)
     if (parts == 0):
         parts = 1
     cur = 0
     next_pos = 0
     goods_ = list()
     t = kit.first_token
     first_pass3180 = True
     while True:
         if first_pass3180: first_pass3180 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (not t.is_newline_before):
             continue
         if (t.begin_char > next_pos):
             next_pos += delta
             cur += 1
             if (not self._on_progress(cur, parts, kit)):
                 break
         if (not t.chars.is_letter and t.next0_ is not None):
             t = t.next0_
         rts = GoodAttrToken.try_parse_list(t)
         if (rts is None or len(rts) == 0):
             continue
         good = GoodReferent()
         for rt in rts:
             rt.referent = ad.register_referent(rt.referent)
             if (good.find_slot(GoodReferent.ATTR_ATTR, rt.referent, True)
                     is None):
                 good.add_slot(GoodReferent.ATTR_ATTR, rt.referent, False,
                               0)
             kit.embed_token(rt)
         goods_.append(good)
         rt0 = ReferentToken(good, rts[0], rts[len(rts) - 1])
         kit.embed_token(rt0)
         t = (rt0)
     for g in goods_:
         ad.referents.append(g)
Esempio n. 21
0
 def create_referents(et: 'DateExToken') -> typing.List['ReferentToken']:
     if (not et.is_diap or len(et.items_to) == 0):
         li = DateRelHelper.__create_refs(et.items_from)
         if (li is None or len(li) == 0):
             return None
         return li
     li_fr = DateRelHelper.__create_refs(et.items_from)
     li_to = DateRelHelper.__create_refs(et.items_to)
     ra = DateRangeReferent()
     if (len(li_fr) > 0):
         ra.date_from = Utils.asObjectOrNull(li_fr[0].tag, DateReferent)
     if (len(li_to) > 0):
         ra.date_to = Utils.asObjectOrNull(li_to[0].tag, DateReferent)
     res = list()
     res.extend(li_fr)
     res.extend(li_to)
     res.append(ReferentToken(ra, et.begin_token, et.end_token))
     if (len(res) == 0):
         return None
     res[0].tag = (ra)
     return res
Esempio n. 22
0
 def tryAttachStateUSATerritory(t: 'Token') -> 'ReferentToken':
     """ Это привязка сокращений штатов
     
     Args:
         t(Token): 
     
     """
     if (t is None or not t.chars.is_latin_letter):
         return None
     tok = TerrItemToken._m_geo_abbrs.tryParse(t, TerminParseAttr.NO)
     if (tok is None):
         return None
     g = Utils.asObjectOrNull(tok.termin.tag, GeoReferent)
     if (g is None):
         return None
     if (tok.end_token.next0_ is not None
             and tok.end_token.next0_.isChar('.')):
         tok.end_token = tok.end_token.next0_
     gg = g.clone()
     gg.occurrence.clear()
     return ReferentToken(gg, tok.begin_token, tok.end_token)
Esempio n. 23
0
 def __deserialize_token(stream : Stream, kit : 'AnalysisKit', vers : int) -> 'Token':
     from pullenti.ner.MetaToken import MetaToken
     from pullenti.ner.ReferentToken import ReferentToken
     typ = SerializerHelper.deserialize_short(stream)
     if (typ == (0)): 
         return None
     t = None
     if (typ == (1)): 
         t = (TextToken(None, kit))
     elif (typ == (2)): 
         t = (NumberToken(None, None, None, NumberSpellingType.DIGIT, kit))
     elif (typ == (3)): 
         t = (ReferentToken(None, None, None, kit))
     else: 
         t = (MetaToken(None, None, kit))
     t._deserialize(stream, kit, vers)
     if (isinstance(t, MetaToken)): 
         tt = SerializerHelper.deserialize_tokens(stream, kit, vers)
         if (tt is not None): 
             t._m_begin_token = tt
             while tt is not None: 
                 t._m_end_token = tt
                 tt = tt.next0_
     return t
Esempio n. 24
0
 def process(self, kit: 'AnalysisKit') -> None:
     ad = kit.getAnalyzerData(self)
     models = TerminCollection()
     objs_by_model = dict()
     obj_by_names = TerminCollection()
     t = kit.first_token
     first_pass3158 = True
     while True:
         if first_pass3158: first_pass3158 = False
         else: t = t.next0_
         if (not (t is not None)): break
         its = WeaponItemToken.tryParseList(t, 10)
         if (its is None):
             continue
         rts = self.__tryAttach(its, False)
         if (rts is not None):
             for rt in rts:
                 rt.referent = ad.registerReferent(rt.referent)
                 kit.embedToken(rt)
                 t = (rt)
                 for s in rt.referent.slots:
                     if (s.type_name == WeaponReferent.ATTR_MODEL):
                         mod = str(s.value)
                         for k in range(2):
                             if (not str.isdigit(mod[0])):
                                 li = []
                                 wrapli2638 = RefOutArgWrapper(None)
                                 inoutres2639 = Utils.tryGetValue(
                                     objs_by_model, mod, wrapli2638)
                                 li = wrapli2638.value
                                 if (not inoutres2639):
                                     li = list()
                                     objs_by_model[mod] = li
                                 if (not rt.referent in li):
                                     li.append(rt.referent)
                                 models.addStr(mod, li, None, False)
                             if (k > 0):
                                 break
                             brand = rt.referent.getStringValue(
                                 WeaponReferent.ATTR_BRAND)
                             if (brand is None):
                                 break
                             mod = "{0} {1}".format(brand, mod)
                     elif (s.type_name == WeaponReferent.ATTR_NAME):
                         obj_by_names.add(
                             Termin._new117(str(s.value), rt.referent))
     if (len(objs_by_model) == 0 and len(obj_by_names.termins) == 0):
         return
     t = kit.first_token
     first_pass3159 = True
     while True:
         if first_pass3159: first_pass3159 = False
         else: t = t.next0_
         if (not (t is not None)): break
         br = BracketHelper.tryParse(t, BracketParseAttr.NO, 10)
         if (br is not None):
             toks = obj_by_names.tryParse(t.next0_, TerminParseAttr.NO)
             if (toks is not None
                     and toks.end_token.next0_ == br.end_token):
                 rt0 = ReferentToken(
                     Utils.asObjectOrNull(toks.termin.tag, Referent),
                     br.begin_token, br.end_token)
                 kit.embedToken(rt0)
                 t = (rt0)
                 continue
         if (not ((isinstance(t, TextToken)))):
             continue
         if (not t.chars.is_letter):
             continue
         tok = models.tryParse(t, TerminParseAttr.NO)
         if (tok is None):
             if (not t.chars.is_all_lower):
                 tok = obj_by_names.tryParse(t, TerminParseAttr.NO)
             if (tok is None):
                 continue
         if (not tok.is_whitespace_after):
             if (tok.end_token.next0_ is None
                     or not tok.end_token.next0_.isCharOf(",.)")):
                 if (not BracketHelper.isBracket(tok.end_token.next0_,
                                                 False)):
                     continue
         tr = None
         li = Utils.asObjectOrNull(tok.termin.tag, list)
         if (li is not None and len(li) == 1):
             tr = li[0]
         else:
             tr = (Utils.asObjectOrNull(tok.termin.tag, Referent))
         if (tr is not None):
             tit = WeaponItemToken.tryParse(tok.begin_token.previous, None,
                                            False, True)
             if (tit is not None and tit.typ == WeaponItemToken.Typs.BRAND):
                 tr.addSlot(WeaponReferent.ATTR_BRAND, tit.value, False, 0)
                 tok.begin_token = tit.begin_token
             rt0 = ReferentToken(tr, tok.begin_token, tok.end_token)
             kit.embedToken(rt0)
             t = (rt0)
             continue
Esempio n. 25
0
 def __tryAttach(self, its: typing.List['WeaponItemToken'],
                 attach: bool) -> typing.List['ReferentToken']:
     tr = WeaponReferent()
     t1 = None
     noun = None
     brand = None
     model = None
     i = 0
     first_pass3160 = True
     while True:
         if first_pass3160: first_pass3160 = False
         else: i += 1
         if (not (i < len(its))): break
         if (its[i].typ == WeaponItemToken.Typs.NOUN):
             if (len(its) == 1):
                 return None
             if (tr.findSlot(WeaponReferent.ATTR_TYPE, None, True)
                     is not None):
                 if (tr.findSlot(WeaponReferent.ATTR_TYPE, its[i].value,
                                 True) is None):
                     break
             if (not its[i].is_internal):
                 noun = its[i]
             tr.addSlot(WeaponReferent.ATTR_TYPE, its[i].value, False, 0)
             if (its[i].alt_value is not None):
                 tr.addSlot(WeaponReferent.ATTR_TYPE, its[i].alt_value,
                            False, 0)
             t1 = its[i].end_token
             continue
         if (its[i].typ == WeaponItemToken.Typs.BRAND):
             if (tr.findSlot(WeaponReferent.ATTR_BRAND, None, True)
                     is not None):
                 if (tr.findSlot(WeaponReferent.ATTR_BRAND, its[i].value,
                                 True) is None):
                     break
             if (not its[i].is_internal):
                 if (noun is not None and noun.is_doubt):
                     noun.is_doubt = False
             brand = its[i]
             tr.addSlot(WeaponReferent.ATTR_BRAND, its[i].value, False, 0)
             t1 = its[i].end_token
             continue
         if (its[i].typ == WeaponItemToken.Typs.MODEL):
             if (tr.findSlot(WeaponReferent.ATTR_MODEL, None, True)
                     is not None):
                 if (tr.findSlot(WeaponReferent.ATTR_MODEL, its[i].value,
                                 True) is None):
                     break
             model = its[i]
             tr.addSlot(WeaponReferent.ATTR_MODEL, its[i].value, False, 0)
             if (its[i].alt_value is not None):
                 tr.addSlot(WeaponReferent.ATTR_MODEL, its[i].alt_value,
                            False, 0)
             t1 = its[i].end_token
             continue
         if (its[i].typ == WeaponItemToken.Typs.NAME):
             if (tr.findSlot(WeaponReferent.ATTR_NAME, None, True)
                     is not None):
                 break
             tr.addSlot(WeaponReferent.ATTR_NAME, its[i].value, False, 0)
             if (its[i].alt_value is not None):
                 tr.addSlot(WeaponReferent.ATTR_NAME, its[i].alt_value,
                            False, 0)
             t1 = its[i].end_token
             continue
         if (its[i].typ == WeaponItemToken.Typs.NUMBER):
             if (tr.findSlot(WeaponReferent.ATTR_NUMBER, None, True)
                     is not None):
                 break
             tr.addSlot(WeaponReferent.ATTR_NUMBER, its[i].value, False, 0)
             if (its[i].alt_value is not None):
                 tr.addSlot(WeaponReferent.ATTR_NUMBER, its[i].alt_value,
                            False, 0)
             t1 = its[i].end_token
             continue
         if (its[i].typ == WeaponItemToken.Typs.DATE):
             if (tr.findSlot(WeaponReferent.ATTR_DATE, None, True)
                     is not None):
                 break
             tr.addSlot(WeaponReferent.ATTR_DATE, its[i].ref, True, 0)
             t1 = its[i].end_token
             continue
     has_good_noun = (False if noun is None else not noun.is_doubt)
     prev = None
     if (noun is None):
         tt = its[0].begin_token.previous
         while tt is not None:
             prev = Utils.asObjectOrNull(tt.getReferent(), WeaponReferent)
             if ((prev) is not None):
                 add_slots = list()
                 for s in prev.slots:
                     if (s.type_name == WeaponReferent.ATTR_TYPE):
                         tr.addSlot(s.type_name, s.value, False, 0)
                     elif (s.type_name == WeaponReferent.ATTR_BRAND
                           or s.type_name == WeaponReferent.ATTR_BRAND
                           or s.type_name == WeaponReferent.ATTR_MODEL):
                         if (tr.findSlot(s.type_name, None, True) is None):
                             add_slots.append(s)
                 for s in add_slots:
                     tr.addSlot(s.type_name, s.value, False, 0)
                 has_good_noun = True
                 break
             elif ((isinstance(tt, TextToken))
                   and ((not tt.chars.is_letter
                         or tt.morph.class0_.is_conjunction))):
                 pass
             else:
                 break
             tt = tt.previous
     if (noun is None and model is not None):
         cou = 0
         tt = its[0].begin_token.previous
         first_pass3161 = True
         while True:
             if first_pass3161: first_pass3161 = False
             else:
                 tt = tt.previous
                 cou += 1
             if (not (tt is not None and (cou < 100))): break
             prev = Utils.asObjectOrNull(tt.getReferent(), WeaponReferent)
             if ((prev) is not None):
                 if (prev.findSlot(WeaponReferent.ATTR_MODEL, model.value,
                                   True) is None):
                     continue
                 add_slots = list()
                 for s in prev.slots:
                     if (s.type_name == WeaponReferent.ATTR_TYPE):
                         tr.addSlot(s.type_name, s.value, False, 0)
                     elif (s.type_name == WeaponReferent.ATTR_BRAND
                           or s.type_name == WeaponReferent.ATTR_BRAND):
                         if (tr.findSlot(s.type_name, None, True) is None):
                             add_slots.append(s)
                 for s in add_slots:
                     tr.addSlot(s.type_name, s.value, False, 0)
                 has_good_noun = True
                 break
     if (has_good_noun):
         pass
     elif (noun is not None):
         if (model is not None
                 or ((brand is not None and not brand.is_doubt))):
             pass
         else:
             return None
     else:
         if (model is None):
             return None
         cou = 0
         ok = False
         tt = t1.previous
         while tt is not None and (cou < 20):
             if ((tt.isValue("ОРУЖИЕ", None) or tt.isValue(
                     "ВООРУЖЕНИЕ", None) or tt.isValue("ВЫСТРЕЛ", None))
                     or tt.isValue("ВЫСТРЕЛИТЬ", None)):
                 ok = True
                 break
             tt = tt.previous
             cou += 1
         if (not ok):
             return None
     res = list()
     res.append(ReferentToken(tr, its[0].begin_token, t1))
     return res
Esempio n. 26
0
 def try_attach(t: 'Token') -> 'ReferentToken':
     if (t is None or not t.chars.is_letter):
         return None
     noun = PersonIdToken.__try_parse(t, None)
     if (noun is None):
         return None
     li = list()
     t = noun.end_token.next0_
     first_pass3371 = True
     while True:
         if first_pass3371: first_pass3371 = False
         else: t = t.next0_
         if (not (t is not None)): break
         if (t.is_table_control_char):
             break
         if (t.is_char_of(",:")):
             continue
         idt = PersonIdToken.__try_parse(
             t, (li[len(li) - 1] if len(li) > 0 else noun))
         if (idt is None):
             if (t.is_value("ОТДЕЛ", None)
                     or t.is_value("ОТДЕЛЕНИЕ", None)):
                 continue
             break
         if (idt.typ == PersonIdToken.Typs.KEYWORD):
             break
         li.append(idt)
         t = idt.end_token
     if (len(li) == 0):
         return None
     num = None
     i = 0
     if (li[0].typ == PersonIdToken.Typs.NUMBER):
         if (len(li) > 1 and li[1].typ == PersonIdToken.Typs.NUMBER
                 and li[1].has_prefix):
             num = (li[0].value + li[1].value)
             i = 2
         else:
             num = li[0].value
             i = 1
     elif (li[0].typ == PersonIdToken.Typs.SERIA and len(li) > 1
           and li[1].typ == PersonIdToken.Typs.NUMBER):
         num = (li[0].value + li[1].value)
         i = 2
     elif (li[0].typ == PersonIdToken.Typs.SERIA and len(li[0].value) > 5):
         num = li[0].value
         i = 1
     else:
         return None
     pid = PersonIdentityReferent()
     pid.typ = noun.value.lower()
     pid.number = num
     if (isinstance(noun.referent, GeoReferent)):
         pid.state = noun.referent
     while i < len(li):
         if (li[i].typ == PersonIdToken.Typs.VIDAN
                 or li[i].typ == PersonIdToken.Typs.CODE):
             pass
         elif (li[i].typ == PersonIdToken.Typs.DATE
               and li[i].referent is not None):
             if (pid.find_slot(PersonIdentityReferent.ATTR_DATE, None, True)
                     is not None):
                 break
             pid.add_slot(PersonIdentityReferent.ATTR_DATE, li[i].referent,
                          False, 0)
         elif (li[i].typ == PersonIdToken.Typs.ADDRESS
               and li[i].referent is not None):
             if (pid.find_slot(PersonIdentityReferent.ATTR_ADDRESS, None,
                               True) is not None):
                 break
             pid.add_slot(PersonIdentityReferent.ATTR_ADDRESS,
                          li[i].referent, False, 0)
         elif (li[i].typ == PersonIdToken.Typs.ORG
               and li[i].referent is not None):
             if (pid.find_slot(PersonIdentityReferent.ATTR_ORG, None, True)
                     is not None):
                 break
             pid.add_slot(PersonIdentityReferent.ATTR_ORG, li[i].referent,
                          False, 0)
         else:
             break
         i += 1
     return ReferentToken(pid, noun.begin_token, li[i - 1].end_token)
Esempio n. 27
0
 def try_parse(t : 'Token') -> 'ReferentToken':
     if (t is None): 
         return None
     if (not (isinstance(t, NumberToken)) and t.length_char != 1): 
         return None
     nex = NumberHelper.try_parse_number_with_postfix(t)
     if (nex is None or nex.ex_typ != NumberExType.MONEY): 
         if ((isinstance(t, NumberToken)) and (isinstance(t.next0_, TextToken)) and (isinstance(t.next0_.next0_, NumberToken))): 
             if (t.next0_.is_hiphen or t.next0_.morph.class0_.is_preposition): 
                 res1 = NumberHelper.try_parse_number_with_postfix(t.next0_.next0_)
                 if (res1 is not None and res1.ex_typ == NumberExType.MONEY): 
                     res0 = MoneyReferent()
                     if ((t.next0_.is_hiphen and res1.real_value == 0 and res1.end_token.next0_ is not None) and res1.end_token.next0_.is_char('(')): 
                         nex2 = NumberHelper.try_parse_number_with_postfix(res1.end_token.next0_.next0_)
                         if ((nex2 is not None and nex2.ex_typ_param == res1.ex_typ_param and nex2.end_token.next0_ is not None) and nex2.end_token.next0_.is_char(')')): 
                             if (nex2.value == t.value): 
                                 res0.currency = nex2.ex_typ_param
                                 res0.add_slot(MoneyReferent.ATTR_VALUE, nex2.value, True, 0)
                                 return ReferentToken(res0, t, nex2.end_token.next0_)
                             if (isinstance(t.previous, NumberToken)): 
                                 if (nex2.value == (((t.previous.real_value * (1000)) + t.value))): 
                                     res0.currency = nex2.ex_typ_param
                                     res0.add_slot(MoneyReferent.ATTR_VALUE, nex2.value, True, 0)
                                     return ReferentToken(res0, t.previous, nex2.end_token.next0_)
                                 elif (isinstance(t.previous.previous, NumberToken)): 
                                     if (nex2.real_value == (((t.previous.previous.real_value * (1000000)) + (t.previous.real_value * (1000)) + t.real_value))): 
                                         res0.currency = nex2.ex_typ_param
                                         res0.add_slot(MoneyReferent.ATTR_VALUE, nex2.value, True, 0)
                                         return ReferentToken(res0, t.previous.previous, nex2.end_token.next0_)
                     res0.currency = res1.ex_typ_param
                     res0.add_slot(MoneyReferent.ATTR_VALUE, t.value, False, 0)
                     return ReferentToken(res0, t, t)
         return None
     res = MoneyReferent()
     res.currency = nex.ex_typ_param
     val = nex.value
     if (val.find('.') > 0): 
         val = val[0:0+val.find('.')]
     res.add_slot(MoneyReferent.ATTR_VALUE, val, True, 0)
     re = math.floor(round(((nex.real_value - res.value)) * (100), 6))
     if (re != 0): 
         res.add_slot(MoneyReferent.ATTR_REST, str(re), True, 0)
     if (nex.real_value != nex.alt_real_value): 
         if (math.floor(res.value) != math.floor(nex.alt_real_value)): 
             val = NumberHelper.double_to_string(nex.alt_real_value)
             if (val.find('.') > 0): 
                 val = val[0:0+val.find('.')]
             res.add_slot(MoneyReferent.ATTR_ALTVALUE, val, True, 0)
         re = (math.floor(round(((nex.alt_real_value - (math.floor(nex.alt_real_value)))) * (100), 6)))
         if (re != res.rest and re != 0): 
             res.add_slot(MoneyReferent.ATTR_ALTREST, str(re), True, 0)
     if (nex.alt_rest_money > 0): 
         res.add_slot(MoneyReferent.ATTR_ALTREST, str(nex.alt_rest_money), True, 0)
     t1 = nex.end_token
     if (t1.next0_ is not None and t1.next0_.is_char('(')): 
         rt = MoneyAnalyzer.try_parse(t1.next0_.next0_)
         if ((rt is not None and rt.referent.can_be_equals(res, ReferentsEqualType.WITHINONETEXT) and rt.end_token.next0_ is not None) and rt.end_token.next0_.is_char(')')): 
             t1 = rt.end_token.next0_
         else: 
             rt = MoneyAnalyzer.try_parse(t1.next0_)
             if (rt is not None and rt.referent.can_be_equals(res, ReferentsEqualType.WITHINONETEXT)): 
                 t1 = rt.end_token
     if (res.alt_value is not None and res.alt_value > res.value): 
         if (t.whitespaces_before_count == 1 and (isinstance(t.previous, NumberToken))): 
             delt = math.floor((res.alt_value - res.value))
             if ((((res.value < 1000) and ((delt % 1000)) == 0)) or (((res.value < 1000000) and ((delt % 1000000)) == 0))): 
                 t = t.previous
                 res.add_slot(MoneyReferent.ATTR_VALUE, res.get_string_value(MoneyReferent.ATTR_ALTVALUE), True, 0)
                 res.add_slot(MoneyReferent.ATTR_ALTVALUE, None, True, 0)
     return ReferentToken(res, t, t1)
Esempio n. 28
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
 def __try_attach(toks: typing.List['NamedItemToken']) -> 'ReferentToken':
     typ = None
     re = None
     nams = None
     ki = NamedEntityKind.UNDEFINED
     i = 0
     i = 0
     while i < len(toks):
         if (toks[i].type_value is not None):
             if (nams is not None and toks[i].name_value is not None):
                 break
             if (typ is None):
                 typ = toks[i]
                 ki = typ.kind
             elif (typ.kind != toks[i].kind):
                 break
         if (toks[i].name_value is not None):
             if (typ is not None
                     and toks[i].kind != NamedEntityKind.UNDEFINED
                     and toks[i].kind != typ.kind):
                 break
             if (nams is None):
                 nams = list()
             elif (nams[0].is_wellknown != toks[i].is_wellknown):
                 break
             if (ki == NamedEntityKind.UNDEFINED):
                 ki = toks[i].kind
             nams.append(toks[i])
         if (toks[i].type_value is None and toks[i].name_value is None):
             break
         if (re is None
                 and NamedEntityAnalyzer.__can_be_ref(ki, toks[i].ref)):
             re = toks[i]
         i += 1
     if ((i < len(toks)) and toks[i].ref is not None):
         if (NamedEntityAnalyzer.__can_be_ref(ki, toks[i].ref)):
             re = toks[i]
             i += 1
     ok = False
     if (typ is not None):
         if (nams is None):
             if (re is None):
                 ok = False
             else:
                 ok = True
         elif ((nams[0].begin_char < typ.end_char)
               and not nams[0].is_wellknown):
             if (re is not None):
                 ok = True
             elif ((nams[0].chars.is_capital_upper
                    and not MiscHelper.can_be_start_of_sentence(
                        nams[0].begin_token)
                    and typ.morph.number != MorphNumber.PLURAL)
                   and typ.morph.case_.is_nominative):
                 ok = True
         else:
             ok = True
     elif (nams is not None):
         if (len(nams) == 1 and nams[0].chars.is_all_lower):
             pass
         elif (nams[0].is_wellknown):
             ok = True
     if (not ok or ki == NamedEntityKind.UNDEFINED):
         return None
     nam = NamedEntityReferent._new1765(ki)
     if (typ is not None):
         nam.add_slot(NamedEntityReferent.ATTR_TYPE, typ.type_value.lower(),
                      False, 0)
     if (nams is not None):
         if (len(nams) == 1 and nams[0].is_wellknown
                 and nams[0].type_value is not None):
             nam.add_slot(NamedEntityReferent.ATTR_TYPE,
                          nams[0].type_value.lower(), False, 0)
         if (typ is not None and (typ.end_char < nams[0].begin_char)):
             str0_ = MiscHelper.get_text_value(
                 nams[0].begin_token, nams[len(nams) - 1].end_token,
                 GetTextAttr.NO)
             nam.add_slot(NamedEntityReferent.ATTR_NAME, str0_, False, 0)
         tmp = io.StringIO()
         for n in nams:
             if (tmp.tell() > 0):
                 print(' ', end="", file=tmp)
             print(n.name_value, end="", file=tmp)
         nam.add_slot(NamedEntityReferent.ATTR_NAME,
                      Utils.toStringStringIO(tmp), False, 0)
     if (re is not None):
         nam.add_slot(NamedEntityReferent.ATTR_REF, re.ref, False, 0)
     return ReferentToken(nam, toks[0].begin_token, toks[i - 1].end_token)
Esempio n. 30
0
 def createRefenetsTokensWithRegister(
         self,
         ad: 'AnalyzerData',
         register: bool = True) -> typing.List['ReferentToken']:
     if (len(self.internals) == 0 and not self.reliable):
         if (len(self.nums.units) == 1 and self.nums.units[0].is_doubt):
             if (self.nums.units[0].unknown_name is not None):
                 pass
             elif (self.nums.is_newline_before):
                 pass
             elif (self.nums.from_val is None or self.nums.to_val is None):
                 return None
     res = list()
     if (((self.nums is None or self.nums.plus_minus_percent))
             and len(self.internals) > 0):
         mr = MeasureReferent()
         templ0 = "1"
         templ = None
         if (self.name is not None):
             mr.addSlot(MeasureReferent.ATTR_NAME, self.name, False, 0)
         ints = list()
         k = 0
         first_pass3036 = True
         while True:
             if first_pass3036: first_pass3036 = False
             else: k += 1
             if (not (k < len(self.internals))): break
             ii = self.internals[k]
             ii.reliable = True
             li = ii.createRefenetsTokensWithRegister(ad, False)
             if (li is None):
                 continue
             res.extend(li)
             mr0 = Utils.asObjectOrNull(res[len(res) - 1].referent,
                                        MeasureReferent)
             if (k == 0):
                 templ0 = mr0.template
                 mr0.template = "1"
             if (ad is not None):
                 mr0 = (Utils.asObjectOrNull(ad.registerReferent(mr0),
                                             MeasureReferent))
             mr.addSlot(MeasureReferent.ATTR_VALUE, mr0, False, 0)
             ints.append(mr0)
             if (templ is None):
                 templ = "1"
             else:
                 nu = len(mr.getStringValues(MeasureReferent.ATTR_VALUE))
                 templ = "{0}{1}{2}".format(
                     templ, (", " if self.is_set else " × "), nu)
         if (self.is_set):
             templ = ("{" + templ + "}")
         if (templ0 != "1"):
             templ = templ0.replace("1", templ)
         if (self.nums is not None and self.nums.plus_minus_percent
                 and self.nums.single_val is not None):
             templ = "[{0} ±{1}%]".format(templ, len(self.internals) + 1)
             mr.addValue(self.nums.single_val)
         mr.template = templ
         has_length = False
         uref = None
         i = 0
         while i < len(ints):
             if (ints[i].kind == MeasureKind.LENGTH):
                 has_length = True
                 uref = (Utils.asObjectOrNull(
                     ints[i].getSlotValue(MeasureReferent.ATTR_UNIT),
                     UnitReferent))
             elif (len(ints[i].units) > 0):
                 break
             i += 1
         if (len(ints) > 1 and has_length and uref is not None):
             for ii in ints:
                 if (ii.findSlot(MeasureReferent.ATTR_UNIT, None, True) is
                         None):
                     ii.addSlot(MeasureReferent.ATTR_UNIT, uref, False, 0)
                     ii.kind = MeasureKind.LENGTH
         if (len(ints) == 3):
             if (ints[0].kind == MeasureKind.LENGTH
                     and ints[1].kind == MeasureKind.LENGTH
                     and ints[2].kind == MeasureKind.LENGTH):
                 mr.kind = MeasureKind.VOLUME
             elif (len(ints[0].units) == 0 and len(ints[1].units) == 0
                   and len(ints[2].units) == 0):
                 nam = mr.getStringValue(MeasureReferent.ATTR_NAME)
                 if (nam is not None):
                     if ("РАЗМЕР" in nam or "ГАБАРИТ" in nam):
                         mr.kind = MeasureKind.VOLUME
         if (len(ints) == 2):
             if (ints[0].kind == MeasureKind.LENGTH
                     and ints[1].kind == MeasureKind.LENGTH):
                 mr.kind = MeasureKind.AREA
         if (ad is not None):
             mr = (Utils.asObjectOrNull(ad.registerReferent(mr),
                                        MeasureReferent))
         res.append(ReferentToken(mr, self.begin_token, self.end_token))
         return res
     re2 = self.nums.createRefenetsTokensWithRegister(
         ad, self.name, register)
     for ii in self.internals:
         li = ii.createRefenetsTokensWithRegister(ad, True)
         if (li is None):
             continue
         res.extend(li)
         re2[len(re2) - 1].referent.addSlot(MeasureReferent.ATTR_REF,
                                            res[len(res) - 1].referent,
                                            False, 0)
     re2[len(re2) - 1].begin_token = self.begin_token
     re2[len(re2) - 1].end_token = self.end_token
     res.extend(re2)
     return res