class SoftParser
Public Instance Methods
initialize_operator()
click to toggle source
# File lib/cogibara/operators/soft_parser.rb, line 4 def initialize_operator @api_key = self.operator_config["API_KEY"] @client = MaluubaNapi::Client.new(@api_key) end
normalize(message, type)
click to toggle source
# File lib/cogibara/operators/soft_parser.rb, line 9 def normalize(message, type) @client.normalize phrase: message, type: type, timezone:"CST" end
normalize_response!(msg, response)
click to toggle source
# File lib/cogibara/operators/soft_parser.rb, line 13 def normalize_response!(msg, response) if response[:entities] if response[:entities][:daterange] n = normalize(msg, "daterange")[:entities][:daterange] response[:entities][:daterange] = n if n end if response[:entities][:timerange] n = normalize(msg, "timerange")[:entities][:timerange] response[:entities][:timerange] = n if n end if response[:entities][:time] n = normalize(msg, "time")[:entities][:time] response[:entities][:time] = n if n end end end
process(message)
click to toggle source
# File lib/cogibara/operators/soft_parser.rb, line 30 def process(message) response = @client.interpret phrase: message.text normalize_response!(message.text, response) ## Should normalize times and do something with them # time_categories = [:REMINDER, :ALARM, :TIMER] # timerange_categories = [:TIMER] # date_categories = [:CALENDAR] # # if time_categories.includes? response[:category] # normalized = @client.normalize phrase: message, type: 'time', timezone: 'CST' # elsif timerange_categories.includes? response[:category] # normalized = @client.normalize phrase: message, type: 'timerange', timezone: 'CST' # elsif date_categories.includes? response[:category] # normalized = @client.normalize phrase: message, type: 'daterange', timezone: 'CST' # end # response end