From 54bc620c309d471989824d5de50915728b2f3afc Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 3 May 2016 14:22:07 +0200 Subject: mv --- js/interface.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'js/interface.js') diff --git a/js/interface.js b/js/interface.js index c946e0c..d346b96 100644 --- a/js/interface.js +++ b/js/interface.js @@ -230,7 +230,7 @@ var next = function () working(); // get metadata stored in DOM - var base_url = "http://coltrane.cl.uni-heidelberg.de"; + var base_url = "http://lemmy.cl.uni-heidelberg.de"; var port = document.getElementById("port").value; var key = document.getElementById("key").value; @@ -334,7 +334,7 @@ var request_and_process_next = function () var last_post_edit = document.getElementById("last_post_edit"); // get metadata stored in DOM - var base_url = "http://coltrane.cl.uni-heidelberg.de"; + var base_url = "http://lemmy.cl.uni-heidelberg.de"; var port = document.getElementById("port").value; var key = document.getElementById("key").value; @@ -525,6 +525,7 @@ $().ready(function() init_text_editor(); document.getElementById("textboxes").style.display = "block"; } + }); -- cgit v1.2.3 From 6bd7135e6039b0682f49234e42451077413f0bd9 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 10 May 2016 10:49:09 +0200 Subject: count clicks and keystrokes, fix bug in rule addition, good params and improvement for phrase2 extraction --- interface.php | 5 ++-- js/interface.js | 47 +++++++++++++++++++++++++++++++- phrase2_extraction/phrase2_extraction.rb | 38 +++++++++++++++++++++++--- server.rb | 10 ++++--- views/debug.haml | 2 ++ 5 files changed, 91 insertions(+), 11 deletions(-) (limited to 'js/interface.js') diff --git a/interface.php b/interface.php index 8df7fd0..46b07f0 100644 --- a/interface.php +++ b/interface.php @@ -33,7 +33,7 @@ Target: - + @@ -52,7 +52,7 @@ Note that the source word may be distorted.
- + Working: ...
@@ -103,5 +103,6 @@ Note that the source word may be distorted. + diff --git a/js/interface.js b/js/interface.js index d346b96..f009641 100644 --- a/js/interface.js +++ b/js/interface.js @@ -5,6 +5,9 @@ var data, // global data object ui_type; // 't' (text) or 'g' (graphical) +var TEXT_count_click=0, + TEXT_count_kbd=0; + /* * cross-site request * @@ -108,6 +111,18 @@ var catch_return = function (e) return false; } +var TEXT_handle_keypress = function (e) +{ + if (e.keyCode == 13) { + e.preventDefault(); + next(); + } + + TEXT_count_kbd += 1; + + return false; +} + /* * working/not working * @@ -259,6 +274,8 @@ var next = function () post_edit = $.trim(target_textarea.value); send_data["post_edit"] = encodeURIComponent(post_edit); send_data['type'] = 't'; + send_data["count_click"] = TEXT_count_click; + send_data["count_kbd"] = TEXT_count_kbd; } send_data["key"] = key; @@ -456,8 +473,11 @@ var request_and_process_next = function () target_textarea.rows = Math.round(translation.length/80+0.5); //raw_source_textarea.rows = Math.round(raw_source.length/80+0.5); target_textarea.focus(); + $("#original_mt").val(target_textarea.value); target_textarea.selectionStart = 0; target_textarea.selectionEnd = 0; + TEXT_count_click = 0; + TEXT_count_kbd = 0; // remember aux data in DOM current_seg_id.value = id; @@ -493,10 +513,35 @@ var init_text_editor = function () { document.getElementById("target_textarea").value = ""; document.getElementById("target_textarea").setAttribute("disabled", "disabled"); + + TEXT_count_click = 0; + TEXT_count_kbd = 0; + + $("#target_textarea").click(function () { + TEXT_count_click += 1; + }); return false; } +var get_ui_type = function () +{ + return document.getElementById("ui_type").value; +} + +var reset = function () +{ + var ui_type = get_ui_type(); + if (ui_type == "t") { + if (!$("#init").val()) return; + TEXT_count_click = 0; + TEXT_count_kbd = 0; + $("#target_textarea").val($("#original_mt").val()); + } else if (ui_type == "g") { + DE_init() + } +} + /* * init site * @@ -514,7 +559,7 @@ $().ready(function() not_working(); - ui_type = document.getElementById("ui_type").value; + ui_type = get_ui_type(); // graphical derivation editor if (ui_type == "g") { diff --git a/phrase2_extraction/phrase2_extraction.rb b/phrase2_extraction/phrase2_extraction.rb index 253df1b..547e0be 100755 --- a/phrase2_extraction/phrase2_extraction.rb +++ b/phrase2_extraction/phrase2_extraction.rb @@ -5,9 +5,9 @@ require 'zipf' module PhrasePhraseExtraction DEBUG = false -MAX_NT = 1 # Chiang: 2 -MAX_SEED_NUM_WORDS = 10 # Chiang: 10 words -MAX_SRC_SZ = 5 # Chiang: 5 words +MAX_NT = 2 # Chiang: 2 +MAX_SEED_NUM_WORDS = 4 # Chiang: 10 words, -> phrases! +MAX_SRC_SZ = 10 # Chiang: 5 words, -> words! FORBID_SRC_ADJACENT_SRC_NT = true # Chiang:true class Rule @@ -51,6 +51,21 @@ class Rule return src_len end + def len_src_w + src_len = 0 + @source.each { |i| + if i.is_a? String + src_len += i.split.size #1 + else + i.each { |j| + src_len += source_context[j].split.size + } + end + } + + return src_len + end + def len_tgt tgt_len = 0 @target.each { |i| @@ -64,6 +79,21 @@ class Rule return tgt_len end + def len_tgt_w + tgt_len = 0 + @target.each { |i| + if i.is_a? String + tgt_len += i.split.size + else + i.each { |j| + tgt_len += target_context[j].split.size + } + end + } + + return tgt_len + end + def to_s source_string = "" @source.each { |i| @@ -625,7 +655,7 @@ end def PhrasePhraseExtraction.remove_too_long_src_sides rules return rules.reject { |r| - r.len_src > PhrasePhraseExtraction::MAX_SRC_SZ + r.len_src_w > PhrasePhraseExtraction::MAX_SRC_SZ } end diff --git a/server.rb b/server.rb index 9ca43b1..599fdbd 100755 --- a/server.rb +++ b/server.rb @@ -295,6 +295,8 @@ def process_next reply $db['svg'] << data['svg'] $db['original_svg'] << data['original_svg'] $db['durations'] << data['duration'].to_f + $db['count_click'] << data['count_click'].to_i + $db['count_kbd'] << data['count_kbd'].to_i $db['post_edits_display'] << send_recv(:detokenizer, post_edit) $last_processed_postedit = $db['post_edits_display'].last # 1. tokenize @@ -423,13 +425,13 @@ def process_next reply all_rules[j] = ar end } - WriteFile.new(grammar).write all_rules.join("\n")+"\n" # - additional rules - logmsg :server, $new_rules.to_s + #logmsg :server, $new_rules.to_s if $new_rules.size > 0 - s = $new_rules.join "\n" - `echo "#{s}" >> #{grammar}` + all_rules += $new_rules + #`echo "#{s}" >> #{grammar}` end + WriteFile.new(grammar).write all_rules.join("\n")+"\n" #$new_rules.each { |rule| # logmsg :server, "adding rule '#{rule}' to grammar '#{grammar}'" # s = splitpipe(rule)[1..2].map{|i|i.strip.lstrip}.join(" ||| ") diff --git a/views/debug.haml b/views/debug.haml index 1bc0fd1..3c1e006 100644 --- a/views/debug.haml +++ b/views/debug.haml @@ -144,6 +144,8 @@ %p.updated Number of updates: #{pairwise_ranking_data["num_up"]} %p.updated Updated features: #{pairwise_ranking_data["updated_features"]} %p Duration: #{data["durations"][progress]}ms + %p Keypresses: #{data["count_kbd"][progress]} + %p Clicks: #{data["count_click"][progress]} %h3 Derivation %p -- cgit v1.2.3