4 // /Applications/Google\ Chrome.app/ --allow-file-access-from-files --disable-web-security
6 var IsDebugModeEnabledOnBoot = true;
8 function AI(messageBoxDOMObject, debugBoxDOMObject){
12 this.input = new AI_Input(this);
13 this.wordRecognition = new AI_WordRecognition(this);
14 this.IOManager = new AI_IOManager(this);
15 this.networkManager = new AI_NetworkManager(this);
16 this.memory = new AI_Memory(this);
17 this.think = new AI_Think(this);
20 this.tickTimer = window.setInterval(function(){that.tick();}, 100);;
21 this.messageBox = null;
22 this.messageBoxBuffer = "";
23 this.maxMessageStringLength = 0xffff;
25 this.debugBoxBuffer = "";
26 this.maxDebugStringLength = 0xffff;
27 this.downloadBox = null;
29 this.setMessageBoxDOMObject(messageBoxDOMObject);
30 this.setDebugBoxDOMObject(debugBoxDOMObject);
32 this.UUID_Mode_Standard,
33 this.UUID_Mode_ReadMemory,
34 this.UUID_Mode_SaveMemory,
35 this.UUID_Mode_InternalConsole,
36 this.UUID_Mode_CompileELCHNOS_OSECPU,
38 this.modeProcessList = [
39 this.inputProcess_Standard,
40 this.inputProcess_ReadMemory,
41 this.inputProcess_SaveMemory,
42 this.inputProcess_InternalConsole,
43 this.inputProcess_CompileELCHNOS_OSECPU,
45 if(!IsDebugModeEnabledOnBoot){
46 this.mode = this.UUID_Mode_Standard;
47 this.processByMode = this.inputProcess_Standard;
49 this.mode = this.UUID_Mode_InternalConsole;
50 this.processByMode = this.inputProcess_InternalConsole;
56 this.debug("AI system initialized.\n");
57 this.debug("To enter internal console mode,\n type '#4ca6ed1a-e62e-470b-9d7b-e332f709e48f'.\n");
61 UUID_Mode_Standard: "1186f6f2-c7c4-4532-8f8f-c7dea883825f",
62 UUID_Mode_ReadMemory: "42e11880-62b8-46ea-a1c4-481264d4440d",
63 UUID_Mode_SaveMemory: "52360c62-6a8a-4f6e-8bdd-43381996e996",
64 UUID_Mode_InternalConsole: "4ca6ed1a-e62e-470b-9d7b-e332f709e48f",
65 UUID_Mode_CompileELCHNOS_OSECPU: "17ddde48-7d4c-498f-98d8-3e73f8845028",
66 UUID_Meaning_UndefinedString : "f9080ed9-1fd4-4982-a979-092d1852298a",
67 UUID_Meaning_UndefinedStrings : "24393cc6-e6c6-4da2-ae19-8e74ff71d390",
68 sendToAI: function(str, srctype){
71 this.debug("**** Start inputting ****\n");
74 var ary = str.split("#");
76 p = -(this.UUIDStrLen + 1);
78 strbaseindex = p + 1 + this.UUIDStrLen;
79 p = str.indexOf("#", strbaseindex);
83 this.processByMode(str.substring(strbaseindex), srctype);
86 //まずはモード変更の直前までの文字列を入力
87 this.processByMode(str.substring(strbaseindex, p), srctype);
89 this.changeMode(str.substring(p + 1, p + 1 + this.UUIDStrLen));
92 this.debug("**** End inputting ****\n");
94 changeMode: function(modeUUIDStr){
95 for(var i = 0, iLen = this.modeList.length; i < iLen; i++){
96 if(this.modeList[i] == modeUUIDStr){
100 if(this.modeList.length <= i){
101 this.debug("Unknown mode-UUID. Mode was NOT changed.\n");
104 if(this.modeList[i] === this.UUID_Mode_SaveMemory){
105 this.debug("Mode exectute for this once.\n uuid:" + this.modeList[i] + "\n");
106 this.modeProcessList[i].call(this);
108 this.debug("Mode changed\n from:" + this.mode + "\n to :" + this.modeList[i] + "\n");
109 this.mode = this.modeList[i];
110 this.processByMode = this.modeProcessList[i];
114 sendTextFromFileToAI: function(str, name, modDate, srctype){
115 //ファイルからの読み込み時は、読み込み終了後に読み込み以前のモードに戻る。
116 this.debug("sendTextFromFileToAI:");
118 this.debug(modDate.toLocaleString());
120 this.debug(" [" + name + "]\n");
121 var oldmode = this.mode;
122 this.sendToAI(str, srctype);
123 this.changeMode(oldmode);
125 setMessageBoxDOMObject: function(mBoxObj){
126 this.messageBox = mBoxObj;
128 setDebugBoxDOMObject: function(dBoxObj){
129 this.debugBox = dBoxObj;
131 message: function(str, noPrefix){
134 this.messageBoxBuffer += "AI> " + str;
136 this.messageBoxBuffer += str;
140 debug: function(str){
142 this.debugBoxBuffer += str;
149 if(this.messageBox && this.messageBoxBuffer != ""){
151 var str = this.messageBox.value + this.messageBoxBuffer;
152 this.messageBoxBuffer = "";
153 if(str.length > this.maxMessageStringLength){
154 str = str.slice(str.length - (this.maxMessageStringLength >> 1));
156 this.messageBox.value = str;
157 this.messageBox.scrollTop = this.messageBox.scrollHeight;
159 if(this.debugBox && this.debugBoxBuffer != ""){
161 var str = this.debugBox.value + this.debugBoxBuffer;
162 this.debugBoxBuffer = "";
163 if(str.length > this.maxDebugStringLength){
164 str = str.slice(str.length - (this.maxDebugStringLength >> 1));
166 this.debugBox.value = str;
167 this.debugBox.scrollTop = this.debugBox.scrollHeight;
170 checkBrowser: function(){
172 this.message("System> このブラウザは記憶保存(HTML5FileAPI)に対応していません。", true);
175 inputProcess_Standard: function(str, srctype){
176 this.debug("**** Start Processing (Standard) ****\n");
178 this.debug("input:[" + str + "]\n");
179 this.input.appendInput(str, srctype);
181 this.debug("**** End Processing (Standard) ****\n");
183 inputProcess_ReadMemory: function(str, srctype){
184 this.debug("**** Start Processing (ReadMemory) ****\n");
186 this.memory.loadMemory(str);
188 this.debug("**** End Processing (ReadMemory) ****\n");
190 inputProcess_SaveMemory: function(str, srctype){
191 this.debug("**** Start Processing (SaveMemory) ****\n");
193 this.memory.saveMemory();
195 this.debug("**** End Processing (SaveMemory) ****\n");
197 inputProcess_InternalConsole: function(str, srctype){
199 this.debug("**** Start Processing (InternalConsole) ****\n");
201 this.debug("Exit InternalConsole.\n");
202 this.changeMode(this.UUID_Mode_Standard);
203 } else if(str == "show cwl"){
204 //show candidateWordList
205 this.wordRecognition.debugShowCandidateWordList();
206 } else if(str == "show wl"){
208 this.debug("wordList:" + this.memory.wordList.length + "\n" );
209 this.memory.wordList.logEachPropertyNamed("str", function(s){ that.debug(s); });
210 } else if(str == "show rlc"){
212 this.debug(this.memory.dbInfo.readLineCount + " lines was inputted.\n" );
213 } else if(str.indexOf("inputFromURL ") == 0){
215 //inputFromURL http://www.aozora.gr.jp/cards/000148/files/773_14560.html
216 //inputFromURL http://www.aozora.gr.jp/cards/000035/files/1567_14913.html
217 //inputFromURL http://www.aozora.gr.jp/cards/000148/files/752_14964.html
218 //inputFromURL http://www.aozora.gr.jp/cards/000035/files/301_14912.html
219 //inputFromURL http://www.aozora.gr.jp/cards/000160/files/3368_25725.html
220 //inputFromURL http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8
221 //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
222 //inputFromURL http://osecpu.osask.jp/wiki/?FrontPage
223 //inputFromURL http://osecpu.osask.jp/wiki/?impressions
225 var url = str.substring(13);
226 this.debug("[" + url + "]\n");
227 var res = this.networkManager.sendRequestThroughPHPSync("GET", url, null);
228 //this.debug("[" + res + "]\n");
229 var parser = new AI_HTMLParser(this);
230 parser.loadText(res);
231 var mainString = parser.mainString;
232 this.debug(mainString);
233 console.log(parser.linkList);
235 this.changeMode(this.UUID_Mode_Standard);
236 this.sendTextFromFileToAI(mainString, url, null, "Web");
237 this.changeMode(this.UUID_Mode_InternalConsole);
239 } else if(str == "savemem"){
240 this.memory.saveMemory();
241 } else if(str == "netDB update"){
242 this.networkManager.networkDBUpdate();
243 } else if(str == "netDB viewall"){
244 this.networkManager.networkDBViewAll();
246 this.debug("Unknown command [" + str + "].\n");
247 this.debug("Command list:\n");
248 this.debug("Implemented command list:\n");
249 this.debug(" show cwl\n");
250 this.debug(" show wl\n");
251 this.debug(" exit\n");
254 this.debug("**** End Processing (InternalConsole) ****\n");
256 inputProcess_CompileELCHNOS_OSECPU: function(str, srctype){
257 this.debug("**** Start Processing (CompileELCHNOS_OSECPU) ****\n");
260 var cc = new ELCHNOSCompiler(function(s){ that.debug(s); }, this.downloadBox);
261 if(cc.compile(str) != null){
265 this.debug("**** End Processing (CompileELCHNOS_OSECPU) ****\n");