Class: Stamina::Command::ClassifyCommand
- Inherits:
-
StaminaCommand
- Object
- StaminaCommand
- Stamina::Command::ClassifyCommand
- Defined in:
- lib/stamina/command/classify_command.rb
Overview
Implementation of the classify command line tool
Instance Attribute Summary
Attributes inherited from StaminaCommand
Instance Method Summary collapse
-
#automaton_file=(file) ⇒ Object
Sets the automaton file.
-
#initialize ⇒ ClassifyCommand
constructor
Creates a score command instance.
-
#main(argv) ⇒ Object
Executes the command.
-
#options ⇒ Object
Installs additional options.
-
#sample_file=(file) ⇒ Object
Sets the sample file.
Methods inherited from StaminaCommand
#assert_readable_file, #assert_writable_file, #parse, #show_usage
Constructor Details
#initialize ⇒ ClassifyCommand
Creates a score command instance
10 11 12 13 |
# File 'lib/stamina/command/classify_command.rb', line 10 def initialize super("classify", "[options] sample.adl automaton.adl", "Classify a sample using an automaton, both expressed in ADL") end |
Instance Method Details
#automaton_file=(file) ⇒ Object
Sets the automaton file
35 36 37 38 39 40 |
# File 'lib/stamina/command/classify_command.rb', line 35 def automaton_file=(file) assert_readable_file(file) @automaton = Stamina::ADL.parse_automaton_file(file) rescue Stamina::ADL::ParseError raise ArgumentError, "#{file} is not a valid ADL automaton file" end |
#main(argv) ⇒ Object
Executes the command
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stamina/command/classify_command.rb', line 43 def main(argv) parse(argv, :sample_file, :automaton_file) if @output_file File.open(@output_file, 'w') do |file| file << @automaton.signature(@sample) << "\n" end else STDOUT << @automaton.signature(@sample) << "\n" end end |
#options ⇒ Object
Installs additional options
16 17 18 19 20 21 22 23 24 |
# File 'lib/stamina/command/classify_command.rb', line 16 def super do |opt| opt.on("-o", "--output=OUTPUT", "Flush classification signature in output file") do |value| assert_writable_file(value) @output_file = value end end end |
#sample_file=(file) ⇒ Object
Sets the sample file
27 28 29 30 31 32 |
# File 'lib/stamina/command/classify_command.rb', line 27 def sample_file=(file) assert_readable_file(file) @sample = Stamina::ADL.parse_sample_file(file) rescue Stamina::ADL::ParseError raise ArgumentError, "#{file} is not a valid ADL sample file" end |