4 // /Applications/Google\ Chrome.app/ --allow-file-access-from-files --disable-web-security
6 var DebugModeEnabled = 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(!DebugModeEnabled){
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;
55 this.debug("AI system initialized.\n");
56 this.debug("To enter internal console mode,\n type '#4ca6ed1a-e62e-470b-9d7b-e332f709e48f'.\n");
60 UUID_Mode_Standard: "1186f6f2-c7c4-4532-8f8f-c7dea883825f",
61 UUID_Mode_ReadMemory: "42e11880-62b8-46ea-a1c4-481264d4440d",
62 UUID_Mode_SaveMemory: "52360c62-6a8a-4f6e-8bdd-43381996e996",
63 UUID_Mode_InternalConsole: "4ca6ed1a-e62e-470b-9d7b-e332f709e48f",
64 UUID_Mode_CompileELCHNOS_OSECPU: "17ddde48-7d4c-498f-98d8-3e73f8845028",
65 UUID_Meaning_UndefinedString : "f9080ed9-1fd4-4982-a979-092d1852298a",
66 UUID_Meaning_UndefinedStrings : "24393cc6-e6c6-4da2-ae19-8e74ff71d390",
67 sendToAI: function(str, srctype){
70 this.debug("**** Start inputting ****\n");
73 var ary = str.split("#");
75 p = -(this.UUIDStrLen + 1);
77 strbaseindex = p + 1 + this.UUIDStrLen;
78 p = str.indexOf("#", strbaseindex);
82 this.processByMode(str.substring(strbaseindex), srctype);
85 //まずはモード変更の直前までの文字列を入力
86 this.processByMode(str.substring(strbaseindex, p), srctype);
88 this.changeMode(str.substring(p + 1, p + 1 + this.UUIDStrLen));
91 this.debug("**** End inputting ****\n");
93 changeMode: function(modeUUIDStr){
94 for(var i = 0, iLen = this.modeList.length; i < iLen; i++){
95 if(this.modeList[i] == modeUUIDStr){
99 if(this.modeList.length <= i){
100 this.debug("Unknown mode-UUID. Mode was NOT changed.\n");
103 if(this.modeList[i] === this.UUID_Mode_SaveMemory){
104 this.debug("Mode exectute for this once.\n uuid:" + this.modeList[i] + "\n");
105 this.modeProcessList[i].call(this);
107 this.debug("Mode changed\n from:" + this.mode + "\n to :" + this.modeList[i] + "\n");
108 this.mode = this.modeList[i];
109 this.processByMode = this.modeProcessList[i];
113 sendTextFromFileToAI: function(str, name, modDate, srctype){
114 //ファイルからの読み込み時は、読み込み終了後に読み込み以前のモードに戻る。
115 this.debug("sendTextFromFileToAI:");
117 this.debug(modDate.toLocaleString());
119 this.debug(" [" + name + "]\n");
120 var oldmode = this.mode;
121 this.sendToAI(str, srctype);
122 this.changeMode(oldmode);
124 setMessageBoxDOMObject: function(mBoxObj){
125 this.messageBox = mBoxObj;
127 setDebugBoxDOMObject: function(dBoxObj){
128 this.debugBox = dBoxObj;
130 message: function(str, noPrefix){
133 this.messageBoxBuffer += "AI> " + str;
135 this.messageBoxBuffer += str;
139 debug: function(str){
141 this.debugBoxBuffer += str;
148 if(this.messageBox && this.messageBoxBuffer != ""){
150 var str = this.messageBox.value + this.messageBoxBuffer;
151 this.messageBoxBuffer = "";
152 if(str.length > this.maxMessageStringLength){
153 str = str.slice(str.length - (this.maxMessageStringLength >> 1));
155 this.messageBox.value = str;
156 this.messageBox.scrollTop = this.messageBox.scrollHeight;
158 if(this.debugBox && this.debugBoxBuffer != ""){
160 var str = this.debugBox.value + this.debugBoxBuffer;
161 this.debugBoxBuffer = "";
162 if(str.length > this.maxDebugStringLength){
163 str = str.slice(str.length - (this.maxDebugStringLength >> 1));
165 this.debugBox.value = str;
166 this.debugBox.scrollTop = this.debugBox.scrollHeight;
169 checkBrowser: function(){
171 this.message("System> このブラウザは記憶保存(HTML5FileAPI)に対応していません。", true);
174 inputProcess_Standard: function(str, srctype){
175 this.debug("**** Start Processing (Standard) ****\n");
177 this.debug("input:[" + str + "]\n");
178 this.input.appendInput(str, srctype);
180 this.debug("**** End Processing (Standard) ****\n");
182 inputProcess_ReadMemory: function(str, srctype){
183 this.debug("**** Start Processing (ReadMemory) ****\n");
185 this.memory.loadMemory(str);
187 this.debug("**** End Processing (ReadMemory) ****\n");
189 inputProcess_SaveMemory: function(str, srctype){
190 this.debug("**** Start Processing (SaveMemory) ****\n");
192 this.memory.saveMemory();
194 this.debug("**** End Processing (SaveMemory) ****\n");
196 inputProcess_InternalConsole: function(str, srctype){
198 this.debug("**** Start Processing (InternalConsole) ****\n");
200 this.debug("Exit InternalConsole.\n");
201 this.changeMode(this.UUID_Mode_Standard);
202 } else if(str == "show cwl"){
203 //show candidateWordList
204 this.wordRecognition.debugShowCandidateWordList();
205 } else if(str == "show wl"){
207 this.debug("wordList:" + this.memory.wordList.length + "\n" );
208 this.memory.wordList.logEachPropertyNamed("str", function(s){ that.debug(s); });
209 } else if(str.indexOf("inputFromURL ") == 0){
211 //inputFromURL http://www.aozora.gr.jp/cards/000148/files/773_14560.html
212 //inputFromURL http://www.aozora.gr.jp/cards/000035/files/1567_14913.html
213 //inputFromURL http://www.aozora.gr.jp/cards/000148/files/752_14964.html
214 //inputFromURL http://www.aozora.gr.jp/cards/000035/files/301_14912.html
215 //inputFromURL http://www.aozora.gr.jp/cards/000160/files/3368_25725.html
216 //inputFromURL http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8
217 //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
218 //inputFromURL http://osecpu.osask.jp/wiki/?FrontPage
219 //inputFromURL http://osecpu.osask.jp/wiki/?impressions
221 var url = str.substring(13);
222 this.debug("[" + url + "]\n");
223 var res = this.networkManager.sendRequestThroughPHPSync("GET", url, null);
224 //this.debug("[" + res + "]\n");
225 var parser = new AI_HTMLParser(this);
226 parser.loadText(res);
227 var mainString = parser.mainString;
228 this.debug(mainString);
229 console.log(parser.linkList);
231 this.changeMode(this.UUID_Mode_Standard);
232 this.sendTextFromFileToAI(mainString, url, null, "Web");
233 this.changeMode(this.UUID_Mode_InternalConsole);
235 } else if(str == "savemem"){
236 this.memory.saveMemory();
237 } else if(str == "netDB update"){
238 this.networkManager.networkDBUpdate();
239 } else if(str == "netDB viewall"){
240 this.networkManager.networkDBViewAll();
242 this.debug("Unknown command [" + str + "].\n");
243 this.debug("Command list:\n");
244 this.debug("Implemented command list:\n");
245 this.debug(" show cwl\n");
246 this.debug(" show wl\n");
247 this.debug(" exit\n");
250 this.debug("**** End Processing (InternalConsole) ****\n");
252 inputProcess_CompileELCHNOS_OSECPU: function(str, srctype){
253 this.debug("**** Start Processing (CompileELCHNOS_OSECPU) ****\n");
256 var cc = new ELCHNOSCompiler(function(s){ that.debug(s); }, this.downloadBox);
257 if(cc.compile(str) != null){
261 this.debug("**** End Processing (CompileELCHNOS_OSECPU) ****\n");