Class: WitBot::Outcome

Inherits:
Object
  • Object
show all
Defined in:
lib/wit_bot/models/outcome.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, raw, i = 0) ⇒ Outcome

Returns a new instance of Outcome.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wit_bot/models/outcome.rb', line 5

def initialize(message, raw, i=0)
  @message = message
  @raw = raw.with_indifferent_access

  @confidence = @raw[:confidence]
  @_text = @raw[:_text]

  @intent = WitModel::Intent.find raw[:intent]
  @entities = @raw[:entities].each.inject({}) do |entities, entity_info|
    role, all = entity_info
    all = all.map { |data| WitModel::Entity.find(data[:entity], create: false).model role, data }

    data = all.shift
    data.others = all

    entities[role] = data
    entities
  end.with_indifferent_access

  raise LowConfidenceError self if i == 0 && low_confidence?
end

Instance Attribute Details

#_textObject (readonly)

Returns the value of attribute _text.



3
4
5
# File 'lib/wit_bot/models/outcome.rb', line 3

def _text
  @_text
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



3
4
5
# File 'lib/wit_bot/models/outcome.rb', line 3

def confidence
  @confidence
end

#entitiesObject (readonly)

Returns the value of attribute entities.



3
4
5
# File 'lib/wit_bot/models/outcome.rb', line 3

def entities
  @entities
end

#intentObject (readonly)

Returns the value of attribute intent.



3
4
5
# File 'lib/wit_bot/models/outcome.rb', line 3

def intent
  @intent
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/wit_bot/models/outcome.rb', line 3

def message
  @message
end

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'lib/wit_bot/models/outcome.rb', line 3

def raw
  @raw
end

Instance Method Details

#low_confidence?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/wit_bot/models/outcome.rb', line 27

def low_confidence?
  @confidence < WitBot.config.minimum_confidence
end