vendor/bundle/ruby/1.8/gems/chronic-0.6.7/lib/chronic/chronic.rb
def pre_normalize(text)
      text = text.to_s.downcase
      text.gsub!(/['"\.]/, '')
      text.gsub!(/,/, ' ')
      text.gsub!(/\bsecond (of|day|month|hour|minute|second)\b/, '2nd \1')
      text = Numerizer.numerize(text)
      text.gsub!(/ \-(\d{4})\b/, ' tzminus\1')
      text.gsub!(/([\/\-\,\@])/) { ' ' + $1 + ' ' }
      text.gsub!(/(?:^|\s)0(\d+:\d+\s*pm?\b)/, '\1')
      text.gsub!(/\btoday\b/, 'this day')
      text.gsub!(/\btomm?orr?ow\b/, 'next day')
      text.gsub!(/\byesterday\b/, 'last day')
      text.gsub!(/\bnoon\b/, '12:00pm')
      text.gsub!(/\bmidnight\b/, '24:00')
      text.gsub!(/\bnow\b/, 'this second')
      text.gsub!(/\b(?:ago|before(?: now)?)\b/, 'past')
      text.gsub!(/\bthis (?:last|past)\b/, 'last')
      text.gsub!(/\b(?:in|during) the (morning)\b/, '\1')
      text.gsub!(/\b(?:in the|during the|at) (afternoon|evening|night)\b/, '\1')
      text.gsub!(/\btonight\b/, 'this night')
      text.gsub!(/\b\d+:?\d*[ap]\b/,'\0m')
      text.gsub!(/(\d)([ap]m|oclock)\b/, '\1 \2')
      text.gsub!(/\b(hence|after|from)\b/, 'future')
      text
    end
# Clean up the specified text ready for parsing
#
# Clean up the string by stripping unwanted characters, converting
# idioms to their canonical form, converting number words to numbers
# (three => 3), and converting ordinal words to numeric
# ordinals (third => 3rd)
#
# @example
#   Chronic.pre_normalize('first day in May')
#     #=> "1st day in may"
#
#   Chronic.pre_normalize('tomorrow after noon')
#     #=> "next day future 12:00"
#
#   Chronic.pre_normalize('one hundred and thirty six days from now')
#     #=> "136 days future this second"
#
# @param [String] text The string to normalize
# @return [String] A new string ready for Chronic to parse
Clean up the specified text ready for parsing
Clean up the string by stripping unwanted characters, converting
idioms to their canonical form, converting number words to numbers
(three => 3), and converting ordinal words to numeric
ordinals (third => 3rd)
Clean up the specified text ready for parsing Clean up the string by stripping unwanted characters converting idioms to their canonical form converting number words to numbers ( three = > 3 ) and converting ordinal words to numeric ordinals ( third = > 3rd )
def pre_normalize(text)
      text = text.to_s.downcase
      text.gsub!(/['"\.]/, '')
      text.gsub!(/,/, ' ')
      text.gsub!(/\bsecond (of|day|month|hour|minute|second)\b/, '2nd \1')
      text = Numerizer.numerize(text)
      text.gsub!(/ \-(\d{4})\b/, ' tzminus\1')
      text.gsub!(/([\/\-\,\@])/) { ' ' + $1 + ' ' }
      text.gsub!(/(?:^|\s)0(\d+:\d+\s*pm?\b)/, '\1')
      text.gsub!(/\btoday\b/, 'this day')
      text.gsub!(/\btomm?orr?ow\b/, 'next day')
      text.gsub!(/\byesterday\b/, 'last day')
      text.gsub!(/\bnoon\b/, '12:00pm')
      text.gsub!(/\bmidnight\b/, '24:00')
      text.gsub!(/\bnow\b/, 'this second')
      text.gsub!(/\b(?:ago|before(?: now)?)\b/, 'past')
      text.gsub!(/\bthis (?:last|past)\b/, 'last')
      text.gsub!(/\b(?:in|during) the (morning)\b/, '\1')
      text.gsub!(/\b(?:in the|during the|at) (afternoon|evening|night)\b/, '\1')
      text.gsub!(/\btonight\b/, 'this night')
      text.gsub!(/\b\d+:?\d*[ap]\b/,'\0m')
      text.gsub!(/(\d)([ap]m|oclock)\b/, '\1 \2')
      text.gsub!(/\b(hence|after|from)\b/, 'future')
      text
    end
def pre_normalize ( text ) text = text . to_s . downcase text . gsub! ( / ['" \. ] / , '' ) text . gsub! ( / , / , ' ' ) text . gsub! ( / \b second (of|day|month|hour|minute|second) \b / , '2nd \1' ) text = Numerizer . numerize ( text ) text . gsub! ( / \- ( \d {4}) \b / , ' tzminus\1' ) text . gsub! ( / ([ \/ \- \, \@ ]) / ) { ' ' + $1 + ' ' } text . gsub! ( / (?:^| \s )0( \d +: \d + \s *pm? \b ) / , '\1' ) text . gsub! ( / \b today \b / , 'this day' ) text . gsub! ( / \b tomm?orr?ow \b / , 'next day' ) text . gsub! ( / \b yesterday \b / , 'last day' ) text . gsub! ( / \b noon \b / , '12:00pm' ) text . gsub! ( / \b midnight \b / , '24:00' ) text . gsub! ( / \b now \b / , 'this second' ) text . gsub! ( / \b (?:ago|before(?: now)?) \b / , 'past' ) text . gsub! ( / \b this (?:last|past) \b / , 'last' ) text . gsub! ( / \b (?:in|during) the (morning) \b / , '\1' ) text . gsub! ( / \b (?:in the|during the|at) (afternoon|evening|night) \b / , '\1' ) text . gsub! ( / \b tonight \b / , 'this night' ) text . gsub! ( / \b \d +:? \d *[ap] \b / , '\0m' ) text . gsub! ( / ( \d )([ap]m|oclock) \b / , '\1 \2' ) text . gsub! ( / \b (hence|after|from) \b / , 'future' ) text end
Clean up the specified text ready for parsing
Clean up the string by stripping unwanted characters, converting
idioms to their canonical form, converting number words to numbers
(three => 3), and converting ordinal words to numeric
ordinals (third => 3rd)
Clean up the specified text ready for parsing Clean up the string by stripping unwanted characters converting idioms to their canonical form converting number words to numbers ( three = > 3 ) and converting ordinal words to numeric ordinals ( third = > 3rd )
A new string ready for Chronic to parse
A new string ready for Chronic to parse
String
text
text The string to normalize
text The string to normalize
example
Chronic.pre_normalize('first day in May') #=> "1st day in may" Chronic.pre_normalize('tomorrow after noon') #=> "next day future 12:00" Chronic.pre_normalize('one hundred and thirty six days from now') #=> "136 days future this second"
Chronic . pre_normalize ( ' first day in May ' ) # = > " 1st day in may " Chronic . pre_normalize ( ' tomorrow after noon ' ) # = > " next day future 12 : 00 " Chronic . pre_normalize ( ' one hundred and thirty six days from now ' ) # = > " 136 days future this second "