Class: AjaxCat::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ajax-cat.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = DEFAULT_PORT, silent = true) ⇒ Runner

Returns a new instance of Runner.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ajax-cat.rb', line 31

def initialize(port = DEFAULT_PORT, silent = true)
  logger = Logger.new
  logger.log "starting ajax-cat"
  #Thin::Logging.silent = silent
  Thin::Logging.debug = :log
  system("mkdir #{Dir.home}/.ajax-cat 2>/dev/null")
  @settings = JSON.parse(File.read("ajax-cat.ini.json"))
  port = @settings["port"] if port == DEFAULT_PORT
  @@pairs = Pairs.new(@settings)
  Dir.chdir(Dir.home)
  Dir.mkdir('.ajax-cat') unless Dir.exist?('.ajax-cat')
  builder = Rack::Builder.new do
    map('/'){ run AjaxCatServer }
  end
  logger.log "starting server on port #{port}"
  @server = builder
  Rack::Handler::Thin.run builder, :Port => port, :Logging => true
  logger.log "ajax-cat server shutted down"
end

Class Method Details

.create_sample_moses_iniObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ajax-cat.rb', line 68

def self.create_sample_moses_ini
  path = File.dirname(__FILE__) + "/../test/fixtures/"
  @moses_ini = <<-END.gsub(/^ {6}/, '')
  #########################
  ### MOSES CONFIG FILE ###
  #########################

  # input factors
  [input-factors]
  0

  # mapping steps, either (T) translation or (G) generation
  [mapping]
  T 0

  # translation tables: source-factors, target-factors, number of scores, file
  [ttable-file]
  0 0 0 1 #{path}phrase-table

  # language models: type(srilm/irstlm/kenlm), factors, order, file
  [lmodel-file]
  8 0 3 #{path}europarl.srilm.gz

  # limit on how many phrase translations e for each phrase f are loaded
  [ttable-limit]
  10

  # distortion (reordering) weight
  [weight-d]
  1

  # language model weights
  [weight-l]
  1

  # translation model weights
  [weight-t]
  1

  # word penalty
  [weight-w]
  0

  [n-best-list]
  nbest.txt
  100



  END
  f = File.new(File.dirname(__FILE__) + "/../test/fixtures/moses.ini", "w")
  f.write(@moses_ini)
  f.close


end

.exampleObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ajax-cat.rb', line 51

def self.example
  self.create_sample_moses_ini()
  ret = <<-END.gsub(/^ {8}/, '')
    {
      "port": #{DEFAULT_PORT},
      "pairs": [
        {
          "name": "de-en",
          "moses_path": "moses",
          "moses_ini_path": "#{File.dirname(__FILE__) + "/../test/fixtures/moses.ini"}"
        }
      ]
    }
  END
  ret
end

.pairsObject



27
28
29
# File 'lib/ajax-cat.rb', line 27

def self.pairs
  @@pairs
end