44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/bot_framework/dialogs/luis_recognizer.rb', line 44
def self.recognize(utterance, model_uri)
uri = model_uri.strip
uri += '&q=' unless uri.end_with? '&q='
uri += URI.encode_www_form_component(utterance || '')
result = JSON.parse HTTParty.get(uri).body
result = result.each_with_object({}) { |(k, v), temp| temp[k.to_sym] = v; temp }
result[:intents] ||= []
result[:entities] ||= []
if result[:topScoringIntent] && result[:intents].empty?
result[:intents] << result[:topScoringIntent]
end
if result[:intents].length == 1 && (result[:intents].first[:score].is_a? Numeric)
result[:intents].first[:score] = 1.0
end
result[:intents].map! do |intent|
intent.each_with_object({}) { |(k, v), temp| temp[k.to_sym] = v; temp }
end
result[:entities].map! do |entity|
entity.each_with_object({}) { |(k, v), temp| temp[k.to_sym] = v; temp }
end
yield nil, result[:intents], result[:entities]
end
|