1 function AI_Think(env){
3 this.jobStack = new Array();
4 this.processingJob = null;
10 if(this.env.input.sentenceList.length > 0){
11 var tickStartTimeMs = new Date();
12 this.env.debug("**** Think ****\n");
13 for(var i = 0; i < 64; i++){
14 if((new Date()) - tickStartTimeMs > this.tickLimitMs){
19 var s = this.env.input.getSentence();
22 this.env.wordRecognition.sortCandidateWordListByWordCount();
23 this.env.wordRecognition.computeEachWordLevel();
24 this.env.wordRecognition.sortCandidateWordListByWordLevel();
27 if(this.env.input.lastSentenceSourceType){
28 this.env.message(this.env.input.lastSentenceSourceType, true);
30 this.env.message("Unknown", true);
32 this.env.message("> " + s + "\n", true);
34 var separated = this.env.wordRecognition.splitByWord(s);
35 this.env.debug("[" + separated.join(" ") + "]\n");
38 this.checkPattern(separated);
41 if(this.processingJob && this.processingJob.input(s) === undefined){
42 this.processingJob = null;
45 } else if(this.processingJob || this.jobStack.length > 0){
46 if(!this.processingJob){
47 this.processingJob = this.jobStack.pop();
49 if(this.processingJob.tick() === undefined){
50 this.processingJob = null;
54 checkPattern: function(separated){
55 var separated_UUID = this.env.wordRecognition.getUUIDListFromSeparatedString(separated);
56 this.env.debug("[\n" + separated_UUID.join("\n") + "\n]\n");
57 var pList = this.env.memory.patternList.copy();
59 if(pList.length <= 0 || separated.length <= 0 || separated_UUID.length <= 0){
63 for(var i = 0, iLen = pList.length; i < iLen; i++){
64 var p = pList[i].pattern;
66 if(separated_UUID.length != p.length){
67 pList.removeByIndex(i);
71 for(var j = 0, jLen = separated_UUID.length; j < jLen; j++){
72 if(p[j] != separated_UUID[j]){
73 pList.removeByIndex(i);
82 for(var i = 0, iLen = pList.length; i < iLen; i++){
85 p.func(this.env, separated, separated_UUID);