OSDN Git Service

AIのDB連携機能を実装中。
[chnosproject/AI004.git] / aijobs.js
1 var AI_Job_Ask_isWord = function(env){
2         AI_Job_Ask_isWord.base.call(this, env);
3         this.waiting = false;
4         this.currentCandidate = null;
5         this.isPromptedByUser = false;
6 }.extend(AI_Job, {
7         //ユーザーが空入力をすると、候補単語が単語であるかどうかをユーザーに問いかける。
8         tick: function(){
9                 //定期的に呼ばれることを期待する
10                 //戻り値がundefinedで処理終了
11                 if(!this.waiting && this.env.memory.candidateWordList.length > 0 && this.isPromptedByUser){
12                         this.currentCandidate = this.env.memory.candidateWordList.pop();
13                         this.env.memory.removeMemoryTagByObject(this.currentCandidate);
14                         this.env.message("「" + this.currentCandidate.str + "」は単語ですか?(y/n)\n");
15                         this.waiting = true;
16                         this.isPromptedByUser = false;
17                 }
18                 return 0;
19         },
20         input: function(s){
21                 //ジョブが登録されているときに入力があると呼ばれる。
22                 //戻り値がundefinedで処理終了
23                 if(this.env.input.lastSentenceSourceType != "User"){
24                         return 0;
25                 }
26                 if(this.waiting == false){
27                         if(s == ""){
28                                 this.isPromptedByUser = true;
29                         }
30                 } else{
31                         if(s == "y"){
32                                 this.env.memory.appendMemoryTag(new AI_WordTag(this.currentCandidate.str));
33                                 this.env.message(this.env.memory.wordList.length + "個目の単語を登録しました!\n");
34                         }
35                         this.waiting = false;
36                         this.currentCandidate = null;
37                 }
38                 return 0;
39         }
40 });