class Indico::Collection

Public Class Methods

new(collection, config = nil) click to toggle source
# File lib/indico.rb, line 181
def initialize(collection, config = nil)
  if collection.kind_of?(String)
    @keywords = {
      "shared" => config.nil? ? nil : config["shared"],
      "domain" => config.nil? ? nil : config["domain"],
      "collection" => collection
    }

  else
    raise TypeError, "Collection must be initialized with a String name"
  end
end

Public Instance Methods

_api_handler(data, api, config = nil, method = 'predict') click to toggle source
# File lib/indico.rb, line 194
def _api_handler(data, api, config = nil, method = 'predict')
  if config.nil?
    config = Hash.new()
  end
  config = @keywords.merge(config)
  Indico.api_handler(data, api, config, method)
end
add_data(data, config = nil) click to toggle source
# File lib/indico.rb, line 202
def add_data(data, config = nil)

  is_batch = data[0].kind_of?(Array)
  if is_batch
    x, y = data.transpose
    x = Indico::preprocess(x, 512, true)
    data = x.zip(y)
  else
    data[0] = Indico::preprocess(data[0], 512, true)
  end
  _api_handler(data, 'custom', config, 'add_data')
end
authorize(email, permission_type = 'read', config = nil) click to toggle source
# File lib/indico.rb, line 268
def authorize(email, permission_type = 'read', config = nil)
  if config.nil?
    config = Hash.new()
  end
  config[:email] = email
  config[:permission_type] = permission_type
  _api_handler(nil, 'custom', config, 'authorize')
end
clear(config = nil) click to toggle source
# File lib/indico.rb, line 246
def clear(config = nil)
  _api_handler(nil, 'custom', config, 'clear_collection')
end
deauthorize(email, config = nil) click to toggle source
# File lib/indico.rb, line 277
def deauthorize(email, config = nil)
  if config.nil?
    config = Hash.new()
  end
  config[:email] = email
  _api_handler(nil, 'custom', config, 'deauthorize')
end
deregister(config = nil) click to toggle source
# File lib/indico.rb, line 264
def deregister(config = nil)
  _api_handler(nil, 'custom', config, 'deregister')
end
info(config = nil) click to toggle source
# File lib/indico.rb, line 232
def info(config = nil)
  _api_handler(nil, 'custom', config, 'info')
end
predict(data, config = nil) click to toggle source
# File lib/indico.rb, line 236
def predict(data, config = nil)
  data = Indico::preprocess(data, 512, true)
  _api_handler(data, 'custom', config, 'predict')
end
register(config = nil) click to toggle source
# File lib/indico.rb, line 260
def register(config = nil)
  _api_handler(nil, 'custom', config, 'register')
end
remove_example(data, config = nil) click to toggle source
# File lib/indico.rb, line 241
def remove_example(data, config = nil)
  data = Indico::preprocess(data, 512, true)
  _api_handler(data, 'custom', config, 'remove_example')
end
rename(name, config = nil) click to toggle source
# File lib/indico.rb, line 250
def rename(name, config = nil)
  if config.nil?
    config = Hash.new()
  end
  config[:name] = name
  result = _api_handler(nil, 'custom', config, 'rename')
  @keywords['collection'] = name
  return result
end
train(config = nil) click to toggle source
# File lib/indico.rb, line 215
def train(config = nil)
  _api_handler(nil, 'custom', config, 'train')
end
wait(interval = 1) click to toggle source
# File lib/indico.rb, line 219
def wait(interval = 1)
  while true do
    status = info()['status']
    if status == "ready"
      break
    elsif status != "training"
      raise IndicoError, "Collection training ended with failure: " + status
      break
    end
    sleep(interval)
  end
end