Class: Clarification::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient


6
7
8
9
10
11
12
# File 'lib/clarification/client.rb', line 6

def initialize
  raise "No Configuration Found." if Clarification.configuration.nil?
  @active_models = convert_config_models_to_model_hash(Clarification.configuration.default_public_models)
  @search = Search.new
  @train = Train.new
  @predict = Predict.new(@active_models)
end

Instance Attribute Details

#active_modelsObject (readonly)

Returns the value of attribute active_models


4
5
6
# File 'lib/clarification/client.rb', line 4

def active_models
  @active_models
end

#predictObject (readonly)

Returns the value of attribute predict


4
5
6
# File 'lib/clarification/client.rb', line 4

def predict
  @predict
end

#searchObject (readonly)

Returns the value of attribute search


4
5
6
# File 'lib/clarification/client.rb', line 4

def search
  @search
end

#trainObject (readonly)

Returns the value of attribute train


4
5
6
# File 'lib/clarification/client.rb', line 4

def train
  @train
end

Instance Method Details

#set_active_models(models) ⇒ Object


47
48
49
50
# File 'lib/clarification/client.rb', line 47

def set_active_models(models)
  @active_models = models
  @predict = Predict.new(@active_models)
end

#set_active_models_by_public_key(model_name_array) ⇒ Predict

A convenience method to quickly set public models as the active models of a client.

Examples:

client.set_active_models_by_public_key([:food, :general])

20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/clarification/client.rb', line 20

def set_active_models_by_public_key(model_name_array)
  if model_name_array.class != Array
    raise "Clarification expects an array of model keys."
  end
  
  name_check = model_name_array - Clarification::PUBLIC_MODELS.keys
  unless name_check.empty?
    raise "#{name_check} models are not recognized.  Check Clarification::PUBLIC_MODELS"
  end

  @active_models = convert_config_models_to_model_hash(model_name_array)
  @predict = Predict.new(@active_models)
end

#set_active_models_from_hash(model_hash) ⇒ Array

Set the models that the client will process against.


38
39
40
41
42
43
44
45
# File 'lib/clarification/client.rb', line 38

def set_active_models_from_hash(model_hash)
  models = []
  model_hash.each do |key, value|
    models << Model.new(name: key, id: value)
  end
  @active_models = models
  @predict = Predict.new(@active_models)
end