From 32320dcc0bb62e057545186825789fa22263668b Mon Sep 17 00:00:00 2001 From: hikarupsp Date: Sun, 2 Feb 2014 16:11:23 +0900 Subject: [PATCH] =?utf8?q?AI=E3=81=AEDB=E9=80=A3=E6=90=BA=E6=A9=9F?= =?utf8?q?=E8=83=BD=E3=82=92=E5=AE=9F=E8=A3=85=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ai.js | 4 + aimemtag.js | 2 + aimtbase.js | 2 + ainet.js | 25 ++++++ aiwrcgnz.js | 2 + dbmysql.php | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ elcc/elccide.html | 2 + webcpu/webcpu.js | 14 ++++ 8 files changed, 278 insertions(+) create mode 100644 dbmysql.php diff --git a/ai.js b/ai.js index 8bf3e29..6bbcde3 100644 --- a/ai.js +++ b/ai.js @@ -234,6 +234,10 @@ AI.prototype = { } else if(str == "savemem"){ this.memory.saveMemory(); + } else if(str == "netDB update"){ + this.networkManager.networkDBUpdate(); + } else if(str == "netDB viewall"){ + this.networkManager.networkDBViewAll(); } else{ this.debug("Unknown command [" + str + "].\n"); this.debug("Command list:\n"); diff --git a/aimemtag.js b/aimemtag.js index d0f659b..64c14ab 100644 --- a/aimemtag.js +++ b/aimemtag.js @@ -48,6 +48,7 @@ var AI_WordTag = function(str, uuid){ }); var AI_PatternTag = function(pattern, uuid, func){ + AI_PatternTag.base.call(this, AI_PatternTag.base.prototype.Type_Pattern); // p.func(this.env, separated, separated_UUID); //patternには関数も指定できる。その場合、関数の形式は //f(separated, separated_UUID)となる。戻り値がtrueの場合、パターンはマッチしたとみなされる @@ -67,6 +68,7 @@ var AI_PatternTag = function(pattern, uuid, func){ }); var AI_MeaningTag = function(uuid, description){ + AI_MeaningTag.base.call(this, AI_MeaningTag.base.prototype.Type_Meaning); if(description){ this.description = description; } diff --git a/aimtbase.js b/aimtbase.js index beca799..5df630f 100644 --- a/aimtbase.js +++ b/aimtbase.js @@ -13,6 +13,8 @@ function AI_MemoryTag(typeUUIDStr){ AI_MemoryTag.prototype = { Type_CandidateWord: "2fba8fc1-2b9a-46e0-8ade-455c0bd30637", Type_Word: "d5eef85c-a796-4d04-bb72-8d45c94c5e4f", + Type_Pattern: "8085e53e-0e99-4221-821c-057f38e35ed9", + Type_Meaning: "dec1789a-9200-4f9b-9248-177495f47f7d", //http://codedehitokoto.blogspot.jp/2012/01/javascriptuuid.html initUUID: function(){ diff --git a/ainet.js b/ainet.js index 34b09dd..75621fd 100644 --- a/ainet.js +++ b/ainet.js @@ -1,6 +1,7 @@ function AI_NetworkManager(env){ this.env = env; this.PHPExtPath = "./ainet.php"; + this.DBPHPPath = "./dbmysql.php"; } AI_NetworkManager.prototype = { //from PCD2013GSCL @@ -87,4 +88,28 @@ AI_NetworkManager.prototype = { sendURL += encodeURIComponent(url); return this.sendRequestSync("GET", sendURL); }, + networkDBUpdate: function(){ + //Upload + var cl = this.env.memory.root; + var k; + for(var i = 0, iLen = cl.length; i < iLen; i++){ + k = cl[i]; + if(k instanceof AI_MemoryTag){ + var sendURL = this.DBPHPPath; + sendURL += "?action=add"; + sendURL += "&uuid=" + k.uuid; + sendURL += "&typeid=" + k.type; + sendURL += "&desc=" + (k.str ? k.str : ""); + sendURL += "&data=" + k.parseToStringData(); + var res = this.sendRequestSync("GET", sendURL); + this.env.debug(res + "\n"); + } + } + }, + networkDBViewAll: function(){ + var sendURL = this.DBPHPPath; + sendURL += "?action=viewall"; + var res = this.sendRequestSync("GET", sendURL); + this.env.debug(res + "\n"); + }, } \ No newline at end of file diff --git a/aiwrcgnz.js b/aiwrcgnz.js index e09220d..027c130 100644 --- a/aiwrcgnz.js +++ b/aiwrcgnz.js @@ -64,12 +64,14 @@ AI_WordRecognition.prototype = { this.env.memory.removeMemoryTagByObject(this.env.memory.candidateWordList[i]); i--; iLen--; + continue; } if(this.env.memory.candidateWordList[i].wordLevel < 1){ this.env.debug("Too small wordLevel of candidateWord [" + this.env.memory.candidateWordList[i].str + "]. Removed.\n"); this.env.memory.removeMemoryTagByObject(this.env.memory.candidateWordList[i]); i--; iLen--; + continue; } } this.env.memory.candidateWordListLastCleanedDate = new Date(); diff --git a/dbmysql.php b/dbmysql.php new file mode 100644 index 0000000..9b79d41 --- /dev/null +++ b/dbmysql.php @@ -0,0 +1,227 @@ +prepare(QUERY_SELECT_ALL_MTAG); + $stmt->execute(); + // + $stmt->store_result(); + if($stmt->errno != 0){ + responseError("A0518702-C90C-4785-B5EA-1A213DD0205B"); + } + + $stmt->bind_result($uuid, $typeid, $desc, $cts, $mts, $data); + while($stmt->fetch()){ + $uuid = strtolower($uuid); + echo('["'); + echo(getFormedUUIDString($uuid)); + echo('","'); + echo(getFormedUUIDString($typeid)); + echo('","'); + echo($desc); + echo('",'); + echo($cts); + echo(','); + echo($mts); + echo(',"'); + echo($data); + echo('"]'); + echo(PHP_EOL); + } + echo($stmt->num_rows); + $stmt->close(); + exit(" OK"); + } else if(strcmp($action, 'viewallhtml') == 0){ + $stmt = $db->prepare(QUERY_SELECT_ALL_MTAG); + $stmt->execute(); + // + $stmt->store_result(); + if($stmt->errno != 0){ + responseError("A0518702-C90C-4785-B5EA-1A213DD0205B"); + } + + $stmt->bind_result($uuid, $typeid, $desc, $cts, $mts, $data); + while($stmt->fetch()){ + $uuid = strtolower($uuid); + echo('["'); + echo(getFormedUUIDString($uuid)); + echo('","'); + echo(getFormedUUIDString($typeid)); + echo('","'); + echo($desc); + echo('",'); + echo($cts); + echo(','); + echo($mts); + //echo(',"'); + //echo($data); + //echo('"]'); + echo("
"); + } + echo($stmt->num_rows); + $stmt->close(); + exit(" OK"); + } else if(strcmp($action, 'add') == 0){ + if(isset($_GET['uuid'])){ + $uuid = $_GET['uuid']; + } else{ + responseError("A0518702-C90C-4785-B5EA-1A213DD0205B", "uuid needed."); + } + if(isset($_GET['typeid'])){ + $typeid = $_GET['typeid']; + } else{ + responseError("A0518702-C90C-4785-B5EA-1A213DD0205B", "typeid needed."); + } + if(isset($_GET['desc'])){ + $desc = $_GET['desc']; + } else{ + responseError("A0518702-C90C-4785-B5EA-1A213DD0205B", "desc needed."); + } + if(isset($_GET['data'])){ + $data = $_GET['data']; + } else{ + responseError("A0518702-C90C-4785-B5EA-1A213DD0205B", "data needed."); + } + $stmt = $db->prepare(QUERY_ADD_MTAG); + //$uuid = "12363456-96EC-4E56-BC1F-B58DD0A76161"; + //$typeid = "12323456-96EC-4E36-BC1F-B58DD0A76161"; + $mts = getTimeStampMs(); + //$desc = "aiueo"; + //$data = "[0]"; + $stmt->bind_param(QUERY_ADD_MTAG_TYPES, $uuid, $typeid, $desc, $mts, $mts, $data); + $stmt->execute(); + // + $stmt->store_result(); + if($stmt->errno != 0){ + responseError("A0518702-C90C-4785-B5EA-1A213DD0205B", mysqli_error($db)); + } + $stmt->close(); + exit("OK"); + } +} + +//NOP error +responseError("B539657C-0FA6-49C2-AFB0-13AF5C7866ED"); + +function responseError($errid, $description = "") +{ + die('["' . $errid .'","' . $description . '"]'); +} + +function connectDB() +{ + $db = new mysqli('localhost', DATABASE_USER, DATABASE_PWD, DATABASE_NAME); + + if (mysqli_connect_error()) { + // DB connect error + responseError("3A8CF3C8-E6B6-4A99-9134-343CA341B591", mysqli_connect_error()); + } + + // 文字化け防止 + $db->set_charset("utf8"); + + //データベース存在確認 + $stmt = $db->prepare("show tables"); + $stmt->execute(); + // + $stmt->store_result(); + if($stmt->errno != 0){ + responseError("80FA2D65-9473-40B0-A3CE-159AE8E67017"); + } + //テーブルの存在確認 + $stmt->bind_result($tablename); + $found = false; + while($stmt->fetch()){ + if($tablename == "MemoryTagRoot"){ + $found = true; + } + } + if(!$found){ + rebuildDB($db); + } + $stmt->close(); + + return $db; +} + +function rebuildDB($db) +{ + //すでにあるテーブルの削除 + //MemoryTagRoot + $stmt = $db->prepare("drop table if exists MemoryTagRoot"); + $stmt->execute(); + //エラーチェック省略 + $stmt->close(); + + //再構築 + $stmt = $db->prepare(QUERY_CREATE_TABLE_MEMORY_TAG_ROOT); + $stmt->execute(); + //エラーチェック省略 + $stmt->close(); +} + +function getFormedUUIDString($str) +{ + $str = strtolower($str); + return ( + substr($str, 0, 8) . "-" . + substr($str, 8, 4) . "-" . + substr($str, 12, 4) . "-" . + substr($str, 16, 4) . "-" . + substr($str, 20, 12) + ); +} + +function getTimeStampMs() +{ + return ceil(microtime(true)*1000); +} +?> \ No newline at end of file diff --git a/elcc/elccide.html b/elcc/elccide.html index 622dc27..5471a1a 100755 --- a/elcc/elccide.html +++ b/elcc/elccide.html @@ -149,6 +149,8 @@ function handleDragOver(evt){
+ +
diff --git a/webcpu/webcpu.js b/webcpu/webcpu.js index f610284..4d04fba 100755 --- a/webcpu/webcpu.js +++ b/webcpu/webcpu.js @@ -441,6 +441,20 @@ WebCPU.prototype = { this.message(" - - - - \n", 30); } }, + showIntegerRegister: function(){ + for(var i = 0; i < this.registers.Integer.length; i++){ + this.message("R" + ("00" + i.toString(16)).slice(-2).toUpperCase() + ":0x" + this.registers.Integer[i].toString(16).toUpperCase() + "\n"); + } + }, + showPointerRegister: function(){ + for(var i = 0; i < this.registers.Pointer.length; i++){ + if(this.registers.Pointer[i]){ + this.message("P" + ("00" + i.toString(16)).slice(-2).toUpperCase() + ":" + this.registers.Pointer[i].toString() + "\n"); + } else{ + this.message("P" + ("00" + i.toString(16)).slice(-2).toUpperCase() + ":(null)\n"); + } + } + }, refreshDebugIntegerRegisterText: function(){ if(this.debugIntegerRegisterText != null){ this.debugIntegerRegisterText.value = ""; -- 2.11.0