OSDN Git Service

f3097e1c6e0f7e4f9fff9aa1d383df8f58e83f5b
[chnosproject/AI004.git] / aisub.js
1 function AI_IOManager(env){
2         this.env = env;
3         this.lastSentenceSourceType = undefined;
4         // User, File, Web
5 }
6 AI_IOManager.prototype = {
7         //http://www.atmarkit.co.jp/ait/articles/1112/16/news135_2.html
8         //http://qiita.com/mohayonao/items/fa7d33b75a2852d966fc
9         showDownloadLink: function(blobData){
10                 if(window.URL){
11                         this.env.downloadBox.innerHTML = "<a href='" + window.URL.createObjectURL(blobData) + "' target='_blank'>ダウンロード</a>";
12                 } else if(window.webkitURL){
13                         this.env.downloadBox.innerHTML = "<a href='" + window.webkitURL.createObjectURL(blobData) + "' target='_blank'>ダウンロード</a>";
14                 } else{
15                         window.alert("Can't create URL");
16                 }
17         }
18 }
19
20 function AI_Input(env){
21         this.env = env;
22         this.historyList = new Array();
23         this.sentenceList = new Array();
24 }
25 AI_Input.prototype = {
26         maxHistoryLength: 32,
27         sentenceSeparator: [
28                 "。",
29                 "!",
30                 "?",
31                 "!",
32                 "?",
33                 "\n",
34         ],
35         appendInput: function(input, srctype){
36                 //inputはStringとArrayが使用できる
37                 var sList;
38                 if(srctype != "User"){
39                         sList = input.splitByArray(this.sentenceSeparator);
40                 } else{
41                         sList = [input];
42                 }
43                 console.log(sList);
44                 this.sentenceList.push([srctype]);
45                 this.sentenceList = this.sentenceList.concat(sList);
46         },
47         getSentence: function(){
48                 for(;;){
49                         if(this.sentenceList.length <= 0){
50                                 return undefined;
51                         }
52                         var retv = this.sentenceList.shift();
53                         if(retv instanceof Array){
54                                 //ソースタイプ変更
55                                 this.lastSentenceSourceType = retv[0];
56                                 continue;
57                         }
58                         retv = retv.trim();
59                         break;
60                 }
61                 //
62                 this.appendHistory(retv);
63                 return retv;
64         },
65         appendHistory: function(str){
66                 this.historyList.push(str);
67                 if(this.historyList.length > this.maxHistoryLength){
68                         this.historyList.splice(0, this.maxHistoryLength >> 1);
69                 }
70         },
71 }