OSDN Git Service

ノード識別子の変更ができるようになった。
[chnosproject/AI004.git] / aimtbase.js
1 function AI_MemoryTag(typeUUIDStr){
2         //保存対象
3         this.uuid = null;
4         this.type = typeUUIDStr;
5         this.createdDate = new Date();
6         
7         //内部データ(保存されない)
8         //this.isBootstrap = false;     //上書き警告抑制用
9         
10         //初期化
11         this.initUUID();
12 }
13 AI_MemoryTag.prototype = {
14         Type_CandidateWord: "2fba8fc1-2b9a-46e0-8ade-455c0bd30637",
15         Type_Word: "d5eef85c-a796-4d04-bb72-8d45c94c5e4f",
16         Type_Pattern: "8085e53e-0e99-4221-821c-057f38e35ed9",
17         Type_Meaning: "dec1789a-9200-4f9b-9248-177495f47f7d",
18         Type_DatabaseInfo: "4e7b3a3e-bb8c-4315-b3d0-6b25f9aead61",
19         
20         //http://codedehitokoto.blogspot.jp/2012/01/javascriptuuid.html
21         initUUID: function(){
22                 if(!this.uuid){
23                         var f = this.initUUIDSub;
24                         this.uuid = f() + f() + "-" + 
25                                                 f() + "-" + 
26                                                 f() + "-" + 
27                                                 f() + "-" + 
28                                                 f() + f() + f();
29                 }
30         },
31         initUUIDSub: function(){
32                 return (((1 + Math.random()) * 0x10000) | 0).toString(16).toLowerCase().substring(1);
33         },
34         parseToStringData: function(data){
35                 //uuid:type:
36                 var d = new Object();
37                 //
38                 d.id = this.uuid;
39                 d.type = this.type;
40                 d.cDate = this.createdDate.toUTCString();
41                 //
42                 d.data = data;
43                 //
44                 return this.parseArrayToStringSource(d);
45         },
46         loadFromMemoryData: function(data){
47                 this.uuid = data.id;
48                 this.type = data.type;
49                 this.createdDate = new Date(data.cDate);
50                 if(data.data){
51                         if(this.loadFromMemoryData != AI_MemoryTag.prototype.loadFromMemoryData){
52                                 this.loadFromMemoryData(data.data);
53                         }
54                 }
55         },
56         parseArrayToStringSource: function(anArray){
57                 if(!anArray){
58                         return "null";
59                 }
60                 var srcstr = "var t=";
61                 srcstr += this.parseArrayToStringSourceSub(anArray);
62                 srcstr += ";t;";
63                 return srcstr;
64         },
65         parseArrayToStringSourceSub: function(anArray){
66                 if(!anArray){
67                         return "null";
68                 }
69                 var srcstr = "{";
70                 for(var k in anArray){
71                         var v = anArray[k];
72                         var t = Object.prototype.toString.call(v);
73                         if(v instanceof Array){
74                                 srcstr += k + ":" + this.parseArrayToStringSourceSub(v) + ",";
75                         } else if(!isNaN(v) && v.toString().replace(/\s+/g, "").length > 0){
76                                 //isNaNだけでは数値判定できないので、文字列化後の空白文字を削除した長さも検査している。
77                                 srcstr += k + ":" + v + ",";
78                         } else if(t == "[object String]"){
79                                 //文字列として変換
80                                 srcstr += k + ":'" + v + "',";
81                         } else if(t == "[object Object]"){
82                                 srcstr += k + ":" + this.parseArrayToStringSourceSub(v) + ",";
83                         } else{
84                                 srcstr += k + ":undefined,";
85                         }
86                 }
87                 if(srcstr.charAt(srcstr.length - 1) == ","){
88                         //最後の余計なカンマを削除
89                         srcstr = srcstr.slice(0, srcstr.length - 1);
90                 }
91                 srcstr += "}";
92                 return srcstr;
93         },
94 }