-
Notifications
You must be signed in to change notification settings - Fork 5
/
igo-web.js
60 lines (58 loc) · 2.18 KB
/
igo-web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$(function() {
function event(data) {
if(data.event=='downloaded') {
$('#loading').text('辞書を展開中・・・');
} else if(data.event=='load') {
$('#loading').hide();
$('#inputform').show();
} else if(data.event=="result" && data.method=="parseNBest") {
var nodeslist = data.morpheme;
var result = '';
for(var j=0;j<nodeslist.length;++j) {
var nodes = nodeslist[j];
for(var i=0;i<nodes.length;i++) {
result += '<div class="morph"><div class="surface">' + nodes[i].surface + '</div><div class="feature">' + nodes[i].feature + '</div></div>';
}
result += '<div>EOS</div>';
}
$('#result').html(result);
} else if(data.event=="error") {
$('#loading').text('エラー発生');
}
}
var post;
if(window.useNodeJS) {
event({event: 'load'});
post = function(data) {
$.ajax(
{
url: 'igo',
data: data,
success: function(data, datatype) {event(data);},
error: function() {event({event:'error'});}
}
);
}
} else {
var BlobBuilder = window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder || window.BlobBuilder;
var worker = new Worker('web.js');
igo.getServerFileToArrayBufffer("ipadic.zip", function(buffer) {
try {
event({event: 'downloaded'});
var blob = new Blob([new Uint8Array(buffer)]);
worker.postMessage({method: 'setdic', dic: blob});
} catch(e) {
console.error(e.toString());
event({event:"error"});
}
});
post = function(data) {
worker.postMessage(data);
}
worker.addEventListener("message", function(e) {event(e.data);});
worker.addEventListener("error", function() {event({event:"error"});});
}
$('#morph').click(function() {
post({method: 'parseNBest', text: $('#input').val(), best: 3});
});
});