UUID_Mode_InternalConsole: "4ca6ed1a-e62e-470b-9d7b-e332f709e48f",
UUID_Mode_CompileELCHNOS_OSECPU: "17ddde48-7d4c-498f-98d8-3e73f8845028",
UUID_Meaning_UndefinedString : "f9080ed9-1fd4-4982-a979-092d1852298a",
+ UUID_Meaning_UndefinedStrings : "24393cc6-e6c6-4da2-ae19-8e74ff71d390",
sendToAI: function(str, srctype){
var p, strbaseindex;
this.memory.wordList.logEachPropertyNamed("str", function(s){ that.debug(s); });
} else if(str.indexOf("inputFromURL ") == 0){
//webページを読み込む
+ //inputFromURL http://www.aozora.gr.jp/cards/000148/files/773_14560.html
//inputFromURL http://www.aozora.gr.jp/cards/000035/files/1567_14913.html
//inputFromURL http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8
//inputFromURL http://ja.wikipedia.org/wiki/%E6%9D%B1%E4%BA%AC%E5%AD%A6%E8%8A%B8%E5%A4%A7%E5%AD%A6%E9%99%84%E5%B1%9E%E9%AB%98%E7%AD%89%E5%AD%A6%E6%A0%A1
//意味タグ
//
append(m(env.UUID_Meaning_UndefinedString, "未定義文字列"));
+ append(m(env.UUID_Meaning_UndefinedStrings, "未定義文字列を含む複数の文字列"));
//
//パターンタグ
//
//単語教示
+ /*
append(p([
env.UUID_Meaning_UndefinedString,
wid("は"),
}
}
));
-
+ */
+ append(p(
+ function(separated, separated_UUID){
+ if(separated.length < 5){
+ return false;
+ }
+ var a = separated.slice(-4);
+
+ return (a.join("") == "は単語です。");
+ },
+ "72d5f5b2-7943-4ea0-8a91-b2c84ed856f6",
+ function(env, separated, UUIDList){
+ var a = separated.slice(0, -4).join("");
+ if(env.memory.getUUIDFromWord(a) == env.UUID_Meaning_UndefinedString){
+ env.message("「" + a + "」は単語なんですね!\n");
+ env.memory.appendMemoryTag(new AI_WordTag(a));
+ env.message(env.memory.wordList.length + "個目の単語を登録しました!\n");
+ } else{
+ env.message("「" + a + "」が単語なのは知ってますよ…。\n");
+ }
+ }
+ ));
//記憶保存
append(p([
wid("記憶"),
//サブリスト
this.candidateWordList = new Array();
this.wordList = new Array();
+ this.wordListLastModifiedDate = new Date();
this.patternList = new Array();
}
AI_Memory.prototype = {
return;
}
this.wordList.push(tag);
+ this.wordListLastModifiedDate = new Date();
}
if(tag instanceof AI_PatternTag){
this.patternList.push(tag);
removeMemoryTagByObject: function(obj){
this.root.removeAnObject(obj);
this.candidateWordList.removeAnObject(obj);
- this.wordList.removeAnObject(obj);
+ if(this.wordList.removeAnObject(obj)){
+ this.wordListLastModifiedDate = new Date();
+ }
},
verifyMemoryStructure: function(){
//メモリ構造検査・修復
var AI_PatternTag = function(pattern, uuid, func){
// p.func(this.env, separated, separated_UUID);
+ //patternには関数も指定できる。その場合、関数の形式は
+ //f(separated, separated_UUID)となる。戻り値がtrueの場合、パターンはマッチしたとみなされる
if(pattern){
this.pattern = pattern;
}
}
}.extend(AI_MemoryTag, {
parseToStringData: function(){
-
+ //Not implemented.
},
});
}
}.extend(AI_MemoryTag, {
parseToStringData: function(){
-
+ //Not implemented.
},
});
this.sentenceList = new Array();
}
AI_Input.prototype = {
- maxHistoryLength: 16,
+ maxHistoryLength: 32,
sentenceSeparator: [
"。",
"!",
],
appendInput: function(input, srctype){
//inputはStringとArrayが使用できる
- var sList = input.splitByArray(this.sentenceSeparator);
+ var sList;
+ if(srctype != "User"){
+ sList = input.splitByArray(this.sentenceSeparator);
+ } else{
+ sList = [input];
+ }
console.log(sList);
this.sentenceList.push([srctype]);
this.sentenceList = this.sentenceList.concat(sList);
}
},
checkPattern: function(separated){
+ //可変長の部分を含むパターンは、
var separated_UUID = this.env.wordRecognition.getUUIDListFromSeparatedString(separated);
this.env.debug("[\n" + separated_UUID.join("\n") + "\n]\n");
var pList = this.env.memory.patternList.copy();
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){
function AI_WordRecognition(env){
this.env = env;
+ this.wordListCache = null;
+ this.wordListCacheLastModifiedDate = new Date();
}
AI_WordRecognition.prototype = {
slideLookUpCandidateWordByHistory: function(input){
//03:すでに単語と判明している候補を削除
var iLen = cList.length;
for(var i = 0; i < iLen; i++){
- if(this.env.memory.getUUIDFromWord(cList[i].str) == this.env.UUID_Meaning_UndefinedString){
+ if(this.env.memory.getUUIDFromWord(cList[i].str) != this.env.UUID_Meaning_UndefinedString){
cList.removeByIndex(i);
i--;
iLen--;
return a.wordLevel - b.wordLevel;
});
},
+ sortWordListByLength: function(){
+ //文字数の大きい方がリストの最初に来るようにする。
+ this.env.memory.wordList.stableSort(function(a, b){
+ return b.str.length - a.str.length;
+ });
+ },
computeWordLevel: function(strTag){
var s = strTag.str;
var iLen = s.length;
}
},
splitByWord: function(s){
- var separatorList = this.env.memory.wordList.propertiesNamed("str");
- separatorList.stableSort(function(a, b){
- return a.length - b.length;
- });
- return s.splitByArraySeparatorSeparated(separatorList);
+ if(!this.wordListCache || this.wordListCacheLastModifiedDate < this.env.memory.wordListLastModifiedDate){
+ //キャッシュが存在しないか古い場合、元のリストをソートしてからキャッシュを作成
+ this.sortWordListByLength();
+ this.wordListCache = this.env.memory.wordList.propertiesNamed("str");
+ this.wordListCacheLastModifiedDate = new Date();
+ }
+ return s.splitByArraySeparatorSeparatedLong(this.wordListCache);
},
getUUIDListFromSeparatedString: function(separated){
var retv = new Array();
//console.log("x:" + loc.x);
//console.log("y:" + loc.y);
};
+ //ファイルの入力を受け付ける場合はコメントを外す
+ //this.canvas.addEventListener('dragover', function(evt){ return that.handleDragOver(evt); }, false);
+ //this.canvas.addEventListener('drop', function(evt){ return that.handleFileSelect(evt); }, false);
}
MGCanvas.prototype = {
setGraph: function(gArray){
this.context.translate(w, h);
this.displayRect = new Rectangle(-w, -h, this.canvas.width, this.canvas.height);
},
+ loadAIMemory: function(str){
+ console.log(str);
+ },
+ // http://www.html5rocks.com/ja/tutorials/file/dndfiles/
+ handleFileSelect: function(evt){
+ evt.stopPropagation();
+ evt.preventDefault();
+
+ var files = evt.dataTransfer.files; // FileList object.
+ var that = this;
+
+ // files is a FileList of File objects. List some properties.
+ var output = [];
+ for(var i = 0, f; f = files[i]; i++){
+ var r = new FileReader();
+ r.onload = (function(file){
+ return function(e){
+ //mainAI.sendTextFromFileToAI(r.result, file.name, file.lastModifiedDate, "File");
+ that.loadAIMemory(r.result);
+ }
+ })(f);
+ r.readAsText(f);
+ }
+ },
+ handleDragOver: function(evt){
+ evt.stopPropagation();
+ evt.preventDefault();
+ evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
+ },
}
function MGNode(env, identifier){