class TinyClassifier::Command::Retrain
Public Class Methods
new(argv=[])
click to toggle source
Calls superclass method
TinyClassifier::Command::Base::new
# 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
Public Instance Methods
run()
click to toggle source
Calls superclass method
TinyClassifier::Command::Base::run
# 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
Private Instance Methods
prepare_categories()
click to toggle source
# File lib/tiny-classifier/command/retrain.rb, line 44 def prepare_categories begin @wrong_category = prepare_category(@wrong_category) rescue StandardError => error case error when NoCategory raise NoWrongCategory.new when InvalidCategory raise InvalidWrongCategory.new(@wrong_category, @categories.all) else raise error end end begin @correct_category = prepare_category(@correct_category) rescue StandardError => error case error when NoCategory raise NoCorrectCategory.new when InvalidCategory raise InvalidCorrectCategory.new(@correct_category, @categories.all) else raise error end end log("training as: #{@wrong_category} => #{@correct_category}") end