コード例 #1
0
ファイル: FundsReferent.py プロジェクト: MihaJjDa/APCLtask
 def percent(self, value) -> float:
     if (value > 0):
         self.addSlot(FundsReferent.ATTR_PERCENT,
                      NumberHelper.doubleToString(value), True, 0)
     else:
         self.addSlot(FundsReferent.ATTR_PERCENT, None, True, 0)
     return value
コード例 #2
0
 def createReferentWithRegister(self, ad : 'AnalyzerData') -> 'UnitReferent':
     ur = self.ext_onto
     if (self.unit is not None): 
         ur = UnitToken.__createReferent(self.unit)
     elif (self.unknown_name is not None): 
         ur = UnitReferent()
         ur.addSlot(UnitReferent.ATTR_NAME, self.unknown_name, False, 0)
         ur.is_unknown = True
     if (self.pow0_ != 1): 
         ur.addSlot(UnitReferent.ATTR_POW, str(self.pow0_), False, 0)
     owns = list()
     owns.append(ur)
     if (self.unit is not None): 
         uu = self.unit.base_unit
         while uu is not None: 
             ur0 = UnitToken.__createReferent(uu)
             owns.append(ur0)
             uu = uu.base_unit
     for i in range(len(owns) - 1, -1, -1):
         if (ad is not None): 
             owns[i] = (Utils.asObjectOrNull(ad.registerReferent(owns[i]), UnitReferent))
         if (i > 0): 
             owns[i - 1].addSlot(UnitReferent.ATTR_BASEUNIT, owns[i], False, 0)
             if ((owns[i - 1].tag).base_multiplier != 0): 
                 owns[i - 1].addSlot(UnitReferent.ATTR_BASEFACTOR, NumberHelper.doubleToString((owns[i - 1].tag).base_multiplier), False, 0)
     return owns[0]
コード例 #3
0
ファイル: MoneyReferent.py プロジェクト: MihaJjDa/APCLtask
 def real_value(self, value_) -> float:
     val = NumberHelper.doubleToString(value_)
     ii = val.find('.')
     if (ii > 0):
         val = val[0:0 + ii]
     self.addSlot(MoneyReferent.ATTR_VALUE, val, True, 0)
     re = ((value_ - self.value)) * (100)
     self.addSlot(MoneyReferent.ATTR_REST, str((math.floor((re + .0001)))),
                  True, 0)
     return value_
コード例 #4
0
 def real_value(self, value_) -> float:
     from pullenti.ner.core.NumberHelper import NumberHelper
     self.value = NumberHelper.doubleToString(value_)
     return value_
コード例 #5
0
ファイル: MeasureReferent.py プロジェクト: MihaJjDa/APCLtask
 def addValue(self, d : float) -> None:
     self.addSlot(MeasureReferent.ATTR_VALUE, NumberHelper.doubleToString(d), False, 0)
コード例 #6
0
 def tryParse(t: 'Token') -> 'ReferentToken':
     if (t is None):
         return None
     if (not ((isinstance(t, NumberToken))) and t.length_char != 1):
         return None
     nex = NumberHelper.tryParseNumberWithPostfix(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.tryParseNumberWithPostfix(
                     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_.isChar('(')):
                         nex2 = NumberHelper.tryParseNumberWithPostfix(
                             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_.isChar(')')):
                             if (nex2.value == (t).value):
                                 res0.currency = nex2.ex_typ_param
                                 res0.addSlot(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.addSlot(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.addSlot(
                                             MoneyReferent.ATTR_VALUE,
                                             nex2.value, True, 0)
                                         return ReferentToken(
                                             res0, t.previous.previous,
                                             nex2.end_token.next0_)
                     res0.currency = res1.ex_typ_param
                     res0.addSlot(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.addSlot(MoneyReferent.ATTR_VALUE, val, True, 0)
     re = math.floor(round(((nex.real_value - res.value)) * (100), 6))
     if (re != 0):
         res.addSlot(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.doubleToString(nex.alt_real_value)
             if (val.find('.') > 0):
                 val = val[0:0 + val.find('.')]
             res.addSlot(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.addSlot(MoneyReferent.ATTR_ALTREST, str((re)), True, 0)
     if (nex.alt_rest_money > 0):
         res.addSlot(MoneyReferent.ATTR_ALTREST, str(nex.alt_rest_money),
                     True, 0)
     t1 = nex.end_token
     if (t1.next0_ is not None and t1.next0_.isChar('(')):
         rt = MoneyAnalyzer.tryParse(t1.next0_.next0_)
         if ((rt is not None and rt.referent.canBeEquals(
                 res, Referent.EqualType.WITHINONETEXT)
              and rt.end_token.next0_ is not None)
                 and rt.end_token.next0_.isChar(')')):
             t1 = rt.end_token.next0_
         else:
             rt = MoneyAnalyzer.tryParse(t1.next0_)
             if (rt is not None and rt.referent.canBeEquals(
                     res, Referent.EqualType.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.addSlot(
                     MoneyReferent.ATTR_VALUE,
                     res.getStringValue(MoneyReferent.ATTR_ALTVALUE), True,
                     0)
                 res.addSlot(MoneyReferent.ATTR_ALTVALUE, None, True, 0)
     return ReferentToken(res, t, t1)