OSDN Git Service

エッジの描画を曲線に変更。
[chnosproject/AI004.git] / aithink.js
index e25fd36..fdd634c 100644 (file)
@@ -7,21 +7,29 @@ AI_Think.prototype = {
        tickLimitMs: 100,
        tick: function(){
                //定期的に呼ばれることを期待する
+               var tickStartTimeMs;
+               var s;
+               var separated;
+               var separated_UUID;
+               var t;
+               tickStartTimeMs = new Date();
                if(this.env.input.sentenceList.length > 0){
-                       var tickStartTimeMs = new Date();
                        this.env.debug("**** Think ****\n");
+                       
                        for(var i = 0; i < 64; i++){
                                if((new Date()) - tickStartTimeMs > this.tickLimitMs){
                                        //CPU時間占有防止
                                        break;
                                }
                                //入力処理ループ
-                               var s = this.env.input.getSentence();
+                               s = this.env.input.getSentence();
+                               
                                if(s === undefined){
-                                       //単語候補をソート
+                                       //å\85¥å\8a\9bæ\96\87å­\97å\88\97ã\81\8cçµ\82äº\86ã\81\97ã\81\9fã\81®ã\81§ã\80\81å\8d\98èª\9eå\80\99è£\9cã\82\92ã\82½ã\83¼ã\83\88
                                        this.env.wordRecognition.sortCandidateWordListByWordCount();
                                        this.env.wordRecognition.computeEachWordLevel();
                                        this.env.wordRecognition.sortCandidateWordListByWordLevel();
+                                       this.env.wordRecognition.cleanCandidateWordList();
                                        break;
                                }
                                if(this.env.input.lastSentenceSourceType){
@@ -30,12 +38,23 @@ AI_Think.prototype = {
                                        this.env.message("Unknown", true);
                                }
                                this.env.message("> " + s + "\n", true);
-                               
-                               var separated = this.env.wordRecognition.splitByWord(s);
+                               //ここで単語候補抽出を行っておく
+                               this.env.wordRecognition.slideLookUpCandidateWordByHistory(s);
+                               //分割
+                               separated = this.env.wordRecognition.splitByWord(s);
                                this.env.debug("[" + separated.join(" ") + "]\n");
-                               
+                               separated_UUID = this.env.wordRecognition.getUUIDListFromSeparatedString(separated);
+                               //分割の結果、未定義文字列と判別された部分を候補単語から探し、候補単語にあれば、その出現回数を+100する。
+                               for(var i = 0, iLen = separated_UUID.length;i < iLen; i++){
+                                       if(separated_UUID[i] == this.env.UUID_Meaning_UndefinedString){
+                                               t = this.env.wordRecognition.getCandidateWordTagByString(separated[i]);
+                                               if(t){
+                                                       t.wordCount += 100;
+                                               }
+                                       }
+                               }
                                //パターン照合
-                               this.checkPattern(separated);
+                               this.checkPattern(separated, separated_UUID);
                                
                                //ジョブに入力
                                if(this.processingJob && this.processingJob.input(s) === undefined){
@@ -51,8 +70,8 @@ AI_Think.prototype = {
                        }
                }
        },
-       checkPattern: function(separated){
-               var separated_UUID = this.env.wordRecognition.getUUIDListFromSeparatedString(separated);
+       checkPattern: function(separated, separated_UUID){
+               //可変長の部分を含むパターンは、
                this.env.debug("[\n" + separated_UUID.join("\n") + "\n]\n");
                var pList = this.env.memory.patternList.copy();
                
@@ -62,23 +81,28 @@ AI_Think.prototype = {
                
                for(var i = 0, iLen = pList.length; i < iLen; i++){
                        var p = pList[i].pattern;
-                       //単純完全一致
-                       if(separated_UUID.length != p.length){
-                               pList.removeByIndex(i);
-                               i--;
-                               iLen--;
-                       } else{
-                               for(var j = 0, jLen = separated_UUID.length; j < jLen; j++){
-                                       if(p[j] != separated_UUID[j]){
-                                               pList.removeByIndex(i);
-                                               i--;
-                                               iLen--;
-                                               break;
+                       if(p instanceof Function){
+                               if(pList[i].pattern(separated, separated_UUID)){
+                                       continue;
+                               }
+                       } else if(p instanceof Array){
+                               //単純完全一致
+                               if(separated_UUID.length == p.length){
+                                       for(var j = 0, jLen = separated_UUID.length; j < jLen; j++){
+                                               if(p[j] != separated_UUID[j]){
+                                                       break;
+                                               }
+                                       }
+                                       if(j == jLen){
+                                               continue;
                                        }
                                }
                        }
+                       pList.removeByIndex(i);
+                       i--;
+                       iLen--;
                }
-               
+               //マッチしたパターンに設定された関数の呼び出し
                for(var i = 0, iLen = pList.length; i < iLen; i++){
                        var p = pList[i];
                        if(p.func){