Class: TinyClassifier::Command::Retrain

Inherits:
Base
  • Object
show all
Defined in:
lib/tiny-classifier/command/retrain.rb

Instance Attribute Summary

Attributes inherited from Base

#classifier, #tokenizer

Instance Method Summary collapse

Methods inherited from Base

#data_file_name, #data_file_path, #parse_command_line_options, run

Constructor Details

#initialize(argv = []) ⇒ Retrain

Returns a new instance of Retrain.



21
22
23
24
25
26
27
# File 'lib/tiny-classifier/command/retrain.rb', line 21

def initialize(argv=[])
  super
  option_parser.banner += " WRONG CORRECT"
  *categories = parse_command_line_options(argv)
  @wrong_category = categories.shift
  @correct_category = categories.shift
end

Instance Method Details

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tiny-classifier/command/retrain.rb', line 29

def run
  super
  prepare_categories
  raise NoEffectiveInput.new if input.empty?
  raise NoTrainingData.new(data_file_path) unless data_file_path.exist?

  classifier.untrain(@wrong_category, input)
  classifier.train(@correct_category, input)
  save
  true
rescue StandardError => error
  handle_error(error)
end