class MachineClassifier::Client
Constants
- HEADERS
Public Instance Methods
call(text)
click to toggle source
# 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
categories()
click to toggle source
# File lib/machine_classifier/client.rb, line 23 def categories output = metadata['dataDescription']['outputFeature']['text'] output.map { |category| category['value'] } end
confusion()
click to toggle source
# File lib/machine_classifier/client.rb, line 28 def confusion metadata['modelDescription']['confusionMatrix'] end
metadata()
click to toggle source
# File lib/machine_classifier/client.rb, line 32 def metadata 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
Private Instance Methods
api_client()
click to toggle source
# File lib/machine_classifier/client.rb, line 62 def api_client @api_client ||= Google::APIClient.new( application_name: configuration.application_name, application_version: configuration.application_version, ) end
model_id()
click to toggle source
# File lib/machine_classifier/client.rb, line 73 def model_id configuration.model end
prediction_api()
click to toggle source
# File lib/machine_classifier/client.rb, line 54 def prediction_api api_client.discovered_api('prediction', configuration.api_version) end
project_id()
click to toggle source
# File lib/machine_classifier/client.rb, line 69 def project_id configuration.project end