Class: TinyClassifier::Command::Untrain

Inherits:
Base
  • Object
show all
Defined in:
lib/tiny-classifier/command/untrain.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 = []) ⇒ Untrain

Returns a new instance of Untrain.



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

def initialize(argv=[])
  super
  option_parser.banner += " CATEGORY"
  *categories = parse_command_line_options(argv)
  @category = categories.first
end

Instance Method Details

#runObject



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

def run
  super
  @category = prepare_category(@category)
  log("untraining as: #{@category}")
  raise NoEffectiveInput.new if input.empty?
  raise NoTrainingData.new(data_file_path) unless data_file_path.exist?

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