OSDN Git Service

ELCHNOS-OSECPU:式の内部表現への変換は完了した。
[chnosproject/AI004.git] / aisub.js
1 function AI_IOManager(env){
2         this.env = env;
3 }
4 AI_IOManager.prototype = {
5         //http://www.atmarkit.co.jp/ait/articles/1112/16/news135_2.html
6         //http://qiita.com/mohayonao/items/fa7d33b75a2852d966fc
7         showDownloadLink: function(blobData){
8                 if(window.URL){
9                         this.env.downloadBox.innerHTML = "<a href='" + window.URL.createObjectURL(blobData) + "' target='_blank'>ダウンロード</a>";
10                 } else if(window.webkitURL){
11                         this.env.downloadBox.innerHTML = "<a href='" + window.webkitURL.createObjectURL(blobData) + "' target='_blank'>ダウンロード</a>";
12                 } else{
13                         window.alert("Can't create URL");
14                 }
15         }
16 }
17
18 function AI_Input(env){
19         this.env = env;
20         this.historyList = new Array();
21         this.sentenceList = new Array();
22 }
23 AI_Input.prototype = {
24         maxHistoryLength: 16,
25         sentenceSeparator: [
26                 "。",
27                 "!",
28                 "?",
29                 "!",
30                 "?",
31                 "\n",
32         ],
33         appendInput: function(input){
34                 //inputはStringとArrayが使用できる
35                 var sList = input.splitByArray(this.sentenceSeparator);
36                 
37                 this.sentenceList = this.sentenceList.concat(sList)
38         },
39         getSentence: function(){
40                 //改行のみの文は破棄
41                 for(;;){
42                         if(this.sentenceList.length <= 0){
43                                 return undefined;
44                         }
45                         var retv = this.sentenceList[0];
46                         this.sentenceList.splice(0, 1);
47                         retv = retv.trim();
48                         if(retv != ""){
49                                 break;
50                         }
51                 }
52                 //ここで単語候補抽出を行っておく
53                 this.env.wordRecognition.slideLookUpCandidateWordByHistory(retv);
54                 //
55                 this.appendHistory(retv);
56                 return retv;
57         },
58         appendHistory: function(str){
59                 this.historyList.push(str);
60                 if(this.historyList.length > this.maxHistoryLength){
61                         this.historyList.splice(0, this.maxHistoryLength >> 1);
62                 }
63         },
64 }