ajax-cat 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +21 -0
- data/Rakefile +8 -2
- data/VERSION +1 -1
- data/ajax-cat.gemspec +22 -3
- data/bin/ajax-cat +20 -5
- data/lib/ajax-cat.rb +95 -8
- data/lib/ajax-cat/ajax_cat_server.rb +74 -6
- data/lib/ajax-cat/log.rb +6 -0
- data/lib/ajax-cat/moses_pair.rb +3 -4
- data/lib/ajax-cat/pairs.rb +56 -0
- data/lib/ajax-cat/public/AjaxCatList.coffee +62 -11
- data/lib/ajax-cat/public/AjaxCatTranslation.coffee +55 -7
- data/lib/ajax-cat/public/Suggestions.coffee +1 -1
- data/lib/ajax-cat/public/TranslationTable.coffee +7 -6
- data/lib/ajax-cat/public/ajax-cat.js +166 -29
- data/lib/ajax-cat/public/index.html +29 -2
- data/lib/ajax-cat/public/translation.html +6 -0
- data/lib/ajax-cat/request/raw.rb +8 -1
- data/lib/ajax-cat/request/suggestion.rb +40 -0
- data/lib/ajax-cat/request/table.rb +94 -0
- data/lib/ajax-cat/task.rb +6 -0
- data/lib/ajax-cat/views/admin.erb +83 -0
- data/lib/ajax-cat/views/experiment.erb +62 -0
- data/logs.db +0 -0
- data/test/fixtures/ajax-cat.ini.json +14 -0
- data/test/fixtures/moses.ini +6 -2
- data/test/fixtures/nbest.txt +19 -0
- data/test/helper.rb +2 -52
- data/test/integration/test_start_and_stop.rb +31 -3
- data/test/unit/test_moses_pair.rb +1 -4
- data/test/unit/test_pairs.rb +43 -0
- data/test/unit/test_suggestion_request.rb +32 -0
- data/test/unit/test_table_request.rb +61 -0
- metadata +56 -21
@@ -0,0 +1,56 @@
|
|
1
|
+
module AjaxCat
|
2
|
+
|
3
|
+
class Pairs
|
4
|
+
|
5
|
+
attr_reader :db
|
6
|
+
|
7
|
+
def initialize(configuration)
|
8
|
+
@pairs = {}
|
9
|
+
unless File.exist?("#{Dir.home}/.ajax-cat/admin.db")
|
10
|
+
@db = SQLite3::Database.new("#{Dir.home}/.ajax-cat/admin.db")
|
11
|
+
@db.execute(
|
12
|
+
|
13
|
+
<<-SQL
|
14
|
+
create table tasks (
|
15
|
+
id integer primary key,
|
16
|
+
pair varchar (30),
|
17
|
+
sentence text
|
18
|
+
)
|
19
|
+
SQL
|
20
|
+
)
|
21
|
+
@db.execute(
|
22
|
+
<<-SQL
|
23
|
+
create table logs (
|
24
|
+
id integer primary key,
|
25
|
+
task_id integer,
|
26
|
+
email varchar (60),
|
27
|
+
time current_timestamp,
|
28
|
+
log text
|
29
|
+
)
|
30
|
+
SQL
|
31
|
+
)
|
32
|
+
#Task.new(id: 1, pair: "de-en", sentence: "Das ist ein kleines haus").save
|
33
|
+
#Task.new(id: 2, pair: "de-en", sentence: "Das ist ein kleines haus 2").save
|
34
|
+
|
35
|
+
#Log.new(task_id: 1, email: "hypertornado@gmail.com", time: Time.now, log: "some log").save
|
36
|
+
else
|
37
|
+
@db = SQLite3::Database.new "#{Dir.home}/.ajax-cat/admin.db"
|
38
|
+
end
|
39
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "#{Dir.home}/.ajax-cat/admin.db")
|
40
|
+
configuration['pairs'].each do |pair|
|
41
|
+
@pairs[pair['name']] = MosesPair.new(pair['name'], pair['moses_path'], pair['moses_ini_path'])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_request(request, pair_name)
|
46
|
+
pair = @pairs[pair_name]
|
47
|
+
pair.process_request(request)
|
48
|
+
end
|
49
|
+
|
50
|
+
def list
|
51
|
+
@pairs.keys
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -2,6 +2,7 @@ class AjaxCatList
|
|
2
2
|
|
3
3
|
constructor: ->
|
4
4
|
$('#new-translation-modal').hide()
|
5
|
+
$('#new-experiment-modal').hide()
|
5
6
|
$('#new-translation').on('click',@new_translation)
|
6
7
|
$('#create-new-translation').on('click',@create_new_translation)
|
7
8
|
@show_translations()
|
@@ -11,12 +12,53 @@ class AjaxCatList
|
|
11
12
|
$('#new-translation-text').val(text)
|
12
13
|
return false
|
13
14
|
)
|
15
|
+
$("#new-experiment-translation").click(
|
16
|
+
=>
|
17
|
+
@new_experiment_translation()
|
18
|
+
)
|
19
|
+
$("#create-new-experiment").click(
|
20
|
+
=>
|
21
|
+
@create_experiment_translation()
|
22
|
+
)
|
23
|
+
|
24
|
+
create_experiment_translation: =>
|
25
|
+
email = $("#new-experiment-email").val()
|
26
|
+
pair = $("#new-experiment-pair").val()
|
27
|
+
filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
|
28
|
+
unless filter.test(email)
|
29
|
+
alert "Write your email, please."
|
30
|
+
return
|
31
|
+
$.ajax "/admin/get_experiment"
|
32
|
+
data:
|
33
|
+
email: email
|
34
|
+
pair: pair
|
35
|
+
success: (data) =>
|
36
|
+
data = JSON.parse(data)
|
37
|
+
id = @add_translation(data.sentence, "EXPERIMENT ##{data.task_id}, #{data.email}", data.pair, data.task_id, data.email)
|
38
|
+
window.location = "/translation.html##{id}"
|
39
|
+
error: =>
|
40
|
+
alert "Could not find experiment for you."
|
41
|
+
|
42
|
+
new_experiment_translation: =>
|
43
|
+
$("#new-experiment-pair").html("")
|
44
|
+
$.ajax "/api/info"
|
45
|
+
success: (data) =>
|
46
|
+
data = JSON.parse(data)
|
47
|
+
for p in data.pairs
|
48
|
+
$("#new-experiment-pair").append("<option value='#{p}'>#{p}</option>")
|
49
|
+
$('#new-experiment-modal').modal('show')
|
14
50
|
|
15
51
|
new_translation: =>
|
16
|
-
$(
|
17
|
-
|
18
|
-
|
19
|
-
|
52
|
+
$("#new-translation-pair").html("")
|
53
|
+
$.ajax "/api/info"
|
54
|
+
success: (data) =>
|
55
|
+
data = JSON.parse(data)
|
56
|
+
for p in data.pairs
|
57
|
+
$("#new-translation-pair").append("<option value='#{p}'>#{p}</option>")
|
58
|
+
$('#new-translation-name').val('Name')
|
59
|
+
$('#new-translation-text').val('')
|
60
|
+
$('#new-translation-modal').modal('show')
|
61
|
+
$('#new-translation-text').focus()
|
20
62
|
|
21
63
|
show_translations: =>
|
22
64
|
$("#translation-list").html('')
|
@@ -29,11 +71,11 @@ class AjaxCatList
|
|
29
71
|
(event) =>
|
30
72
|
id = $(event.currentTarget).data("id")
|
31
73
|
if confirm("Delete this translation?")
|
32
|
-
|
74
|
+
AjaxCatList.delete_document(id)
|
33
75
|
@show_translations()
|
34
76
|
)
|
35
77
|
|
36
|
-
delete_document: (id) =>
|
78
|
+
@delete_document: (id) =>
|
37
79
|
return unless localStorage['ac-data']
|
38
80
|
ids = JSON.parse(localStorage['ac-data'])
|
39
81
|
new_ids = []
|
@@ -44,20 +86,29 @@ class AjaxCatList
|
|
44
86
|
|
45
87
|
|
46
88
|
create_new_translation: =>
|
47
|
-
text = $('#new-translation-text').val()
|
89
|
+
text = $('#new-translation-text').val()
|
90
|
+
name = $('#new-translation-name').val()
|
91
|
+
pair = $('#new-translation-pair').val()
|
92
|
+
@add_translation(text, name, pair)
|
93
|
+
$('#new-translation-modal').modal('hide')
|
94
|
+
@show_translations()
|
95
|
+
|
96
|
+
add_translation: (text, name, pair, task_id = false, email = false) =>
|
48
97
|
if localStorage['ac-data']
|
49
98
|
docs = JSON.parse(localStorage['ac-data'])
|
50
99
|
else
|
51
100
|
docs = []
|
52
101
|
doc = {}
|
53
102
|
doc.id = Utils.random_string()
|
54
|
-
doc
|
55
|
-
doc
|
103
|
+
doc.name = name
|
104
|
+
doc.pair = pair
|
105
|
+
doc.email = email
|
106
|
+
doc.task_id = task_id
|
56
107
|
doc.source = Utils.split_source(text)
|
57
108
|
doc.target = new Array(doc.source.length)
|
58
109
|
docs.push(doc.id)
|
59
110
|
localStorage.setItem('ac-data', JSON.stringify(docs))
|
60
111
|
localStorage.setItem(doc.id, JSON.stringify(doc))
|
61
|
-
|
62
|
-
|
112
|
+
return doc.id
|
113
|
+
|
63
114
|
|
@@ -1,21 +1,21 @@
|
|
1
1
|
class AjaxCatTranslation
|
2
2
|
|
3
3
|
cur_position: false
|
4
|
-
pair: "en-cs"
|
5
|
-
#host: "10.10.24.118"
|
6
|
-
host: "localhost"
|
7
4
|
|
8
5
|
constructor: ->
|
9
|
-
@
|
6
|
+
@now = Date.now()
|
7
|
+
$('#new-experiment-modal').hide()
|
8
|
+
$("#send-experiment").hide()
|
10
9
|
@suggestions = new Suggestions(@)
|
11
10
|
$('#translation-preview-modal').hide()
|
12
11
|
$('#myTab').tab('show')
|
13
|
-
hash = window.location.hash.substr(1)
|
14
|
-
data = localStorage.getItem(hash)
|
12
|
+
@hash = window.location.hash.substr(1)
|
13
|
+
data = localStorage.getItem(@hash)
|
15
14
|
unless data
|
16
15
|
alert "No such document."
|
17
16
|
return
|
18
17
|
@doc = JSON.parse(data)
|
18
|
+
@prepare_test() if @doc.task_id
|
19
19
|
@pair = @doc.pair
|
20
20
|
$('h1').html("#{@doc.name} <small>#{@pair}</small>")
|
21
21
|
$("title").html("#{@doc.name} - AJAX-CAT")
|
@@ -40,13 +40,61 @@ class AjaxCatTranslation
|
|
40
40
|
@bind_events()
|
41
41
|
@resize()
|
42
42
|
|
43
|
+
time: =>
|
44
|
+
sec = parseInt((Date.now() - @now) / 1000)
|
45
|
+
t = "time from start: #{parseInt(sec / 60)}:#{sec % 60}"
|
46
|
+
$("#time").html(t)
|
47
|
+
setTimeout(@time, 10)
|
48
|
+
|
49
|
+
prepare_test: =>
|
50
|
+
AjaxCatList.delete_document(@hash)
|
51
|
+
$("#save").hide()
|
52
|
+
$("#send-experiment").show()
|
53
|
+
$("#send-experiment").click(
|
54
|
+
=>
|
55
|
+
$("#send-experiment").hide()
|
56
|
+
$.ajax "/admin/save_experiment"
|
57
|
+
data:
|
58
|
+
log: JSON.stringify(@doc)
|
59
|
+
type: "POST"
|
60
|
+
success: =>
|
61
|
+
alert "Experiment saved."
|
62
|
+
window.location = "/"
|
63
|
+
error: =>
|
64
|
+
alert "Could not save experiment."
|
65
|
+
)
|
66
|
+
@doc.log = []
|
67
|
+
@time()
|
68
|
+
$("#log").append("<h2>Log</h2>")
|
69
|
+
@log()
|
70
|
+
|
71
|
+
log: (type = false, param = false) =>
|
72
|
+
new_log = (
|
73
|
+
time: Date.now()
|
74
|
+
target: $("#target-sentence").val()
|
75
|
+
)
|
76
|
+
new_log.type = type if type
|
77
|
+
new_log.param = param if param
|
78
|
+
@doc.log.push(new_log)
|
79
|
+
$("#log").append(JSON.stringify(new_log) + "<br>")
|
80
|
+
|
81
|
+
|
43
82
|
resize: =>
|
44
83
|
width = $(window).width()
|
45
84
|
$("#translation-table-container").width(width - 60)
|
46
85
|
|
47
86
|
bind_events: =>
|
87
|
+
$("#target-sentence").on('keyup',
|
88
|
+
=>
|
89
|
+
@log()
|
90
|
+
)
|
91
|
+
$("#target-sentence").on('click',
|
92
|
+
=>
|
93
|
+
@log()
|
94
|
+
)
|
48
95
|
$("#target-sentence").on('keydown'
|
49
96
|
(event) =>
|
97
|
+
@log()
|
50
98
|
switch event.which
|
51
99
|
when 13 #enter
|
52
100
|
@suggestions.take_suggestion()
|
@@ -108,7 +156,7 @@ class AjaxCatTranslation
|
|
108
156
|
@suggestions.clear()
|
109
157
|
return
|
110
158
|
$("#translation-table-container").text("")
|
111
|
-
$.ajax "
|
159
|
+
$.ajax "/api/table"
|
112
160
|
data:
|
113
161
|
pair: @pair
|
114
162
|
q: sentence
|
@@ -33,7 +33,7 @@ class Suggestions
|
|
33
33
|
sentence = Utils.tokenize(sentence)
|
34
34
|
translated = Utils.tokenize($("#source-target").text())
|
35
35
|
covered = @translation.table.covered_vector()
|
36
|
-
$.ajax "
|
36
|
+
$.ajax "/api/suggestion"
|
37
37
|
data:
|
38
38
|
pair: @translation.pair
|
39
39
|
q: Utils.tokenize(sentence)
|
@@ -2,13 +2,14 @@ class TranslationTable
|
|
2
2
|
|
3
3
|
constructor: (@translation, data) ->
|
4
4
|
@data = JSON.parse(data)
|
5
|
+
console.log @data
|
5
6
|
|
6
7
|
get_table: =>
|
7
8
|
ret = $("<table>"
|
8
9
|
class: 'translation-table'
|
9
10
|
)
|
10
11
|
ret.append(@get_header())
|
11
|
-
for row in @data.
|
12
|
+
for row in @data.table
|
12
13
|
ret.append(@get_row(row))
|
13
14
|
return ret
|
14
15
|
|
@@ -36,15 +37,15 @@ class TranslationTable
|
|
36
37
|
ret = $("<tr>")
|
37
38
|
i = 0
|
38
39
|
for word in row
|
39
|
-
len = parseInt(word.
|
40
|
-
if word.
|
41
|
-
ret.append("<td colspan='#{
|
40
|
+
len = parseInt(word.w)
|
41
|
+
if !word.str
|
42
|
+
ret.append("<td colspan='#{len}' class='ac-empty'></td>")
|
42
43
|
else
|
43
|
-
cell = $("<td colspan='#{
|
44
|
+
cell = $("<td colspan='#{len}' class='ac-word'></td>")
|
44
45
|
content = $("<div>"
|
45
46
|
'data-position-from': i
|
46
47
|
'data-position-to': (i + len - 1)
|
47
|
-
html: word.
|
48
|
+
html: word.str
|
48
49
|
click: (event) =>
|
49
50
|
i = parseInt($(event.currentTarget).data('position-from'))
|
50
51
|
while i <= parseInt($(event.currentTarget).data('position-to'))
|
@@ -4,12 +4,15 @@ var AjaxCatList, AjaxCatTranslation, Suggestions, TranslationTable, Utils,
|
|
4
4
|
AjaxCatList = (function() {
|
5
5
|
|
6
6
|
function AjaxCatList() {
|
7
|
+
this.add_translation = __bind(this.add_translation, this);
|
7
8
|
this.create_new_translation = __bind(this.create_new_translation, this);
|
8
|
-
this.delete_document = __bind(this.delete_document, this);
|
9
9
|
this.show_translations = __bind(this.show_translations, this);
|
10
10
|
this.new_translation = __bind(this.new_translation, this);
|
11
|
+
this.new_experiment_translation = __bind(this.new_experiment_translation, this);
|
12
|
+
this.create_experiment_translation = __bind(this.create_experiment_translation, this);
|
11
13
|
var _this = this;
|
12
14
|
$('#new-translation-modal').hide();
|
15
|
+
$('#new-experiment-modal').hide();
|
13
16
|
$('#new-translation').on('click', this.new_translation);
|
14
17
|
$('#create-new-translation').on('click', this.create_new_translation);
|
15
18
|
this.show_translations();
|
@@ -19,13 +22,76 @@ AjaxCatList = (function() {
|
|
19
22
|
$('#new-translation-text').val(text);
|
20
23
|
return false;
|
21
24
|
});
|
25
|
+
$("#new-experiment-translation").click(function() {
|
26
|
+
return _this.new_experiment_translation();
|
27
|
+
});
|
28
|
+
$("#create-new-experiment").click(function() {
|
29
|
+
return _this.create_experiment_translation();
|
30
|
+
});
|
22
31
|
}
|
23
32
|
|
33
|
+
AjaxCatList.prototype.create_experiment_translation = function() {
|
34
|
+
var email, filter, pair,
|
35
|
+
_this = this;
|
36
|
+
email = $("#new-experiment-email").val();
|
37
|
+
pair = $("#new-experiment-pair").val();
|
38
|
+
filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
39
|
+
if (!filter.test(email)) {
|
40
|
+
alert("Write your email, please.");
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
return $.ajax("/admin/get_experiment", {
|
44
|
+
data: {
|
45
|
+
email: email,
|
46
|
+
pair: pair
|
47
|
+
},
|
48
|
+
success: function(data) {
|
49
|
+
var id;
|
50
|
+
data = JSON.parse(data);
|
51
|
+
id = _this.add_translation(data.sentence, "EXPERIMENT #" + data.task_id + ", " + data.email, data.pair, data.task_id, data.email);
|
52
|
+
return window.location = "/translation.html#" + id;
|
53
|
+
},
|
54
|
+
error: function() {
|
55
|
+
return alert("Could not find experiment for you.");
|
56
|
+
}
|
57
|
+
});
|
58
|
+
};
|
59
|
+
|
60
|
+
AjaxCatList.prototype.new_experiment_translation = function() {
|
61
|
+
var _this = this;
|
62
|
+
$("#new-experiment-pair").html("");
|
63
|
+
return $.ajax("/api/info", {
|
64
|
+
success: function(data) {
|
65
|
+
var p, _i, _len, _ref;
|
66
|
+
data = JSON.parse(data);
|
67
|
+
_ref = data.pairs;
|
68
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
69
|
+
p = _ref[_i];
|
70
|
+
$("#new-experiment-pair").append("<option value='" + p + "'>" + p + "</option>");
|
71
|
+
}
|
72
|
+
return $('#new-experiment-modal').modal('show');
|
73
|
+
}
|
74
|
+
});
|
75
|
+
};
|
76
|
+
|
24
77
|
AjaxCatList.prototype.new_translation = function() {
|
25
|
-
|
26
|
-
$(
|
27
|
-
|
28
|
-
|
78
|
+
var _this = this;
|
79
|
+
$("#new-translation-pair").html("");
|
80
|
+
return $.ajax("/api/info", {
|
81
|
+
success: function(data) {
|
82
|
+
var p, _i, _len, _ref;
|
83
|
+
data = JSON.parse(data);
|
84
|
+
_ref = data.pairs;
|
85
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
86
|
+
p = _ref[_i];
|
87
|
+
$("#new-translation-pair").append("<option value='" + p + "'>" + p + "</option>");
|
88
|
+
}
|
89
|
+
$('#new-translation-name').val('Name');
|
90
|
+
$('#new-translation-text').val('');
|
91
|
+
$('#new-translation-modal').modal('show');
|
92
|
+
return $('#new-translation-text').focus();
|
93
|
+
}
|
94
|
+
});
|
29
95
|
};
|
30
96
|
|
31
97
|
AjaxCatList.prototype.show_translations = function() {
|
@@ -43,13 +109,13 @@ AjaxCatList = (function() {
|
|
43
109
|
var id;
|
44
110
|
id = $(event.currentTarget).data("id");
|
45
111
|
if (confirm("Delete this translation?")) {
|
46
|
-
|
112
|
+
AjaxCatList.delete_document(id);
|
47
113
|
return _this.show_translations();
|
48
114
|
}
|
49
115
|
});
|
50
116
|
};
|
51
117
|
|
52
|
-
AjaxCatList.
|
118
|
+
AjaxCatList.delete_document = function(id) {
|
53
119
|
var i, ids, new_ids, _i, _len;
|
54
120
|
if (!localStorage['ac-data']) return;
|
55
121
|
ids = JSON.parse(localStorage['ac-data']);
|
@@ -63,8 +129,19 @@ AjaxCatList = (function() {
|
|
63
129
|
};
|
64
130
|
|
65
131
|
AjaxCatList.prototype.create_new_translation = function() {
|
66
|
-
var
|
132
|
+
var name, pair, text;
|
67
133
|
text = $('#new-translation-text').val();
|
134
|
+
name = $('#new-translation-name').val();
|
135
|
+
pair = $('#new-translation-pair').val();
|
136
|
+
this.add_translation(text, name, pair);
|
137
|
+
$('#new-translation-modal').modal('hide');
|
138
|
+
return this.show_translations();
|
139
|
+
};
|
140
|
+
|
141
|
+
AjaxCatList.prototype.add_translation = function(text, name, pair, task_id, email) {
|
142
|
+
var doc, docs;
|
143
|
+
if (task_id == null) task_id = false;
|
144
|
+
if (email == null) email = false;
|
68
145
|
if (localStorage['ac-data']) {
|
69
146
|
docs = JSON.parse(localStorage['ac-data']);
|
70
147
|
} else {
|
@@ -72,29 +149,26 @@ AjaxCatList = (function() {
|
|
72
149
|
}
|
73
150
|
doc = {};
|
74
151
|
doc.id = Utils.random_string();
|
75
|
-
doc
|
76
|
-
doc
|
152
|
+
doc.name = name;
|
153
|
+
doc.pair = pair;
|
154
|
+
doc.email = email;
|
155
|
+
doc.task_id = task_id;
|
77
156
|
doc.source = Utils.split_source(text);
|
78
157
|
doc.target = new Array(doc.source.length);
|
79
158
|
docs.push(doc.id);
|
80
159
|
localStorage.setItem('ac-data', JSON.stringify(docs));
|
81
160
|
localStorage.setItem(doc.id, JSON.stringify(doc));
|
82
|
-
|
83
|
-
return this.show_translations();
|
161
|
+
return doc.id;
|
84
162
|
};
|
85
163
|
|
86
164
|
return AjaxCatList;
|
87
165
|
|
88
|
-
})();
|
166
|
+
}).call(this);
|
89
167
|
|
90
168
|
AjaxCatTranslation = (function() {
|
91
169
|
|
92
170
|
AjaxCatTranslation.prototype.cur_position = false;
|
93
171
|
|
94
|
-
AjaxCatTranslation.prototype.pair = "en-cs";
|
95
|
-
|
96
|
-
AjaxCatTranslation.prototype.host = "localhost";
|
97
|
-
|
98
172
|
function AjaxCatTranslation() {
|
99
173
|
this.add_words = __bind(this.add_words, this);
|
100
174
|
this.change_position = __bind(this.change_position, this);
|
@@ -103,19 +177,25 @@ AjaxCatTranslation = (function() {
|
|
103
177
|
this.show_preview = __bind(this.show_preview, this);
|
104
178
|
this.bind_events = __bind(this.bind_events, this);
|
105
179
|
this.resize = __bind(this.resize, this);
|
106
|
-
|
180
|
+
this.log = __bind(this.log, this);
|
181
|
+
this.prepare_test = __bind(this.prepare_test, this);
|
182
|
+
this.time = __bind(this.time, this);
|
183
|
+
var data, i, s, t, _i, _j, _len, _len2, _ref, _ref2,
|
107
184
|
_this = this;
|
108
|
-
this.
|
185
|
+
this.now = Date.now();
|
186
|
+
$('#new-experiment-modal').hide();
|
187
|
+
$("#send-experiment").hide();
|
109
188
|
this.suggestions = new Suggestions(this);
|
110
189
|
$('#translation-preview-modal').hide();
|
111
190
|
$('#myTab').tab('show');
|
112
|
-
hash = window.location.hash.substr(1);
|
113
|
-
data = localStorage.getItem(hash);
|
191
|
+
this.hash = window.location.hash.substr(1);
|
192
|
+
data = localStorage.getItem(this.hash);
|
114
193
|
if (!data) {
|
115
194
|
alert("No such document.");
|
116
195
|
return;
|
117
196
|
}
|
118
197
|
this.doc = JSON.parse(data);
|
198
|
+
if (this.doc.task_id) this.prepare_test();
|
119
199
|
this.pair = this.doc.pair;
|
120
200
|
$('h1').html("" + this.doc.name + " <small>" + this.pair + "</small>");
|
121
201
|
$("title").html("" + this.doc.name + " - AJAX-CAT");
|
@@ -147,6 +227,55 @@ AjaxCatTranslation = (function() {
|
|
147
227
|
this.resize();
|
148
228
|
}
|
149
229
|
|
230
|
+
AjaxCatTranslation.prototype.time = function() {
|
231
|
+
var sec, t;
|
232
|
+
sec = parseInt((Date.now() - this.now) / 1000);
|
233
|
+
t = "time from start: " + (parseInt(sec / 60)) + ":" + (sec % 60);
|
234
|
+
$("#time").html(t);
|
235
|
+
return setTimeout(this.time, 10);
|
236
|
+
};
|
237
|
+
|
238
|
+
AjaxCatTranslation.prototype.prepare_test = function() {
|
239
|
+
var _this = this;
|
240
|
+
AjaxCatList.delete_document(this.hash);
|
241
|
+
$("#save").hide();
|
242
|
+
$("#send-experiment").show();
|
243
|
+
$("#send-experiment").click(function() {
|
244
|
+
$("#send-experiment").hide();
|
245
|
+
return $.ajax("/admin/save_experiment", {
|
246
|
+
data: {
|
247
|
+
log: JSON.stringify(_this.doc),
|
248
|
+
type: "POST"
|
249
|
+
},
|
250
|
+
success: function() {
|
251
|
+
alert("Experiment saved.");
|
252
|
+
return window.location = "/";
|
253
|
+
},
|
254
|
+
error: function() {
|
255
|
+
return alert("Could not save experiment.");
|
256
|
+
}
|
257
|
+
});
|
258
|
+
});
|
259
|
+
this.doc.log = [];
|
260
|
+
this.time();
|
261
|
+
$("#log").append("<h2>Log</h2>");
|
262
|
+
return this.log();
|
263
|
+
};
|
264
|
+
|
265
|
+
AjaxCatTranslation.prototype.log = function(type, param) {
|
266
|
+
var new_log;
|
267
|
+
if (type == null) type = false;
|
268
|
+
if (param == null) param = false;
|
269
|
+
new_log = {
|
270
|
+
time: Date.now(),
|
271
|
+
target: $("#target-sentence").val()
|
272
|
+
};
|
273
|
+
if (type) new_log.type = type;
|
274
|
+
if (param) new_log.param = param;
|
275
|
+
this.doc.log.push(new_log);
|
276
|
+
return $("#log").append(JSON.stringify(new_log) + "<br>");
|
277
|
+
};
|
278
|
+
|
150
279
|
AjaxCatTranslation.prototype.resize = function() {
|
151
280
|
var width;
|
152
281
|
width = $(window).width();
|
@@ -155,8 +284,15 @@ AjaxCatTranslation = (function() {
|
|
155
284
|
|
156
285
|
AjaxCatTranslation.prototype.bind_events = function() {
|
157
286
|
var _this = this;
|
287
|
+
$("#target-sentence").on('keyup', function() {
|
288
|
+
return _this.log();
|
289
|
+
});
|
290
|
+
$("#target-sentence").on('click', function() {
|
291
|
+
return _this.log();
|
292
|
+
});
|
158
293
|
$("#target-sentence").on('keydown', function(event) {
|
159
294
|
var ar, text, word;
|
295
|
+
_this.log();
|
160
296
|
switch (event.which) {
|
161
297
|
case 13:
|
162
298
|
return _this.suggestions.take_suggestion();
|
@@ -227,7 +363,7 @@ AjaxCatTranslation = (function() {
|
|
227
363
|
return;
|
228
364
|
}
|
229
365
|
$("#translation-table-container").text("");
|
230
|
-
return $.ajax("
|
366
|
+
return $.ajax("/api/table", {
|
231
367
|
data: {
|
232
368
|
pair: this.pair,
|
233
369
|
q: sentence
|
@@ -329,7 +465,7 @@ Suggestions = (function() {
|
|
329
465
|
sentence = Utils.tokenize(sentence);
|
330
466
|
translated = Utils.tokenize($("#source-target").text());
|
331
467
|
covered = this.translation.table.covered_vector();
|
332
|
-
return $.ajax("
|
468
|
+
return $.ajax("/api/suggestion", {
|
333
469
|
data: {
|
334
470
|
pair: this.translation.pair,
|
335
471
|
q: Utils.tokenize(sentence),
|
@@ -419,6 +555,7 @@ TranslationTable = (function() {
|
|
419
555
|
this.get_header = __bind(this.get_header, this);
|
420
556
|
this.get_table = __bind(this.get_table, this);
|
421
557
|
this.data = JSON.parse(data);
|
558
|
+
console.log(this.data);
|
422
559
|
}
|
423
560
|
|
424
561
|
TranslationTable.prototype.get_table = function() {
|
@@ -427,7 +564,7 @@ TranslationTable = (function() {
|
|
427
564
|
"class": 'translation-table'
|
428
565
|
});
|
429
566
|
ret.append(this.get_header());
|
430
|
-
_ref = this.data.
|
567
|
+
_ref = this.data.table;
|
431
568
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
432
569
|
row = _ref[_i];
|
433
570
|
ret.append(this.get_row(row));
|
@@ -471,15 +608,15 @@ TranslationTable = (function() {
|
|
471
608
|
i = 0;
|
472
609
|
for (_i = 0, _len = row.length; _i < _len; _i++) {
|
473
610
|
word = row[_i];
|
474
|
-
len = parseInt(word.
|
475
|
-
if (word.
|
476
|
-
ret.append("<td colspan='" +
|
611
|
+
len = parseInt(word.w);
|
612
|
+
if (!word.str) {
|
613
|
+
ret.append("<td colspan='" + len + "' class='ac-empty'></td>");
|
477
614
|
} else {
|
478
|
-
cell = $("<td colspan='" +
|
615
|
+
cell = $("<td colspan='" + len + "' class='ac-word'></td>");
|
479
616
|
content = $("<div>", {
|
480
617
|
'data-position-from': i,
|
481
618
|
'data-position-to': i + len - 1,
|
482
|
-
html: word.
|
619
|
+
html: word.str,
|
483
620
|
click: function(event) {
|
484
621
|
i = parseInt($(event.currentTarget).data('position-from'));
|
485
622
|
while (i <= parseInt($(event.currentTarget).data('position-to'))) {
|