Module: NekonekoGen

Defined in:
lib/nekoneko_gen.rb,
lib/nekoneko_gen/pa.rb,
lib/nekoneko_gen/mlp.rb,
lib/nekoneko_gen/arow.rb,
lib/nekoneko_gen/version.rb,
lib/nekoneko_gen/classifier.rb,
lib/nekoneko_gen/linear_classifier.rb,
lib/nekoneko_gen/classifier_factory.rb,
lib/nekoneko_gen/text_classifier_generator.rb

Defined Under Namespace

Modules: ClassifierFactory Classes: Arow, Classifier, LinearClassifier, MLP, PA, TextClassifierGenerator

Constant Summary collapse

VERSION =
"0.4.2"

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/nekoneko_gen.rb', line 8

def self.run(argv)
  iteration = nil
  rubyfile = nil
  quiet = false
  
  $stdout.sync = true
  method = nil
  c = nil
  opt = OptionParser.new do |o|
    o.on('-n NAME', 'new classifier name') do |v|
      rubyfile = File.join(File.dirname(v), File.basename(v, ".*") + ".rb")
      FileUtils.touch(rubyfile)
    end
    o.on('-i N', "iteration (default: auto)") do |v|
      iteration = v.to_i.abs
    end
    o.on('-m METHOD', "machine learning method [AROW|PA2|MLP] (default AROW)") do |v|
      if (v)
        case v.downcase
        when 'arow'
          method = :arow
        when 'pa1'
          method = :pa1
        when 'pa2'
          method = :pa2
        when 'mlp'
          method = :mlp
        else
          warn opt
          return -1
        end
      else
        warn opt
        return -1
      end
    end
    o.on('-p C', "parameter (default AROW::R=10.0, PA2::C=1.0, MLP::HIDDEN_UNIT=K)") do |v|
      c = v.to_f
    end
    o.on('-q', "quiet") do
      quiet = true
    end
  end
  opt.version = NekonekoGen::VERSION
  opt.banner = "Usage: nekoneko_gen [OPTIONS] -n NAME FILE1 FILE2 [FILES...]"
  files = opt.parse(argv)
  
  unless (rubyfile)
    warn opt
    return -1
  end
  if (files.size < 2)
    warn opt
    return -1
  end
  files.each do |file|
    unless (File.readable?(file))
      warn "#{file}: error.\n"
      return -1
    end
  end
  
  gen = NekonekoGen::TextClassifierGenerator.new(rubyfile, files, {:method => method, :c => c})
  if (quiet)
    gen.quiet = true
  end
  gen.train(iteration)
  gen.generate
  
  return 0
end