Class: SoftParser

Inherits:
Cogibara::OperatorBase show all
Defined in:
lib/cogibara/operators/soft_parser.rb

Instance Attribute Summary

Attributes inherited from Cogibara::OperatorBase

#clientID, #message_structure, #message_text, #operator_config

Instance Method Summary collapse

Methods inherited from Cogibara::OperatorBase

#confirm, #initialize, #process_file, #receive_message, #say

Constructor Details

This class inherits a constructor from Cogibara::OperatorBase

Instance Method Details

#initialize_operatorObject



4
5
6
7
# 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) ⇒ Object



9
10
11
# 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) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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