Class: Classifier::CLI
Constant Summary collapse
- CLASSIFIER_TYPES =
{ 'bayes' => :bayes, 'lsi' => :lsi, 'knn' => :knn, 'lr' => :logistic_regression, 'logistic_regression' => :logistic_regression }.freeze
- DEFAULT_REGISTRY =
: String
ENV.fetch('CLASSIFIER_REGISTRY', 'cardmagic/classifier-models')
- CACHE_DIR =
: String
ENV.fetch('CLASSIFIER_CACHE', File.('~/.classifier'))
Instance Method Summary collapse
-
#initialize(args, stdin: nil) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(args, stdin: nil) ⇒ CLI
Returns a new instance of CLI.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/classifier/cli.rb', line 31 def initialize(args, stdin: nil) @args = args.dup @stdin = stdin @options = { model: ENV.fetch('CLASSIFIER_MODEL', './classifier.json'), type: ENV.fetch('CLASSIFIER_TYPE', 'bayes'), probabilities: false, quiet: false, count: 10, k: 5, weighted: false, learning_rate: nil, regularization: nil, max_iterations: nil, remote: nil, output_path: nil } @output = [] #: Array[String] @error = [] #: Array[String] @exit_code = 0 end |
Instance Method Details
#run ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/classifier/cli.rb', line 53 def run execute_command { output: @output.join("\n"), error: @error.join("\n"), exit_code: @exit_code } rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::InvalidArgument => e @error << "Error: #{e.}" @exit_code = 2 { output: @output.join("\n"), error: @error.join("\n"), exit_code: @exit_code } rescue StandardError => e @error << "Error: #{e.}" @exit_code = 1 { output: @output.join("\n"), error: @error.join("\n"), exit_code: @exit_code } end |