1 function AI_Think(env){
3 this.jobStack = new Array();
4 this.processingJob = null;
15 if(this.env.input.sentenceList.length > 0){
16 tickStartTimeMs = new Date();
17 this.env.debug("**** Think ****\n");
18 if(this.env.memory.candidateWordListLastModifiedDate > this.env.memory.candidateWordListLastCleanedDate){
19 if(this.env.memory.candidateWordListLastCleanedDate.getTime() + 1000 < tickStartTimeMs){
20 this.env.wordRecognition.cleanCandidateWordList();
23 for(var i = 0; i < 64; i++){
24 if((new Date()) - tickStartTimeMs > this.tickLimitMs){
29 s = this.env.input.getSentence();
32 //入力文字列が終了したので、単語候補をソート
33 this.env.wordRecognition.sortCandidateWordListByWordCount();
34 this.env.wordRecognition.computeEachWordLevel();
35 this.env.wordRecognition.sortCandidateWordListByWordLevel();
38 if(this.env.input.lastSentenceSourceType){
39 this.env.message(this.env.input.lastSentenceSourceType, true);
41 this.env.message("Unknown", true);
43 this.env.message("> " + s + "\n", true);
45 this.env.wordRecognition.slideLookUpCandidateWordByHistory(s);
47 separated = this.env.wordRecognition.splitByWord(s);
48 this.env.debug("[" + separated.join(" ") + "]\n");
49 separated_UUID = this.env.wordRecognition.getUUIDListFromSeparatedString(separated);
50 //分割の結果、未定義文字列と判別された部分を候補単語から探し、候補単語にあれば、その出現回数を+100する。
51 for(var i = 0, iLen = separated_UUID.length;i < iLen; i++){
52 if(separated_UUID[i] == this.env.UUID_Meaning_UndefinedString){
53 t = this.env.wordRecognition.getCandidateWordTagByString(separated[i]);
60 this.checkPattern(separated, separated_UUID);
63 if(this.processingJob && this.processingJob.input(s) === undefined){
64 this.processingJob = null;
67 } else if(this.processingJob || this.jobStack.length > 0){
68 if(!this.processingJob){
69 this.processingJob = this.jobStack.pop();
71 if(this.processingJob.tick() === undefined){
72 this.processingJob = null;
76 checkPattern: function(separated, separated_UUID){
78 this.env.debug("[\n" + separated_UUID.join("\n") + "\n]\n");
79 var pList = this.env.memory.patternList.copy();
81 if(pList.length <= 0 || separated.length <= 0 || separated_UUID.length <= 0){
85 for(var i = 0, iLen = pList.length; i < iLen; i++){
86 var p = pList[i].pattern;
87 if(p instanceof Function){
88 if(pList[i].pattern(separated, separated_UUID)){
91 } else if(p instanceof Array){
93 if(separated_UUID.length == p.length){
94 for(var j = 0, jLen = separated_UUID.length; j < jLen; j++){
95 if(p[j] != separated_UUID[j]){
104 pList.removeByIndex(i);
108 //マッチしたパターンに設定された関数の呼び出し
109 for(var i = 0, iLen = pList.length; i < iLen; i++){
112 p.func(this.env, separated, separated_UUID);