class Sapcai::Response

Attributes

act[R]
entities[R]
intents[R]
language[R]
processing_language[R]
raw[R]
sentiment[R]
source[R]
status[R]
timestamp[R]
type[R]
uuid[R]
version[R]

Public Class Methods

new(response) click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 23
def initialize(response)
  @raw = JSON.dump(response)
  response = response['results']

  @uuid                = response['uuid']
  @source              = response['source']
  @intents             = response['intents'].map{ |i| Intent.new(i) }
  @act                 = response['act']
  @type                = response['type']
  @sentiment           = response['sentiment']
  @entities            = response['entities'].flat_map{ |n, e| e.map{ |ee| Entity.new(n, ee) } }
  @language            = response['language']
  @processing_language = response['processing_language']
  @version             = response['version']
  @timestamp           = response['timestamp']
  @status              = response['status']
end

Public Instance Methods

abbreviation?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 75
def abbreviation?
  !@type.index(Utils::TYPE_ABBREVIATION).nil?
end
all(name) click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 53
def all(name)
  @entities.select do |entity|
    entity.name.casecmp(name.to_s).zero?
  end
end
assert?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 59
def assert?
  @act == Utils::ACT_ASSERT
end
command?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 63
def command?
  @act == Utils::ACT_COMMAND
end
description?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 83
def description?
  !@type.index(Utils::TYPE_DESCRIPTION).nil?
end
entity?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 79
def entity?
  !@type.index(Utils::TYPE_ENTITY).nil?
end
get(name) click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 45
def get(name)
  @entities.each do |entity|
    return entity if entity.name.casecmp(name.to_s).zero?
  end

  nil
end
human?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 87
def human?
  !@type.index(Utils::TYPE_HUMAN).nil?
end
intent() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 41
def intent
  @intents.any? ? @intents.first : nil
end
location?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 91
def location?
  !@type.index(Utils::TYPE_LOCATION).nil?
end
negative?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 111
def negative?
  @sentiment == Utils::SENTIMENT_NEGATIVE
end
neutral?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 107
def neutral?
  @sentiment == Utils::SENTIMENT_NEUTRAL
end
number?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 95
def number?
  !@type.index(Utils::TYPE_NUMBER).nil?
end
positive?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 103
def positive?
  @sentiment == Utils::SENTIMENT_POSITIVE
end
vnegative?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 115
def vnegative?
  @sentiment == Utils::SENTIMENT_VNEGATIVE
end
vpositive?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 99
def vpositive?
  @sentiment == Utils::SENTIMENT_VPOSITIVE
end
wh_query?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 67
def wh_query?
  @act == Utils::ACT_WH_QUERY
end
yn_query?() click to toggle source
# File lib/sapcai/apis/request/models/response.rb, line 71
def yn_query?
  @act == Utils::ACT_YN_QUERY
end