diff options
author | Patrick Simianer <p@simianer.de> | 2015-06-23 16:03:23 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-06-23 16:03:23 +0200 |
commit | 14f7bbab028d781cd2057a348862f911324338fd (patch) | |
tree | 170df2d80cb4aea161700e26bd951d06276a81f5 /util | |
parent | 553d54484725614fa73e805b59136a39e6dee295 (diff) |
overhaul
Diffstat (limited to 'util')
-rwxr-xr-x | util/de-tok.rb | 36 | ||||
-rwxr-xr-x | util/kill | 4 | ||||
-rwxr-xr-x | util/run_server | 8 | ||||
-rwxr-xr-x | util/truecase.rb | 30 |
4 files changed, 78 insertions, 0 deletions
diff --git a/util/de-tok.rb b/util/de-tok.rb new file mode 100755 index 0000000..92c563f --- /dev/null +++ b/util/de-tok.rb @@ -0,0 +1,36 @@ +#!/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/kill b/util/kill new file mode 100755 index 0000000..f1924b2 --- /dev/null +++ b/util/kill @@ -0,0 +1,4 @@ +#!/bin/bash + +for i in {1..6}; do ps ax | grep -P "(server.rb|atools|net_fa|sa.extract|dtrain)" | grep -v vim | grep -v -P "^\s\+$" | cut -d " " -f $i | xargs kill -9 &>/dev/null; done + diff --git a/util/run_server b/util/run_server new file mode 100755 index 0000000..88dadb5 --- /dev/null +++ b/util/run_server @@ -0,0 +1,8 @@ +#!/bin/bash -x + +export LD_LIBRARY_PATH=/fast_scratch/simianer/lfpe/nanomsg-0.5-beta/lib +export PYTHONPATH=/fast_scratch/simianer/lfpe/python +UTIL=/fast_scratch/simianer/lfpe/lfpe/util +DATA=/fast_scratch/simianer/lfpe/data/tiny_test +clear;$UTIL/kill;$UTIL/kill;$UTIL/kill;rm $DATA/work/lockfile; cp $DATA/data.json.original $DATA/data.json; $UTIL/../server.rb $DATA/conf.rb + diff --git a/util/truecase.rb b/util/truecase.rb new file mode 100755 index 0000000..3e97bd5 --- /dev/null +++ b/util/truecase.rb @@ -0,0 +1,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" + |