summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--interface.php5
-rw-r--r--js/interface.js47
-rwxr-xr-xphrase2_extraction/phrase2_extraction.rb38
-rwxr-xr-xserver.rb10
-rw-r--r--views/debug.haml2
5 files changed, 91 insertions, 11 deletions
diff --git a/interface.php b/interface.php
index 8df7fd0..46b07f0 100644
--- a/interface.php
+++ b/interface.php
@@ -33,7 +33,7 @@
<tr>
<td align="right">Target:</td>
<td>
- <textarea id="target_textarea" name="target" cols="80" rows="1" onkeypress="catch_return(event);" disabled></textarea>
+ <textarea id="target_textarea" name="target" cols="80" rows="1" onkeypress="TEXT_handle_keypress(event);" disabled></textarea>
</td>
</tr>
</table>
@@ -52,7 +52,7 @@ Note that the source word may be distorted.
<div>
<button id="help_button" class="button" onclick="$('#help').toggle('blind')">Help</button>
<button id="pause_button" class='button' type="button" onclick="pause()">Pause</button>
- <button id="reset_button" class='button' type="button" onclick="DE_init()">Reset</button>
+ <button id="reset_button" class='button' type="button" onclick="reset()">Reset</button>
<button id="next" type="button" class='button' onclick="next();">Start/Continue</button>
<span id="status"><strong>Working: <span id="status_detail">...</span></strong> <img src="static/ajax-loader-large.gif" width="20px" /></span>
</div>
@@ -103,5 +103,6 @@ Note that the source word may be distorted.
<textarea style="display:none" id="ui_type" ><?php echo $_GET["ui_type"]; ?></textarea>
<textarea style="display:none" id="data" ></textarea>
<textarea style="display:none" id="original_svg" ></textarea>
+<textarea style="display:none" id="original_mt" ></textarea>
<!-- /Data -->
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 <strong>Number of updates:</strong> #{pairwise_ranking_data["num_up"]}
%p.updated <strong>Updated features:</strong> #{pairwise_ranking_data["updated_features"]}
%p <strong>Duration:</strong> #{data["durations"][progress]}ms
+ %p <strong>Keypresses:</strong> #{data["count_kbd"][progress]}
+ %p <strong>Clicks:</strong> #{data["count_click"][progress]}
%h3 Derivation
%p