Class: TinyClassifier::Command::Classify

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

Returns a new instance of Classify.



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

def initialize(argv=[])
  super
  parse_command_line_options(argv)
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tiny-classifier/command/classify.rb', line 26

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

  category = classifier.classify(input)
  $stdout.puts(category.downcase)
  true
rescue StandardError => error
  handle_error(error)
end