Class: MachineClassifier::Client

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

Constant Summary collapse

HEADERS =
{'Content-Type' => 'application/json'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration

Returns:

  • (Object)

    the current value of configuration



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

def configuration
  @configuration
end

Instance Method Details

#call(text) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/machine_classifier/client.rb', line 7

def call(text)
  authorize!

  predict       = prediction_api.trainedmodels.predict
  body          = {input: {csvInstance: [text]}}.to_json

  result = api_client.execute(
    api_method: predict,
    parameters: {'id' => model_id, 'project' => project_id},
    body:       body,
    headers:    HEADERS
  )
  data = JSON.parse(result.body)
  Result.new(data)
end

#categoriesObject



23
24
25
26
# File 'lib/machine_classifier/client.rb', line 23

def categories
  output = ['dataDescription']['outputFeature']['text']
  output.map { |category| category['value'] }
end

#confusionObject



28
29
30
# File 'lib/machine_classifier/client.rb', line 28

def confusion
  ['modelDescription']['confusionMatrix']
end

#metadataObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/machine_classifier/client.rb', line 32

def 
  return @metadata if @metadata

  authorize!

  analyze = prediction_api.trainedmodels.analyze

  result = api_client.execute(
    api_method: analyze,
    parameters: {'id' => model_id, 'project' => project_id},
    headers:    HEADERS
  )
  @metadata = JSON.parse(result.body)
end