visuddhinanda 5 лет назад
Родитель
Сommit
39b7edd8a5

+ 9 - 3
app/dict/split.php

@@ -7,7 +7,7 @@ require_once "../path.php";
 require_once "../public/_pdo.php";
 
 if(isset($_POST["word"])){
-	$input_word=mb_strtolower($_POST["word"],'UTF-8');
+	$input_word=mb_strtolower(trim($_POST["word"]),'UTF-8');
 	if(trim($input_word)==""){
 		echo "Empty";
 	return;
@@ -27,7 +27,7 @@ Words: <textarea type="text" name="word"></textarea>
 	return;
 }
 global $dbh;
-$dns = "sqlite:"._FILE_DB_part_;
+$dns = "sqlite:"._FILE_DB_PART_;
 $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
@@ -420,7 +420,13 @@ function mySplit2($strWord,$deep,$express=false,$adj_len=0,$c_threshhold=0.8){
 		}
 		$len=pow(mb_strlen($strWord,"UTF-8"),3);
 		$cf+=(0-$len)/($len+150);
-		$word .= "{$strWord}(0)";
+		if(isset($_POST["debug"])){
+			$word .= $strWord."(0)";
+		}
+		else{
+			$word .= $strWord;
+		}
+		
 		$result[$word]=$cf;
 	}
 }

+ 72 - 0
app/install/refdict_db/ref.sql

@@ -0,0 +1,72 @@
+--
+-- 由SQLiteStudio v3.1.1 产生的文件 周三 8月 5 15:10:22 2020
+--
+-- 文本编码:UTF-8
+--
+PRAGMA foreign_keys = off;
+BEGIN TRANSACTION;
+
+-- 表:dict
+DROP TABLE IF EXISTS dict;
+
+CREATE TABLE dict (
+    id       INTEGER PRIMARY KEY AUTOINCREMENT
+                     UNIQUE,
+    language TEXT,
+    dict_id  INTEGER,
+    eword    TEXT,
+    word     TEXT,
+    paliword TEXT,
+    mean     TEXT,
+    length   INTEGER,
+    status   INTEGER DEFAULT (1) 
+);
+
+
+-- 表:info
+DROP TABLE IF EXISTS info;
+
+CREATE TABLE info (
+    language  TEXT,
+    id        INTEGER PRIMARY KEY
+                      NOT NULL,
+    shortname TEXT,
+    name      TEXT
+);
+
+
+-- 索引:eword
+DROP INDEX IF EXISTS eword;
+
+CREATE INDEX eword ON dict (
+    "eword" ASC
+);
+
+
+-- 索引:len
+DROP INDEX IF EXISTS len;
+
+CREATE INDEX len ON dict (
+    "length" ASC
+);
+
+
+-- 索引:word
+DROP INDEX IF EXISTS word;
+
+CREATE INDEX word ON dict (
+    "word" ASC
+);
+
+
+-- 视图:語法彙編
+DROP VIEW IF EXISTS 語法彙編;
+CREATE VIEW 語法彙編 AS
+    SELECT *
+      FROM dict
+     WHERE dict_id = 32;
+
+
+COMMIT TRANSACTION;
+VACUUM;
+PRAGMA foreign_keys = on;

+ 32 - 0
app/install/refdict_db/ref_index.sql

@@ -0,0 +1,32 @@
+--
+-- 由SQLiteStudio v3.1.1 产生的文件 周三 8月 5 15:11:23 2020
+--
+-- 文本编码:UTF-8
+--
+PRAGMA foreign_keys = off;
+BEGIN TRANSACTION;
+
+-- 表:dict
+DROP TABLE IF EXISTS dict;
+
+CREATE TABLE dict (
+    id     INTEGER,
+    eword  TEXT,
+    word   TEXT,
+    length INTEGER,
+    count  INTEGER
+);
+
+
+-- 索引:search
+DROP INDEX IF EXISTS search;
+
+CREATE INDEX search ON dict (
+    eword,
+    word
+);
+
+
+COMMIT TRANSACTION;
+VACUUM;
+PRAGMA foreign_keys = on;

+ 108 - 18
app/install/step3.php

@@ -1,33 +1,64 @@
 <?php
 require_once '../pcdl/html_head.php';
 ?>
-
 <body>
 <style>
 #step3{
 	background-color: #f1e7a4;
 }
+body{
+    font-size:unset;
+}
 </style>
 <?php
 require_once 'nav_bar.php';
 ?>
-<h3>Step 3 Dictionary</h3>
 <div style="margin:1em;background-color:#f1e7a4;">
-生成字典数据库。约需要10分钟。您可以从网络下载已经生成好的数据库。
-<a href="https://www.dropbox.com/s/naf7sk9i9sf0dfi/appdata.7z?dl=0">drobox 7z format 754MB</a>
-解压缩后放在项目目录中
-<pre>
-[project dir]
- └app
- └appdata
-   └dict
-     └3rd
-     └system
-   └palicanon
- └user 
- </pre>
+生成字典数据库。约需要10分钟。
 </div>
+<div>
+<?php
+$dbfile[]=array(_FILE_DB_REF_,"ref.sql");
+$dbfile[]=array(_FILE_DB_REF_INDEX_,"ref_index.sql");
+$dir="./refdict_db/";
+
+if(isset($_GET["index"])){
+echo '<div style="padding:10px;margin:5px;border-bottom: 1px solid gray;background-color:yellow;">';	
+	$index = $_GET["index"];
+	$dns = "sqlite:".$dbfile[$index][0];
+	$dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+	//建立数据库
+	$_sql = file_get_contents($dir.$dbfile[$index][1]);
+	$_arr = explode(';', $_sql);
+	//执行sql语句
+	foreach ($_arr as $_value) {
+		$dbh->query($_value.';');
+	}
+	echo $dns."建立数据库成功";
+echo "</div>"; 
+}
 
+
+for($i=0; $i<count($dbfile); $i++){
+	$db = $dbfile[$i];
+	echo '<div style="padding:10px;margin:5px;border-bottom: 1px solid gray;display:flex;">';
+	echo '<div style="flex:5;">'.$db[0].'</div>';
+	echo '<div style="flex:3;">';
+	if(!file_exists($db[0])){
+        echo "<span style='color:red;'>数据库不存在</span>";
+    	echo "</div>"; 
+        echo '<div style="flex:2;"><a href="step3.php?index='.$i.'">建立</a></div>';    
+	}
+	else{
+        echo "<span style='color:green;'>已存在</span>";
+    	echo "</div>"; 
+        echo '<div style="flex:2;"><a href="step3.php?index='.$i.'">重建</a><span style="color:red;">注意!此操作将删除原数据库中所有数据!</span></div>';
+    }
+	echo "</div>";  
+}
+?>
+</div>
 <div id="response"></div>
 <script>
 <?php
@@ -51,7 +82,7 @@ echo "var sys_file_list = new Array();\n";
 $filelist = array();
 if(($handle=fopen(_DIR_DICT_TEXT_.'/system/list.txt','r'))!==FALSE){
 	while(($data=fgetcsv($handle,0,','))!==FALSE){
-        $filelist[] = $data;     
+        $filelist[] = $data; 
 	}
 }
 else{
@@ -63,6 +94,22 @@ foreach($filelist as $value){
 
 }
 
+echo "var thin_file_list = new Array();\n";
+$filelist = array();
+if(($handle=fopen(_DIR_DICT_TEXT_.'/thin/list.csv','r'))!==FALSE){
+	while( ($data=fgetcsv($handle,0 , ',' ) )!==FALSE){
+        $filelist[] = $data; 
+	}
+}
+else{
+    exit("无法打开thin文件列表");
+}
+
+foreach($filelist as $value){
+    echo "thin_file_list.push(['{$value[0]}','{$value[1]}','{$value[2]}']);\n";
+
+}
+
 ?>
 var iCurrRichDictIndex = 0;
 var iCurrSysDictIndex = 0;
@@ -106,6 +153,28 @@ function run_sys_dict(index){
     }
 }
 
+var iCurrThinDictIndex=0;
+function run_ref_dict(index){
+    if(index >= thin_file_list.length){
+        $("#response").html($("#response").html()+"All Down");
+    }
+    else{
+        iCurrThinDictIndex = index;
+        $.get("step3_run.php",
+        {
+            dbtype:"thin",
+            filename:thin_file_list[index][0],
+            dbname:thin_file_list[index][1],
+            table:thin_file_list[index][2]
+        },
+        function(data,status){
+            $("#response").html($("#response").html()+data+"<br>");
+            iCurrThinDictIndex++;
+            run_ref_dict(iCurrThinDictIndex);
+        });
+    }
+}
+
 function run_part_dict(){
         $.get("step3_run.php",
         {
@@ -120,9 +189,30 @@ function run_part_dict(){
 </script>
 
 <h2>
-<button onclick="run_rich_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
-<button onclick="run_part_dict()">Build part dictionary</button><span style="请注意!此操作将会覆盖原有数据库。">
+
+
 </h2>
+
+<div class="card">
+	<h4>第三方参考字典</h4>
+	<div class="contence">
+	<button onclick="run_ref_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
+	</div>
+</div>
+
+<div class="card">
+	<h4>标准格式字典</h4>
+	<div class="contence">
+	<button onclick="run_rich_dict(0)">Build rich dictionary </button><span style="请注意!此操作将会覆盖原有数据库。"><br>
+	</div>
+</div>
+
+<div class="card">
+	<h4>组分字典</h4>
+	<div class="contence">
+	    <button onclick="run_part_dict()">Build part dictionary</button><span style="请注意!此操作将会覆盖原有数据库。">
+	</div>
+</div>
 <hr>
 <h2><a href="step4.php">[Next]</a></h2>
 </body>

+ 15 - 18
app/install/step3_run.php

@@ -75,26 +75,32 @@ switch($_GET["dbtype"]){
 
     break;
     case "thin":
-        $dbfilename = _DIR_DICT_TEXT_."/system/{$dbname}";
-        $sDescDbFile = _DIR_DICT_SYSTEM_."/".$dbname;      
-        $csvfile = _DIR_DICT_TEXT_."/system/{$filename}";    
-        $dns = "sqlite:".$dbfilename;
+        echo "doing filename: $filename dbname: $dbname table:$table<br>";
+        $sDescDbFile = _DIR_DICT_SYSTEM_."/".$dbname; 
+        $csvfile = _DIR_DICT_TEXT_."/thin/{$filename}";    
+        $dns = "sqlite:".$sDescDbFile;
         $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
         $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
         // 开始一个事务,关闭自动提交
         $dbh->beginTransaction();
         if($dbname==="ref.db"){
             if($table==="dict"){
-                $query="INSERT INTO {$table} ('id','pali', 'type', 'gramma', 'parent', 'mean', 'note', 'parts', 'partmean', 'status', 'confidence', 'len', 'dict_name', 'lang') VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                $query="INSERT INTO dict ('id','language', 'dict_id', 'eword', 'word', 'paliword', 'mean', 'length', 'status') VALUES ( ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ?  )";
             }
             else if($table==="info"){
-                $query="INSERT INTO {$table} ('id','pali', 'type', 'gramma', 'parent', 'mean', 'note', 'parts', 'partmean', 'status', 'confidence', 'len', 'dict_name', 'lang') VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                $query="INSERT INTO info ('language' , 'id' ,  'shortname' , 'name') VALUES (  ? ,  ? ,  ? ,  ? )";
+            }
+            else{
+                echo "table name $table unkow.";
             }
         }
         else if($dbname==="ref1.db"){
-            $query="INSERT INTO {$table} ('id','pali', 'type', 'gramma', 'parent', 'mean', 'note', 'parts', 'partmean', 'status', 'confidence', 'len', 'dict_name', 'lang') VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+            $query="INSERT INTO dict ('id','eword', 'word', 'length', 'count') VALUES (  ? ,  ? ,  ? ,  ? ,  ? )";
         }
-        
+        else{
+            echo "db name $dbname unkow.";
+        }
+       
         $stmt = $dbh->prepare($query);
         $count=0;
         // 打开文件并读取数据
@@ -122,17 +128,9 @@ switch($_GET["dbtype"]){
 
         $dbh = null;
 
-
-        if(copy($dbfilename,$sDescDbFile)){
-            echo "文件复制成功<br>";
-        }
-        else{
-            echo "文件复制失败<br>";
-        }
-
     break;
     case "part":
-        $dns = "sqlite:"._FILE_DB_part_;
+        $dns = "sqlite:"._FILE_DB_PART_;
         $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
         $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
@@ -156,7 +154,6 @@ switch($_GET["dbtype"]){
         // 打开文件并读取数据
         if(($fp=fopen(_DIR_DICT_TEXT_."/system/part.csv", "r"))!==FALSE){
             while(($data=fgetcsv($fp,0,','))!==FALSE){
-                //id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
                 $stmt->execute($data);
                 $count++;
             }

+ 1 - 1
app/path.php

@@ -19,7 +19,7 @@ define("_DIR_USERS_GUIDE_" , __DIR__."/../documents/users_guide");
 
 define("_FILE_DB_REF_"  , __DIR__."/../appdata/dict/system/ref.db");
 define("_FILE_DB_REF_INDEX_"  , __DIR__."/../appdata/dict/system/ref1.db");
-define("_FILE_DB_part_"  , __DIR__."/../appdata/dict/system/part.db3");
+define("_FILE_DB_PART_"  , __DIR__."/../appdata/dict/system/part.db3");
 
 
 define("_DIR_USER_BASE_" , __DIR__."/../user");

+ 6 - 3
dicttext/thin/list.txt → dicttext/thin/list.csv

@@ -1,4 +1,4 @@
-ref_index.db,ref1.db,dict
+ref_index.csv,ref1.db,dict
 dict_info.csv,ref.db,info
 ref1.csv,ref.db,dict
 ref2.csv,ref.db,dict
@@ -10,7 +10,11 @@ ref7.csv,ref.db,dict
 ref8.csv,ref.db,dict
 ref9.csv,ref.db,dict
 ref10.csv,ref.db,dict
-ref11.csv,ref.db,dict
+ref11-1.csv,ref.db,dict
+ref11-2.csv,ref.db,dict
+ref11-3.csv,ref.db,dict
+ref11-4.csv,ref.db,dict
+ref11-5.csv,ref.db,dict
 ref12.csv,ref.db,dict
 ref13.csv,ref.db,dict
 ref14.csv,ref.db,dict
@@ -28,7 +32,6 @@ ref25.csv,ref.db,dict
 ref26.csv,ref.db,dict
 ref26.csv,ref.db,dict
 ref28.csv,ref.db,dict
-ref29.csv,ref.db,dict
 ref30.csv,ref.db,dict
 ref31.csv,ref.db,dict
 ref32.csv,ref.db,dict

Разница между файлами не показана из-за своего большого размера
+ 8 - 0
dicttext/thin/ref11-1.csv


Разница между файлами не показана из-за своего большого размера
+ 1089 - 0
dicttext/thin/ref11-2.csv


Разница между файлами не показана из-за своего большого размера
+ 3859 - 0
dicttext/thin/ref11-3.csv


Разница между файлами не показана из-за своего большого размера
+ 255 - 0
dicttext/thin/ref11-4.csv


Разница между файлами не показана из-за своего большого размера
+ 915 - 0
dicttext/thin/ref11-5.csv


Разница между файлами не показана из-за своего большого размера
+ 0 - 8
dicttext/thin/ref11.csv


Некоторые файлы не были показаны из-за большого количества измененных файлов