Method: BotFramework::Dialogs::LuisRecognizer#recognize

Defined in:
lib/bot_framework/dialogs/luis_recognizer.rb

#recognize(context) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bot_framework/dialogs/luis_recognizer.rb', line 8

def recognize(context)
  result = { score: 0.0, intent: nil }
  if context && context[:message] && context[:message][:text]
    utterance = context[:message][:text]
    locale = context[:locale] || '*'
    model = @models[locale] || @models['*']
    if model
      LuisRecognizer.recognize(utterance, model) do |error, intents, entities|
        if error
          yield 'Error', nil
        else
          result[:intents] = intents
          result[:entities] = entities

          top = intents.max { |intent| intent[score] }
          if top
            result[:score] = top[:score]
            result[:intent] = top[:intent]
            case top[:intent].downcase
            when 'builtin.intent.none'
            when 'none'
              result[:score] = 0.1
            end
          end
          yield nil, result
        end
        yield nil, result
      end
    else
      yield StandardError.new("Luis model not found for locale #{locale}"), nil
    end
  else
    yield nil, result
  end
end