Press the 'Next' button to submit your post-edit and to request the next segment for translation.
Alternatively, just press enter when you finished the post-edit and the 'Target' text area is in focus. Warning: Past post-edits can not be altered. The session can be stopped at any time and continued later; However, if you have to pause your session, wait until the activity notification disappears and then press 'Pause', as we are collecting timing information. You may also just reload this site and re-request the next segment upon your return. Please only use one browser window at once. Going back to earlier examples is not possible, please take great care when interacting with the system.
@@ -86,5 +107,7 @@ The interface was only tested with Firefox 31.
+
+
diff --git a/lfpe.js b/lfpe.js
index 10c3093..a4aff1c 100644
--- a/lfpe.js
+++ b/lfpe.js
@@ -28,70 +28,6 @@ var Timer = {
}
}
-/*
- * init site
- *
- */
-function init()
-{
- document.getElementById("target_textarea").value = "";
- document.getElementById("raw_source_textarea").value = "";
- document.getElementById("source").value = "";
- document.getElementById("current_seg_id").value = "";
- document.getElementById("paused").value = "";
- document.getElementById("oov_correct").value = false;
- document.getElementById("displayed_oov_hint").value = false;
- document.getElementById("init").value = "";
- document.getElementById("target_textarea").setAttribute("disabled", "disabled");
- document.getElementById("next").removeAttribute("disabled");
- document.getElementById("pause_button").removeAttribute("disabled");
-
- return false;
-}
-
-/*
- * cross-site request
- *
- */
-function CreateCORSRequest(method, url)
-{
- var xhr = new XMLHttpRequest();
- if ("withCredentials" in xhr) {
- xhr.open(method, url, true);
- } else {
- xhr = null;
- }
-
- return xhr;
-}
-
-/*
- * no newline on return in textarea
- *
- */
-function catch_return(e)
-{
- if (e.keyCode == 13) {
- e.preventDefault();
- Next();
- }
-
- return false;
-}
-
-/*
- * check oov correction input
- *
- */
-function check_oov_correction()
-{
- var need = trim(document.getElementById("raw_source_textarea").value).split(";").length;
- var a = trim(document.getElementById("target_textarea").value).split(";");
- a = a.filter(function(i){ return i!=""; })
-
- return need==a.length;
-}
-
/*
* pause/unpause timer
*
@@ -103,6 +39,7 @@ function pause()
var next_button = document.getElementById("next");
var target_textarea = document.getElementById("target_textarea")
var initialized = document.getElementById("init");
+
if (paused.value == 0) {
button.innerHTML = "Unpause";
paused.value = 1;
@@ -121,15 +58,15 @@ function pause()
}
/*
- * hacky way to remove class from node
+ * no newline on return in textarea
*
*/
-function removeClass(node, className)
+function catch_return(e)
{
- node.className =
- node.className.replace(" "+className,'');
- node.className =
- node.className.replace(" "+className,''); // ???
+ if (e.keyCode == 13) {
+ e.preventDefault();
+ Next();
+ }
return false;
}
@@ -138,24 +75,51 @@ function removeClass(node, className)
*
*
*/
-function toggleDisplay(node)
+function working()
{
- if (node.style.display=='none') {
- node.style.display = 'block';
- } else {
- node.style.display = 'none';
- }
+ // elements
+ var button = document.getElementById("next");
+ var pause_button = document.getElementById("pause_button");
+ var target_textarea = document.getElementById("target_textarea")
+ var raw_source_textarea = document.getElementById("raw_source_textarea");
+ var current_seg_id = document.getElementById("current_seg_id");
+ var source = document.getElementById("source");
+ var status = document.getElementById("status");
+ var oov_correct = document.getElementById("oov_correct");
+ var last_post_edit = document.getElementById("last_post_edit");
- return false;
+ // show 'working' message
+ status.style.display = "block";
+
+ // disable button and textarea
+ button.setAttribute("disabled", "disabled");
+ pause_button.setAttribute("disabled", "disabled");
+ target_textarea.setAttribute("disabled", "disabled");
}
/*
- * trim string
+ *
*
*/
-function trim(s)
+function not_working()
{
- return s.replace(/^\s+|\s+$/g, '');
+ // elements
+ var button = document.getElementById("next");
+ var pause_button = document.getElementById("pause_button");
+ var target_textarea = document.getElementById("target_textarea")
+ var raw_source_textarea = document.getElementById("raw_source_textarea");
+ var current_seg_id = document.getElementById("current_seg_id");
+ var source = document.getElementById("source");
+ var status = document.getElementById("status");
+ var oov_correct = document.getElementById("oov_correct");
+ var last_post_edit = document.getElementById("last_post_edit");
+
+ // hide 'working' message
+ status.style.display = "none";
+
+ // enable buttons
+ document.getElementById("next").removeAttribute("disabled");
+ document.getElementById("pause_button").removeAttribute("disabled");
}
/*
@@ -175,19 +139,28 @@ function Next()
var oov_correct = document.getElementById("oov_correct");
var last_post_edit = document.getElementById("last_post_edit");
- // disable button and textarea
- button.setAttribute("disabled", "disabled");
- pause_button.setAttribute("disabled", "disabled");
- target_textarea.setAttribute("disabled", "disabled");
+ working();
// get metadata stored in DOM
+ var base_url = "http://coltrane.cl.uni-heidelberg.de";
var port = document.getElementById("port").value;
- var base_url = "http://coltrane.cl.uni-heidelberg.de:"+port;
var key = document.getElementById("key").value;
- next_url = base_url+"/next?key="+key;
+ // url
+ next_url = base_url+":"+port+"/next?key="+key;
- var post_edit = trim(target_textarea.value);
+ // post edit
+ var post_edit = '';
+
+ // extract data from interfaces
+ if (ui_type == 'g') {
+ post_edit = JSON.parse(extract_data())["target"].join(" ")
+ } else {
+ post_edit = trim(target_textarea.value);
+ }
+
+ // send data
+ // ???
if (oov_correct.value=="false" && post_edit != "") {
// compose request
next_url += "&example="+encodeURIComponent(source.value)+"%20%7C%7C%7C%20"+encodeURIComponent(post_edit)+"&duration="+Timer.get();
@@ -197,15 +170,28 @@ function Next()
}
// update document overview
document.getElementById("seg_"+(current_seg_id.value)+"_t").innerHTML=post_edit;
+ // OOV correction mode
} else if (oov_correct.value=="true") {
- if (!check_oov_correction()) {
- alert("Please provide translations for each word in the 'Source' text area, separated by ';'.");
- target_textarea.removeAttribute("disabled", "disabled");
- pause_button.removeAttribute("disabled", "disabled");
- button.removeAttribute("disabled", "disabled");
- return;
- }
- next_url += "&correct="+encodeURIComponent(raw_source_textarea.value)+"%20%7C%7C%7C%20"+encodeURIComponent(post_edit)
+ var l = document.getElementById("oov_fields").children.length;
+ var src = [];
+ var tgt = [];
+ for (var i=0; i
hide/disable functional elements
+ return;
+ }
+
+ data = JSON.parse(xhr.responseText)
+ document.getElementById("data").value = xhr.responseText;
+
+ // done, disable interface
+ if (data["fin"]) {
raw_source_textarea.setAttribute("disabled", "disabled");
target_textarea.setAttribute("disabled", "disabled");
status.style.display = "none";
button.innerHTML = "Session finished, thank you!";
button.setAttribute("disabled", "disabled");
pause_button.setAttribute("disabled", "disabled");
- removeClass(document.getElementById("seg_"+current_seg_id.value), "bold");
- } else {
- // got response: OOV\tseg id\ttoken_1\ttoken_2\t...
- // 0 1 2 3 ...
- if (x[0] == "OOV") {
- var s = "";
- for (var i=2; i < x.length; i++) {
- s += x[i].substr(1,x[i].length-2);
- if (i+1 < x.length) {
- s += "; ";
- }
- raw_source_textarea.value = s;
- }
- // update interface
- status.style.display = "none";
- button.innerHTML = "Correct";
- button.removeAttribute("disabled");
- target_textarea.removeAttribute("disabled", "disabled");
- pause_button.removeAttribute("disabled", "disabled");
- target_textarea.value = "";
- target_textarea.focus();
- target_textarea.selectionStart = 0;
- target_textarea.selectionEnd = 0;
- oov_correct.value = true;
- var id = x[1];
- document.getElementById("seg_"+id).className += " bold";
- if (id > 0) {
- removeClass(document.getElementById("seg_"+(id-1)), "bold");
- }
- if (document.getElementById("displayed_oov_hint").value == "false") {
- alert("Please translate the following words (separated by semicolons) to enable translation of the next sentence. Source words are always in lower case. Use correct casing for suggested translation.");
- document.getElementById("displayed_oov_hint").value = true;
- }
-
- return;
+ if (current_seg_id.value)
+ removeClass(document.getElementById("seg_"+current_seg_id.value), "bold");
+
+ return;
+
+ // enter OOV correct mode
+ } else if (data["oovs"]) {
+ var append_to = document.getElementById("oov_fields");
+ for (var i=0; i "/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 ||| #{source} "
- transl = send_recv :dtrain, msg
- $db['mt_raw'] << transl
+ obj_str = proc_deriv(send_recv(:dtrain, msg))
+ obj = JSON.parse obj_str
+ obj["transl"] = obj["target_groups"].join " "
# 4. detokenizer
- transl = send_recv :detokenizer, transl
- $db['mt'] << transl
+ obj["transl_detok"] = send_recv(:detokenizer, obj["transl"]).strip
+ obj["target_groups"].each_index { |j|
+ prev = obj["target_groups"][j][0]
+ obj["target_groups"][j] = send_recv(:detokenizer, obj["target_groups"][j]).strip
+ obj["target_groups"][j][0]=prev if j > 0
+ }
+ obj["source"] = source
+ obj["progress"]= $db['progress']
+ obj["raw_source"] = raw_source
+ w_idx = 0
+ obj["source_groups"].each_index { |j|
+ a = obj["source_groups"][j].split
+ a.each_with_index
+ }
+ # save
+ # FIXME
# 5. reply
- $last_reply = "#{$db['progress']}\t#{source}\t#{transl.strip}\t#{raw_source}"
+ $last_reply = obj.to_json
$lock = false
$confirmed = false
logmsg :server, "response: '#{$last_reply}'"
return $last_reply # return
end
- return "oh oh" # return FIXME: do something sensible
+ return "{}" # return [ERROR]
end
get '/debug' do # debug view
--
cgit v1.2.3