OSDN Git Service

5df630f244653a59c2632fa68f0d41a883c78f0e
[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         
19         //http://codedehitokoto.blogspot.jp/2012/01/javascriptuuid.html
20         initUUID: function(){
21                 if(!this.uuid){
22                         var f = this.initUUIDSub;
23                         this.uuid = f() + f() + "-" + 
24                                                 f() + "-" + 
25                                                 f() + "-" + 
26                                                 f() + "-" + 
27                                                 f() + f() + f();
28                 }
29         },
30         initUUIDSub: function(){
31                 return (((1 + Math.random()) * 0x10000) | 0).toString(16).toLowerCase().substring(1);
32         },
33         parseToStringData: function(data){
34                 //uuid:type:
35                 var d = new Object();
36                 //
37                 d.id = this.uuid;
38                 d.type = this.type;
39                 d.cDate = this.createdDate.toUTCString();
40                 //
41                 d.data = data;
42                 //
43                 return this.parseArrayToStringSource(d);
44         },
45         loadFromMemoryData: function(data){
46                 this.uuid = data.id;
47                 this.type = data.type;
48                 this.createdDate = new Date(data.cDate);
49                 if(data.data){
50                         if(this.loadFromMemoryData != AI_MemoryTag.prototype.loadFromMemoryData){
51                                 this.loadFromMemoryData(data.data);
52                         }
53                 }
54         },
55         parseArrayToStringSource: function(anArray){
56                 if(!anArray){
57                         return "null";
58                 }
59                 var srcstr = "var t=";
60                 srcstr += this.parseArrayToStringSourceSub(anArray);
61                 srcstr += ";t;";
62                 return srcstr;
63         },
64         parseArrayToStringSourceSub: function(anArray){
65                 if(!anArray){
66                         return "null";
67                 }
68                 var srcstr = "{";
69                 for(var k in anArray){
70                         var v = anArray[k];
71                         var t = Object.prototype.toString.call(v);
72                         if(v instanceof Array){
73                                 srcstr += k + ":" + this.parseArrayToStringSourceSub(v) + ",";
74                         } else if(!isNaN(v) && v.toString().replace(/\s+/g, "").length > 0){
75                                 //isNaNだけでは数値判定できないので、文字列化後の空白文字を削除した長さも検査している。
76                                 srcstr += k + ":" + v + ",";
77                         } else if(t == "[object String]"){
78                                 //文字列として変換
79                                 srcstr += k + ":'" + v + "',";
80                         } else if(t == "[object Object]"){
81                                 srcstr += k + ":" + this.parseArrayToStringSourceSub(v) + ",";
82                         } else{
83                                 srcstr += k + ":undefined,";
84                         }
85                 }
86                 if(srcstr.charAt(srcstr.length - 1) == ","){
87                         //最後の余計なカンマを削除
88                         srcstr = srcstr.slice(0, srcstr.length - 1);
89                 }
90                 srcstr += "}";
91                 return srcstr;
92         },
93 }