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
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
def parse_relation(self, s): return None if s == None or len(s) == 0 else td.property( s, td.wordtype.relation)
def parse_special_hour(self, s): return None if s == None or len(s) == 0 else td.property( s, td.wordtype.special_hour)
def parse_direct(self, s): return None if s == None or len(s) == 0 else td.property( s, td.wordtype.direct)
def parse_lunar_month(self, s): return None if s == None or len(s) == 0 else td.property( s, td.wordtype.lunar_month)
def parse_holiday(self, s): return None if s == None or len(s) == 0 else td.property( s, td.wordtype.holiday)
def parse_calendar(self, s): return None if s == None or len(s) == 0 else td.property( s, td.wordtype.calendar)
def parse_quantity(self, s): return None if s == None or len(s) == 0 else td.property( s, td.wordtype.quantity)