Class: Indico::Collection
- Inherits:
-
Object
- Object
- Indico::Collection
- Defined in:
- lib/indico.rb
Instance Method Summary collapse
- #_api_handler(data, api, config = nil, method = 'predict') ⇒ Object
- #add_data(data, config = nil) ⇒ Object
- #authorize(email, permission_type = 'read', config = nil) ⇒ Object
- #clear(config = nil) ⇒ Object
- #deauthorize(email, config = nil) ⇒ Object
- #deregister(config = nil) ⇒ Object
- #info(config = nil) ⇒ Object
-
#initialize(collection, config = nil) ⇒ Collection
constructor
A new instance of Collection.
- #predict(data, config = nil) ⇒ Object
- #register(config = nil) ⇒ Object
- #remove_example(data, config = nil) ⇒ Object
- #rename(name, config = nil) ⇒ Object
- #train(config = nil) ⇒ Object
- #wait(interval = 1) ⇒ Object
Constructor Details
#initialize(collection, config = nil) ⇒ Collection
Returns a new instance of Collection.
181 182 183 184 185 186 187 188 189 190 191 192 |
# 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 |
Instance Method Details
#_api_handler(data, api, config = nil, method = 'predict') ⇒ Object
194 195 196 197 198 199 200 |
# 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) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 |
# 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) ⇒ Object
268 269 270 271 272 273 274 275 |
# File 'lib/indico.rb', line 268 def (email, = 'read', config = nil) if config.nil? config = Hash.new() end config[:email] = email config[:permission_type] = _api_handler(nil, 'custom', config, 'authorize') end |
#clear(config = nil) ⇒ Object
246 247 248 |
# File 'lib/indico.rb', line 246 def clear(config = nil) _api_handler(nil, 'custom', config, 'clear_collection') end |
#deauthorize(email, config = nil) ⇒ Object
277 278 279 280 281 282 283 |
# File 'lib/indico.rb', line 277 def (email, config = nil) if config.nil? config = Hash.new() end config[:email] = email _api_handler(nil, 'custom', config, 'deauthorize') end |
#deregister(config = nil) ⇒ Object
264 265 266 |
# File 'lib/indico.rb', line 264 def deregister(config = nil) _api_handler(nil, 'custom', config, 'deregister') end |
#info(config = nil) ⇒ Object
232 233 234 |
# File 'lib/indico.rb', line 232 def info(config = nil) _api_handler(nil, 'custom', config, 'info') end |
#predict(data, config = nil) ⇒ Object
236 237 238 239 |
# 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) ⇒ Object
260 261 262 |
# File 'lib/indico.rb', line 260 def register(config = nil) _api_handler(nil, 'custom', config, 'register') end |
#remove_example(data, config = nil) ⇒ Object
241 242 243 244 |
# 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) ⇒ Object
250 251 252 253 254 255 256 257 258 |
# 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) ⇒ Object
215 216 217 |
# File 'lib/indico.rb', line 215 def train(config = nil) _api_handler(nil, 'custom', config, 'train') end |
#wait(interval = 1) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 |
# 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 |