Class: Stamina::Command::RPNICommand

Inherits:
StaminaCommand show all
Defined in:
lib/stamina/command/rpni_command.rb

Overview

Implementation of the rpni command line tool

Instance Attribute Summary

Attributes inherited from StaminaCommand

#description, #name, #usage

Instance Method Summary collapse

Methods inherited from StaminaCommand

#assert_readable_file, #assert_writable_file, #parse, #show_usage

Constructor Details

#initializeRPNICommand

Creates a score command instance



10
11
12
13
14
# File 'lib/stamina/command/rpni_command.rb', line 10

def initialize
  super("rpni", "[options] sample.adl",
        "Executes RPNI (Regular Positive and Negative Inference) on a ADL sample and\n"\
        "flushes the induced DFA on the standard output in ADL format as well")
end

Instance Method Details

#main(argv) ⇒ Object

Executes the command



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/stamina/command/rpni_command.rb', line 40

def main(argv)
  parse(argv, :sample_file)
  t1 = Time.now
  dfa = Stamina::Induction::RPNI.execute(@sample, {:verbose => @verbose})
  t2 = Time.now
  if @output_file 
    File.open(@output_file, 'w') do |file|
      Stamina::ADL.print_automaton(dfa, file)
    end
  else
    Stamina::ADL.print_automaton(dfa, STDOUT)
  end          
  puts "Executed in #{t2-t1} sec" if @verbose
end

#optionsObject

Installs additional options



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stamina/command/rpni_command.rb', line 17

def options
  super do |opt|
    opt.on("-v", "--verbose", "Verbose mode") do
      @verbose = true
    end
    opt.on("-o", "--output=OUTPUT",
           "Flush induced DFA in output file") do |value|
      assert_writable_file(value)
      @output_file = value
    end
  end
end

#sample_file=(file) ⇒ Object

Sets the sample file



31
32
33
34
35
36
37
# File 'lib/stamina/command/rpni_command.rb', line 31

def sample_file=(file)
  assert_readable_file(file)
  puts "Parsing sample and building PTA" if @verbose
  @sample = Stamina::ADL.parse_sample_file(file)
rescue Stamina::ADL::ParseError
  raise ArgumentError, "#{file} is not a valid ADL sample file"
end