Example #1
0
 def __from_match(self, match, src_time):
     """ Initialize the instance given a plaintext match string."""
     # It's possible to match but not be parseable because our regex allows values with no meridian.
     # parsedatetime needs this however so we just append PM unless we know otherwise.
     append_meridien_match = self.EXTRACTION_REGEX.search(match) 
     if append_meridien_match:
         if not append_meridien_match.groupdict().get(u'meridian'):
             match = match + " PM"
         seed_dt = utils.safe_parsedatetime_first_nlp(match, src_time).get(u'datetime')
         if seed_dt:
             self.match = match
             self.modification = seed_dt
     else:
         raise ValueError(u'ReferencePointModifierAtom cannot parse and intialized from given match value = '\
                 + unicode(match))
Example #2
0
 def __from_match(self, match, src_time, parse_type=u'range'):
     """ Initialize the instance given a plaintext match string."""
     seed_dt = utils.safe_parsedatetime_first_nlp(match, src_time).get(u'datetime')
     if seed_dt:
         if parse_type == u'range':
             start = utils.start_of_day(seed_dt)
             end = utils.end_of_day(seed_dt)
         elif parse_type == u'exact':
             start = seed_dt
             end = seed_dt + datetime.timedelta(seconds=0)
         else:
             raise ValueError(u'Invalid value for parse_type. Try "range" or "exact"')
         # The special case in which an entire month is specified and not a specific date during it.
         if not re.search('[0-9]', match) and start.day == 1 and u'day' not in match:
             end = utils.end_of_month(seed_dt)
         DaterangeAtom.__init__(self, start, end, match, src_time)
     else:
         raise ValueError(u'CalendarDateRangeAtom cannot parse and intialized from given match value = '\
                 + unicode(match))
Example #3
0
 def match_function(nltext): return utils.safe_parsedatetime_first_nlp(nltext, src_time, ignore='time').get(u'match')
 matcher = SequentialMatcher(match_function, label=CalendarDaterangeAtom.TAG);
Example #4
0
 def match_function(nltext): return utils.safe_parsedatetime_first_nlp(nltext, src_time, ignore='time').get(u'match')
 def match_transformer(match): return CalendarDateRangeAtom(match, src_time, parse_type=parse_type)