From 3c20ae7fcba64ec27c8a75651bf8b82bba1c8300 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Wed, 11 Nov 2015 16:17:40 +0100
Subject: a lot of fixes and additions, most notably: also sending json
---
js/lfpe.js | 14 +++++++++++---
server.rb | 34 ++++++++++++++++++++++++++--------
util/wrapper.rb | 2 +-
views/debug.haml | 36 +++++++++++++++++++++++++++++++-----
4 files changed, 69 insertions(+), 17 deletions(-)
diff --git a/js/lfpe.js b/js/lfpe.js
index e2b0f42..edfae9b 100644
--- a/js/lfpe.js
+++ b/js/lfpe.js
@@ -162,23 +162,31 @@ function Next()
// post edit
var post_edit = '';
+ var send_data = new Object();
// extract data from interfaces
if (ui_type == 'g') {
- post_edit = trim(JSON.parse(DE_extract_data())["target"].join(" "))
+ send_data = JSON.parse(DE_extract_data());
+ post_edit = trim(send_data["target"].join(" "));
+ send_data["post_edit"] = post_edit;
} else {
post_edit = trim(target_textarea.value);
+ send_data["post_edit"] = post_edit;
}
// send data
// ???
if (oov_correct.value=="false" && post_edit != "") {
+ send_data["duration"] = Timer.get();
+ send_data["source_value"] = source.value;
// compose request
- next_url += "&example="+encodeURIComponent(source.value)+"%20%7C%7C%7C%20"+encodeURIComponent(post_edit)+"&duration="+Timer.get();
+ //next_url += "&example="+encodeURIComponent(source.value)+"%20%7C%7C%7C%20"+encodeURIComponent(post_edit)+"&duration="+Timer.get();
// no change?
if (post_edit == last_post_edit.value) {
- next_url += "&nochange=1";
+ //next_url += "&nochange=1";
+ send_data["nochange"] = true;
}
+ next_url += "&example="+encodeURIComponent(JSON.stringify(send_data));
// update document overview
document.getElementById("seg_"+(current_seg_id.value)+"_t").innerHTML=post_edit;
// OOV correction mode
diff --git a/server.rb b/server.rb
index 6b81b36..b0da33a 100755
--- a/server.rb
+++ b/server.rb
@@ -174,11 +174,16 @@ get '/next' do # (receive post-edit, update models), send next translation
# 5d. actual update
# 6. update database
if params[:example]
+ logmsg :server, params[:example]
+ rcv_obj = JSON.parse params[:example]
# 0. save raw post-edit
- source, reference = params[:example].strip.split(" ||| ")
+ #source, reference = params[:example].strip.split(" ||| ")
+ source = rcv_obj["source_value"]
+ reference = rcv_obj["target"].join " "
reference = cleanstr(reference)
+ $db['feedback'] << params[:example]
$db['post_edits_raw'] << reference.strip
- $db['durations'] << params['duration'].to_i
+ $db['durations'] << rcv_obj['duration'].to_i
# 1. tokenize
reference = send_recv :tokenizer, reference
# 2. truecase
@@ -187,7 +192,7 @@ get '/next' do # (receive post-edit, update models), send next translation
logmsg :db, "saving processed post-edit"
$db['post_edits'] << reference.strip
nochange = false
- if params[:nochange]
+ if rcv_obj[:nochange]
logmsg :server, "no change -> no updates!"
nochange = true
end
@@ -210,8 +215,11 @@ get '/next' do # (receive post-edit, update models), send next translation
send_recv :extractor, "default_context ||| #{source} ||| #{reference} ||| #{a}"
# 6. update database
logmsg :db, "updating database"
+ $db['updated'] << true
+ else
+ $db['updated'] << false
end
- update_database
+ update_database
end
source = $db['source_segments'][$db['progress']]
raw_source = $db['raw_source_segments'][$db['progress']]
@@ -284,7 +292,8 @@ get '/next' do # (receive post-edit, update models), send next translation
end
# 3. translation
msg = "act:translate |||