Exemple #1
0
    def parse_digits(self, str, ex_dict=None):
        if str == None or len(str) == 0: return None
        sum = 0
        digit = 0
        min_unit = 0

        for s in str:
            d = td.property(s, td.wordtype.digit)
            if d == None:
                if ex_dict == None: break
                d = ex_dict.get(s, None)
                if d == None: break

            if (0 < d and d < 10) or \
                    (d == 0 and digit != 0):
                digit = digit * 10 + d
            else:
                if d == 0:
                    min_unit = 10
                else:
                    min_unit = d
                    sum += digit == 0 and d or digit * d
                    digit = 0

        if digit > 0:
            sum += min_unit == 0 and digit or digit * (min_unit / 10)

        return sum
Exemple #2
0
 def parse_degree(self, s):
     if s == None or len(s) == 0: return None
     degree = 0
     for k in s:
         d = td.property(k, td.wordtype.degree)
         if d == None:
             print(u"can not find property for {0}".format(k))
             continue
         degree += d
     return degree
Exemple #3
0
 def parse_relation(self, s):
     return None if s == None or len(s) == 0 else td.property(
         s, td.wordtype.relation)
Exemple #4
0
 def parse_special_hour(self, s):
     return None if s == None or len(s) == 0 else td.property(
         s, td.wordtype.special_hour)
Exemple #5
0
 def parse_direct(self, s):
     return None if s == None or len(s) == 0 else td.property(
         s, td.wordtype.direct)
Exemple #6
0
 def parse_lunar_month(self, s):
     return None if s == None or len(s) == 0 else td.property(
         s, td.wordtype.lunar_month)
Exemple #7
0
 def parse_holiday(self, s):
     return None if s == None or len(s) == 0 else td.property(
         s, td.wordtype.holiday)
Exemple #8
0
 def parse_calendar(self, s):
     return None if s == None or len(s) == 0 else td.property(
         s, td.wordtype.calendar)
Exemple #9
0
 def parse_quantity(self, s):
     return None if s == None or len(s) == 0 else td.property(
         s, td.wordtype.quantity)