summaryrefslogtreecommitdiff
path: root/util/truecase.rb
blob: 3e97bd549c7c2ba887f002f32704a67c409c8269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env ruby

require 'nanomsg'
require 'open3'
require 'trollop'

conf = Trollop::options do
  opt :addr, "socket address", :short => "-S", :type => :string, :required => true
  opt :moses, "path to moses directory", :short => "-m", :type => :string, :required => true
  opt :model, "model file", :short => "-n", :type => :string, :required => true
end

sock = NanoMsg::PairSocket.new
sock.bind conf[:addr]
sock.send "hello"

cmd = "#{conf[:moses]}/scripts/recaser/truecase.perl -b --model #{conf[:model]}"
while true
  inp = sock.recv + " " # FIXME?
  break if !inp||inp=="shutdown"
  Open3.popen3(cmd) do |pin, pout, perr|
    pin.write inp
    pin.close
    s = pout.gets.strip
    sock.send s #pout.gets.strip
  end
end

sock.send "off"