From e1bbf92a8bc8ae97408092a29da106821e276d20 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Wed, 28 Oct 2015 10:04:37 +0100
Subject: enabled use of graphical ui and switching between grahpical and
 textual ui
---
 server.rb | 57 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 17 deletions(-)
(limited to 'server.rb')
diff --git a/server.rb b/server.rb
index ca17148..8d45ca7 100755
--- a/server.rb
+++ b/server.rb
@@ -7,6 +7,7 @@ require 'nanomsg'
 require 'zipf'
 require 'json'
 require 'haml'
+require_relative './derivation_to_json/derivation_to_json'
 
 # #############################################################################
 # Load configuration file and setup global variables
@@ -24,11 +25,12 @@ end
 # #############################################################################
 # Daemons
 # #############################################################################
+DIR="/fast_scratch/simianer/lfpe/"
 $daemons = {
-  :tokenizer    => "/fast_scratch/simianer/lfpe/lfpe/util/wrapper.rb -a tokenize   -S '__ADDR__' -e #{EXTERNAL} -l #{TARGET_LANG}",
-  :detokenizer  => "/fast_scratch/simianer/lfpe/lfpe/util/wrapper.rb -a detokenize -S '__ADDR__' -e #{EXTERNAL} -l #{TARGET_LANG}",
-  :truecaser    => "/fast_scratch/simianer/lfpe/lfpe/util/wrapper.rb -a truecase   -S '__ADDR__' -e #{EXTERNAL} -t #{SESSION_DIR}/truecase.model",
-  :dtrain       => "#{CDEC}/training/dtrain/dtrain_net_interface -c #{SESSION_DIR}/dtrain.ini -d #{WORK_DIR}/dtrain.debug.json -o #{WORK_DIR}/weights -a '__ADDR__'",
+  :tokenizer    => "#{DIR}/lfpe/util/wrapper.rb -a tokenize   -S '__ADDR__' -e #{EXTERNAL} -l #{TARGET_LANG}",
+  :detokenizer  => "#{DIR}/lfpe/util/wrapper.rb -a detokenize -S '__ADDR__' -e #{EXTERNAL} -l #{TARGET_LANG}",
+  :truecaser    => "#{DIR}/lfpe/util/wrapper.rb -a truecase   -S '__ADDR__' -e #{EXTERNAL} -t #{SESSION_DIR}/truecase.model",
+  :dtrain       => "#{CDEC}/training/dtrain/dtrain_net_interface -c #{SESSION_DIR}/dtrain.ini -d #{WORK_DIR}/dtrain.debug.json -o #{WORK_DIR}/weights -a '__ADDR__' -E",
   :extractor    => "python -m cdec.sa.extract -c #{SESSION_DIR}/sa.ini --online -u -S '__ADDR__'",
   :aligner_fwd  => "#{CDEC}/word-aligner/net_fa -f #{SESSION_DIR}/forward.params  -m #{FWD_MEAN_SRCLEN_MULT}  -T #{FWD_TENSION}  --sock_url '__ADDR__'",
   :aligner_back => "#{CDEC}/word-aligner/net_fa -f #{SESSION_DIR}/backward.params -m #{BACK_MEAN_SRCLEN_MULT} -T #{BACK_TENSION} --sock_url '__ADDR__'",
@@ -47,7 +49,6 @@ set :max_age,           "1728000"
 set :expose_headers,    ['Content-Type']
 set :public_folder,     File.dirname(__FILE__) + '/static'
 
-
 # #############################################################################
 # Helper functions
 # #############################################################################
@@ -144,8 +145,8 @@ get '/next' do      # (receive post-edit, update models), send next translation
     grammar = "#{WORK_DIR}/g/#{$db['progress']}.grammar"
     src, tgt = splitpipe(params[:correct])
     tgt = cleanstr(tgt)
-    src = src.split(';').map { |i| i.strip }
-    tgt = tgt.split(';').map { |i| i.strip }
+    src = src.split("\t").map { |i| i.strip }
+    tgt = tgt.split("\t").map { |i| i.strip }
     src.each_with_index { |s,i|
       next if s==''||tgt[i]==''
       a = ""
@@ -212,7 +213,7 @@ get '/next' do      # (receive post-edit, update models), send next translation
   if !source # input is done -> displays 'Thank you!'
     logmsg :server, "end of input, sending 'fi'"
     $lock = false
-    return "fi"                                                        # return
+    return {'fin'=>true}.to_json                                       # return
   elsif !$confirmed
     logmsg :server, "locked, re-sending last reply"
     $lock = false
@@ -231,7 +232,11 @@ get '/next' do      # (receive post-edit, update models), send next translation
     if NOMT
       $lock = false
       logmsg :server, "no mt"
-      return "#{$db['progress']}\t#{source}\t \t#{raw_source}"         # return
+      obj = Hash.new
+      obj["progress"] = $db["progress"]
+      obj["source"] = source
+      obj["raw_source"] = raw_source
+      return obj.to_json                                               # return
     end
     # 1. generate grammar for current sentence
     grammar = "#{WORK_DIR}/g/#{$db['progress']}.grammar"
@@ -254,8 +259,11 @@ get '/next' do      # (receive post-edit, update models), send next translation
     }
     oovs.uniq!
     logmsg :server, "OOVs: #{oovs.to_s}"
-    if oovs.size > 0
-      $last_reply = "OOV\t#{$db['progress']}\t#{oovs.map{|i| "\"#{i}\""}.join("\t")}"
+    if oovs.size > 0                                               # OOVs FIXME
+      obj = Hash.new
+      obj["oovs"] = oovs
+      obj["progress"] = $db['progress']
+      $last_reply = obj.to_json
       logmsg :server, "OOV reply: '#{$last_reply}'"
       $lock = false
       $confirmed = false
@@ -263,20 +271,35 @@ get '/next' do      # (receive post-edit, update models), send next translation
     end
     # 3. translation
     msg = "act:translate |||