class FrequencyTagger
Public Class Methods
new()
click to toggle source
# File lib/list_taggers/frequency_tagger.rb, line 19 def initialize @name = 'freq' @list = [/q\.?\s?(?:a\.?m\.?|morning)/i, /q\.?\s?(?:p\.?m\.?|afternoon)/i, /q\.?\s?h\.?(?:s\.?)?/i, /(?:at\s*)?night(?:ly)?/i, /(?:at\s*)bedtime/i, /(?:at\s*)midday/i, /in the morning/i, /immediately/i, /hs/i, /(?x)(?:(?:every|q\.?)\s*(?:\d\-)? (?:2|3|4|5|6|7|8|9|10|11|12|24|36|48|72| two|four|six|eight|twelve)(?:(?:-|\s+to\s+) (?:2|3|4|5|6|7|8|9|10|11|12|24|36|48|72| two|four|six|eight|twelve))?\s* (?:h(?:rs?|(?:ours?))?\.?))/i, /q\.?\s?d(?:\.|ay)?/i, /q-day/i, /(?x)(?:(?:every|each)\s*\d?\s* (?:day|night|week|morning|afternoon|evening))/i, /(?:(?:once|twice)\s+(?:(?:a|per)\s+(?:day|week|night|month)))/i, /(?x)(?:(?:(?:(?:\d\-)?(?:two|three|four|five|\d) \s+times?\s+)|(once|twice)\s+)?(?:daily|weekly|hourly))/i, /qod/i, /every other day/i, /[bqt]\.i\.d\./i, /[bqt]idh?\b/i, /(?x)(?:(?:\d\-?)?(?:one|two|three|four|five|\d)\s+ (?:times?|days?|nights?)?\s? (?:a|per|\/)\s?(?:day|week|night|month))/i, /(?:once|twice|(?:(?:\d+|one|two|three|four|five)\s*times))?monthly/i, /(?:as|when)\s+needed/i, /p\.?r\.?n\.?/i] end
Public Instance Methods
normalize(freq)
click to toggle source
# File lib/list_taggers/frequency_tagger.rb, line 55 def normalize(freq) numwords = {"one"=>"1","two"=>"2","three"=>"3","four"=>"4","five"=>"5","six"=>"6","seven"=>"7","eight"=>"8"} case freq when /prn.?/i, /as needed/i return :prn when /qod/i return :qod when /(\d+(-\d+)?|[a-z]+) times? ((a|per) )?(day|week|daily|weekly)/i return :range if $2 num, unit = $1, $5.downcase subs = {"1" => "q", "2" => "bi", "3" => "ti", "4" => "qi"} num = numwords[num] || num num = subs[num] || num+"i" return (num + unit[0]).to_sym when /(once |twice )(a )?(day|week|daily|weekly)/i num, unit = $1, ($3).downcase return ("bi"+unit[0]).to_sym if ($1).downcase == "twice " return ("q"+unit[0]).to_sym when /daily/i #we've checked other contexts for daily already return :qd when /(q|every|each) ?(\d+(-\d+)?|[a-z]+)? ?(days?|ho?u?rs?|morning|night)/i return :qod if $2 && ["other","two","2"].include?(($2).downcase) && $4 == "day" return :range if $3 subs = {"morning" => "am", "afternoon" => "pm", "night" => "hs"} num, unit = $2, $4 num = numwords[num] || num unit = subs[unit.downcase] || unit[0].downcase return ("q" + num.to_s + unit).to_sym when /q(\d+(-\d+)?)?(am|d|hs|pm|w|h)/i return :range if $2 return $&.downcase.to_sym when /(b|t|q|(\d+(-\d+)?))i(w|h|d)/i return :range if $3 return $&.downcase.to_sym end end