Class: SoftParser
Instance Attribute Summary
#clientID, #message_structure, #message_text, #operator_config
Instance Method Summary
collapse
#confirm, #initialize, #process_file, #receive_message, #say
Instance Method Details
#initialize_operator ⇒ Object
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)
response
end
|