Class: Indico::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/indico.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection, config = nil) ⇒ Collection

Returns a new instance of Collection.



175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/indico.rb', line 175

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

Instance Method Details

#_api_handler(data, api, config = nil, method = 'predict') ⇒ Object



188
189
190
191
192
193
194
# File 'lib/indico.rb', line 188

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) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/indico.rb', line 196

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) ⇒ Object



262
263
264
265
266
267
268
269
# File 'lib/indico.rb', line 262

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) ⇒ Object



240
241
242
# File 'lib/indico.rb', line 240

def clear(config = nil)
  _api_handler(nil, 'custom', config, 'clear_collection')
end

#deauthorize(email, config = nil) ⇒ Object



271
272
273
274
275
276
277
# File 'lib/indico.rb', line 271

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) ⇒ Object



258
259
260
# File 'lib/indico.rb', line 258

def deregister(config = nil)
  _api_handler(nil, 'custom', config, 'deregister')
end

#info(config = nil) ⇒ Object



226
227
228
# File 'lib/indico.rb', line 226

def info(config = nil)
  _api_handler(nil, 'custom', config, 'info')
end

#predict(data, config = nil) ⇒ Object



230
231
232
233
# File 'lib/indico.rb', line 230

def predict(data, config = nil)
  data = Indico::preprocess(data, 512, true)
  _api_handler(data, 'custom', config, 'predict')
end

#register(config = nil) ⇒ Object



254
255
256
# File 'lib/indico.rb', line 254

def register(config = nil)
  _api_handler(nil, 'custom', config, 'register')
end

#remove_example(data, config = nil) ⇒ Object



235
236
237
238
# File 'lib/indico.rb', line 235

def remove_example(data, config = nil)
  data = Indico::preprocess(data, 512, true)
  _api_handler(data, 'custom', config, 'remove_example')
end

#rename(name, config = nil) ⇒ Object



244
245
246
247
248
249
250
251
252
# File 'lib/indico.rb', line 244

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) ⇒ Object



209
210
211
# File 'lib/indico.rb', line 209

def train(config = nil)
  _api_handler(nil, 'custom', config, 'train')
end

#wait(interval = 1) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/indico.rb', line 213

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