예제 #1
0
    def parse_by_rules(self, text):
        # TODO: refine me, here is an ad-hoc patch to distinguish weekday and hour
        _text = re.sub(ur'([周|星期]\w)(\d)', r'\1 \2', text, flags=re.U)
        self.words = pseg.lcut(parse_cn_number(_text), HMM=False)
        while self.has_next():
            self.parse_beginning = self.get_index()

            self.consume_repeat()

            self.consume_year_period() \
                or self.consume_month_period() \
                or self.consume_day_period()

            self.consume_weekday_period() \
                or self.consume_hour_period() \
                or self.consume_minute_period() \
                or self.consume_second_period()

            self.consume_year() \
                or self.consume_month() \
                or self.consume_day()

            self.consume_hour()

            if self.get_index() != self.parse_beginning:
                # Time found
                self.consume_word(u'准时')
                self.consume_word(u'是')
                if self.consume_word(u'提醒'):
                    self.consume_word(u'我')
                if self.current_tag() == 'v' and self.peek_next_word() == u'我':
                    self.advance(2)
                self.consume_to_end()
                try:
                    self.now += relativedelta(**self.time_delta_fields)
                    self.now = self.now.replace(**self.time_fields)
                except ValueError:
                    raise ParseError(u'/:no亲,时间或者日期超范围了')
                # Donot set event to None, since serializer will just skip None and we will have no chance to modify it
                remind = Remind(time=self.now,
                                repeat=self.repeat,
                                desc=text,
                                event=self.do_what)
                remind.reschedule()
                return remind
            else:
                self.advance()
        return None
예제 #2
0
    def parse_by_rules(self, text):
        self.words = pseg.lcut(parse_cn_number(text), HMM=False)
        while self.has_next():
            beginning = self.get_index()

            self.consume_repeat()

            self.consume_year_period() \
                or self.consume_month_period() \
                or self.consume_day_period()

            self.consume_weekday_period() \
                or self.consume_hour_period() \
                or self.consume_minute_period() \
                or self.consume_second_period()

            self.consume_year() \
                or self.consume_month() \
                or self.consume_day()

            self.consume_hour()

            if self.get_index() != beginning:
                # Time found
                self.consume_word(u'准时')
                if self.consume_word(u'提醒'):
                    self.consume_word(u'我')
                if self.current_tag() == 'v' and self.peek_next_word() == u'我':
                    self.advance(2)
                self.consume_to_end()
                # Donot set event to None,since serializer will just skip None and we will have no chance to modify it
                remind = Remind(time=self.now,
                                repeat=self.repeat,
                                desc=text,
                                event=self.do_what)
                remind.reschedule()
                return remind
            else:
                self.advance()
        return None
예제 #3
0
    def parse_by_rules(self, text):
        self.words = pseg.lcut(parse_cn_number(text), HMM=False)
        while self.has_next():
            beginning = self.get_index()

            self.consume_repeat()

            self.consume_year_period() \
                or self.consume_month_period() \
                or self.consume_day_period()

            self.consume_weekday_period() \
                or self.consume_hour_period() \
                or self.consume_minute_period() \
                or self.consume_second_period()

            self.consume_year() \
                or self.consume_month() \
                or self.consume_day()

            self.consume_hour()

            if self.get_index() != beginning:
                # Time found
                self.consume_word(u'准时')
                if self.consume_word(u'提醒'):
                    self.consume_word(u'我')
                if self.current_tag() == 'v' and self.peek_next_word() == u'我':
                    self.advance(2)
                self.consume_to_end()
                # Donot set event to None,since serializer will just skip None and we will have no chance to modify it
                remind = Remind(time=self.now, repeat=self.repeat, desc=text, event=self.do_what)
                remind.reschedule()
                return remind
            else:
                self.advance()
        return None