1 function AI_Memory(env){
5 this.root = new Array();
7 this.candidateWordList = new Array();
8 this.wordList = new Array();
10 AI_Memory.prototype = {
11 saveMemory: function(){
12 var m = this.env.IOManager;
13 var s = "#" + this.env.UUID_Mode_ReadMemory + "\n";
15 for(var i = 0, iLen = cl.length; i < iLen; i++){
16 if(cl[i] instanceof AI_MemoryTag){
17 s += cl[i].parseToStringData() + "\n";
20 var d = new Blob([s]);
22 m.showDownloadLink(d);
25 loadMemory: function(str){
28 this.env.debug("Memory loading...\n");
29 a = str.splitByArray(["\n"]);
31 for(var i = 1, iLen = a.length; i < iLen; i++){
35 this.env.debug(i + ": " + e + "\n");
42 if(q == AI_MemoryTag.prototype.Type_CandidateWord){
43 t = new AI_CandidateWordTag();
44 } else if(q == AI_MemoryTag.prototype.Type_Word){
47 t = new AI_MemoryTag();
49 AI_MemoryTag.prototype.loadFromMemoryData.call(t, d);
50 this.appendMemoryTag(t);
52 this.verifyMemoryStructure();
53 this.env.debug("Memory loading done.\n" + this.root.length + " tags exist.\n");
55 appendMemoryTag: function(tag){
56 //同じUUIDのタグがあった場合はデバッグ表示をして、新たなものに置き換える。
57 var s = this.root.isIncluded(tag, function(a, b){ return (a.uuid == b.uuid); });
59 this.env.debug("appendMemoryTag: duplicated UUID " + tag.uuid + ", overwritten.\n");
60 this.removeMemoryTagByObject(s);
64 //タグに合わせてそれぞれのサブリストに分配
65 if(tag instanceof AI_CandidateWordTag){
66 this.candidateWordList.push(tag);
68 if(tag instanceof AI_WordTag){
69 this.wordList.push(tag);
73 appendMemoryTagFromString: function(str){
81 this.env.debug(""i + ": " + e + "\n");
88 if(q == AI_MemoryTag.prototype.Type_CandidateWord){
89 t = new AI_CandidateWordTag();
91 t = new AI_MemoryTag();
93 AI_MemoryTag.prototype.loadFromMemoryData.call(t, d);
94 this.appendMemoryTag(t);
97 removeMemoryTagByObject: function(obj){
98 this.root.removeAnObject(obj);
99 this.candidateWordList.removeAnObject(obj);
100 this.wordList.removeAnObject(obj);
102 verifyMemoryStructure: function(){
104 //単語が単語候補に残っていた場合は単語候補から削除
105 for(var i = 0, iLen = this.wordList.length; i < iLen; i++){
106 var w = this.wordList[i].str;
107 for(var j = 0, jLen = this.candidateWordList.length; j < jLen; j++){
108 if(this.candidateWordList[j].str == w){
109 this.env.debug("Word duplicated in CWL. Remove.\n");
110 this.removeMemoryTagByObject(this.candidateWordList[j]);
116 this.env.debug("Memory verifying done.\n");