diff options
author | Patrick Simianer <p@simianer.de> | 2015-06-24 17:47:32 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-06-24 17:47:32 +0200 |
commit | 60f93614186ebd6150602cae140b7a96dc4bca8a (patch) | |
tree | 1edfe37ee6c12de3e21535270a80425c537c68a9 /util | |
parent | e6b57a4f119820275ca363a3c3996ebee366e942 (diff) |
better wrapper script
Diffstat (limited to 'util')
-rwxr-xr-x | util/de-tok.rb | 36 | ||||
-rwxr-xr-x | util/truecase.rb | 30 | ||||
-rwxr-xr-x | util/wrapper.rb | 47 |
3 files changed, 47 insertions, 66 deletions
diff --git a/util/de-tok.rb b/util/de-tok.rb deleted file mode 100755 index 92c563f..0000000 --- a/util/de-tok.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env ruby - -require 'nanomsg' -require 'open3' -require 'trollop' - -conf = Trollop::options do - opt :action, "tokenize (T) or detokenize (D)", :type => :string, :requred => true - opt :addr, "socket address", :short => "-S", :type => :string, :required => true - opt :scripts, "path to scripts directory", :short => "-p", :type => :string, :required => true - opt :lang, "language", :short => "-l", :type => :string, :required => true -end - -sock = NanoMsg::PairSocket.new -sock.bind conf[:addr] -sock.send "hello" - -if conf[:action] == "D" - cmd = "#{conf[:scripts]}/detokenizer.perl -q -b -u -l #{conf[:lang]}" -elsif conf[:action] == "T" - cmd = "#{conf[:scripts]}/tokenizer-no-escape.perl -q -b -a -l #{conf[:lang]}" -else - # ERROR -end -while true - inp = sock.recv - break if !inp||inp=="shutdown" - Open3.popen3(cmd) do |pin, pout, perr| - pin.write inp - pin.close - sock.send pout.gets.strip - end -end - -sock.send "off" - diff --git a/util/truecase.rb b/util/truecase.rb deleted file mode 100755 index 3e97bd5..0000000 --- a/util/truecase.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/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" - diff --git a/util/wrapper.rb b/util/wrapper.rb new file mode 100755 index 0000000..8445f0f --- /dev/null +++ b/util/wrapper.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +require 'nanomsg' +require 'open3' +require 'trollop' + +conf = Trollop::options do + opt :action, "tokenize, detokenize or truecase", :short => "-a", :type => :string, :required => true + opt :addr, "socket address", :short => "-S", :type => :string, :required => true + opt :ext, "path to externals", :short => "-e", :type => :string, :required => true + opt :lang, "language", :short => "-l", :type => :string + opt :truecase_model, "model file for truecaser", :short => "-t", :type => :string +end + +sock = NanoMsg::PairSocket.new +sock.bind conf[:addr] +sock.send "hello" + +if conf[:action] == "detokenize" + cmd = "#{conf[:ext]}/detokenizer.perl -q -b -u -l #{conf[:lang]}" + if !conf[:lang] + STDERR.write "[detokenizer] No language given, exiting!\n"; exit + end +elsif conf[:action] == "tokenize" + cmd = "#{conf[:ext]}/tokenizer-no-escape.perl -q -b -a -l #{conf[:lang]}" + if !conf[:lang] + STDERR.write "[tokenizer] No language given, exiting!\n"; exit + end +elsif conf[:action] == "truecase" + cmd = "#{conf[:ext]}/truecase.perl -b --model #{conf[:truecase_model]}" + if !conf[:truecase_model] + STDERR.write "[truecaser] No model given for truecaser, exiting!\n"; exit + end +else + STDERR.write "[wrapper] Unknown action #{conf[:action]}, exiting!\n"; exit +end +pin, pout, perr = Open3.popen3(cmd) +while true + inp = sock.recv.strip+"\n" + break if !inp||inp=="shutdown" + pin.write inp + sock.send pout.gets.strip +end + +pin.close; pout.close; perr.close +sock.send "off" + |