Class: TinyClassifier::Trainer

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

Direct Known Subclasses

Untrainer

Instance Attribute Summary

Attributes inherited from Base

#tokenizer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#classifier, #parse_command_line_options

Constructor Details

#initializeTrainer

Returns a new instance of Trainer.



29
30
31
32
# File 'lib/tiny-classifier/trainer.rb', line 29

def initialize
  super
  option_parser.banner += " LABEL"
end

Class Method Details

.run(argv = nil) ⇒ Object



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

def run(argv=nil)
  argv ||= ARGV.dup
  trainer = new
  *labels = trainer.parse_command_line_options(argv)
  trainer.run(label: labels.first)
end

Instance Method Details

#run(params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tiny-classifier/trainer.rb', line 34

def run(params)
  @label = params[:label]
  prepare_label
  if input.empty?
    STDERR.puts("Error: No effective input.")
    false
  else
    classifier.send("train_#{@label}", input)
    save
    true
  end
end