Kaynağa Gözat

逐词译模版改为支持pg

visuddhinanda 4 yıl önce
ebeveyn
işleme
914085c5ac

+ 37 - 56
app/install/db_insert_templet.php

@@ -77,68 +77,49 @@ $xmlfile = $inputFileName;
 echo "doing:" . $xmlfile . "<br>";
 $log = $log . "$from,$FileName,open\r\n";
 
-$arrInserString = array();
-
-$db_file = _DIR_PALICANON_TEMPLET_ . "/" . $bookId . '_tpl.db3';
-PDO_Connect("sqlite:{$db_file}");
-
-PDO_Execute("DROP TABLE IF EXISTS main;");
-$query = "CREATE TABLE 'main' ( 'id' TEXT PRIMARY KEY NOT NULL,
-							'book' INTEGER,
-							'paragraph' INTEGER,
-							'wid' INTEGER,
-							'word' TEXT,
-							'real' TEXT,
-							'type' TEXT,
-							'gramma' TEXT,
-							'part' TEXT,
-							'style' TEXT)";
-$stmt = @PDO_Execute($query);
-if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-    $error = PDO_ErrorInfo();
-    print_r($error[2]);
 
-}
-PDO_Execute("DROP INDEX IF EXISTS search;");
+PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
 
-$query = "CREATE INDEX 'search' ON \"main\" (\"book\", \"paragraph\", \"wid\" ASC)";
-$stmt = @PDO_Execute($query);
-if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-    $error = PDO_ErrorInfo();
-    print_r($error[2]);
-    $log = $log . "$from, $FileName, error, $error[2] \r\n";
-}
+$row=0;
 
-// 打开文件并读取数据
-if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".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
-
-        $params = array($data[0],
-            mb_substr($data[2], 1),
-            $data[3],
-            $data[16],
-            $data[4],
-            $data[5],
-            $data[6],
-            $data[7],
-            $data[10],
-            $data[15]);
-        $arrInserString[] = $params;
-    }
-    fclose($fp);
-    echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
-} else {
-    echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
-}
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query = "INSERT INTO main ('id','book','paragraph','wid','word','real','type','gramma','part','style') VALUES (?,?,?,?,?,?,?,?,?,?)";
+$query = "INSERT INTO "._TABLE_PALICANON_TEMPLET_." ( book , paragraph, wid , word , real , type , gramma , part , style ) VALUES (?,?,?,?,?,?,?,?,?)";
 $stmt = $PDO->prepare($query);
-foreach ($arrInserString as $oneParam) {
-    $stmt->execute($oneParam);
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+	exit;
+} else {
+	// 打开文件并读取数据
+	if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+		while (($data = fgetcsv($fp, 0, ',')) !== false) {
+			if($row>0){
+				$params = array(
+					mb_substr($data[2], 1),
+					$data[3],
+					$data[16],
+					$data[4],
+					$data[5],
+					$data[6],
+					$data[7],
+					$data[10],
+					$data[15]);		
+				$stmt->execute($params);	
+			}
+
+			$row++;
+		}
+		fclose($fp);
+		echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+	} else {
+		echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
+	}
 }
+
 // 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
@@ -147,8 +128,8 @@ if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
 
     $log = $log . "$from, $FileName, error, $error[2] \r\n";
 } else {
-    $count = count($arrInserString);
-    echo "updata $count recorders.";
+    
+    echo "updata $row recorders.";
 }
 
 $myLogFile = fopen($dirLog . "insert_db.log", "a");

+ 4 - 1
app/path.php

@@ -66,7 +66,10 @@ define("_DB_NAME_", "mint");
 
 //语料库数据表 pali canon db file 
 //巴利语料模版表
-define("_FILE_DB_PALICANON_TEMPLET_", __DIR__ . "/../tmp/appdata/palicanon/templet.db3");
+define("_FILE_DB_PALICANON_TEMPLET_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
+//define("_FILE_DB_PALICANON_TEMPLET_","sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/templet.db3");
+define("_TABLE_PALICANON_TEMPLET_","wbw_templet");
+
 //标题资源表
 define("_FILE_DB_RESRES_INDEX_", "sqlite:" . __DIR__ . "/../tmp/appdata/palicanon/res.db3");
 //巴利语料段落表

+ 7 - 7
app/studio/dict_find_auto.php

@@ -18,10 +18,10 @@ set_error_handler(function(int $number, string $message) {
 $user_setting = get_setting();
 
 if (isset($_GET["book"])) {
-    $in_book = $_GET["book"];
+    $in_book = (int)$_GET["book"];
 }
 if (isset($_GET["para"])) {
-    $in_para = $_GET["para"];
+    $in_para = (int)$_GET["para"];
 }
 $para_list = str_getcsv($in_para);
 $strQueryPara = "("; //单词查询字串
@@ -51,10 +51,10 @@ global $PDO;
 
 //查询单词表
 $db_file = _DIR_PALICANON_TEMPLET_ . "/p" . $in_book . "_tpl.db3";
-PDO_Connect("sqlite:{$db_file}");
-$query = "SELECT paragraph,wid,real FROM \"main\" WHERE (\"paragraph\" in " . $strQueryPara . " ) and \"real\"<>\"\" and \"type\"<>'.ctl.' ";
+PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
+$query = "SELECT paragraph,wid,real FROM "._TABLE_PALICANON_TEMPLET_." WHERE ( book = ".$PDO->quote($in_book)." AND paragraph  in " . $strQueryPara . " ) and  real <> '' and  type <> '.ctl.' ";
 if ($debug) {
-    echo "filename:" . $db_file . "<br>";
+    
     echo $query . "<br>";
 }
 $FetchAllWord = PDO_FetchAll($query);
@@ -174,9 +174,9 @@ for ($i = 0; $i < $lookup_loop; $i++) {
         $strOrderby = $db["file"][1];
 
         if ($i == 0) {
-            $query = "select * from dict where \"pali\" in {$strQueryWord} AND ( type <> '.n:base.' AND  type <> '.ti:base.' AND  type <> '.adj:base.'  AND  type <> '.pron:base.'  AND  type <> '.v:base.'  AND  type <> '.part.' ) " . $strOrderby;
+            $query = "select * from dict where  pali  in {$strQueryWord} AND ( type <> '.n:base.' AND  type <> '.ti:base.' AND  type <> '.adj:base.'  AND  type <> '.pron:base.'  AND  type <> '.v:base.'  AND  type <> '.part.' ) " . $strOrderby;
         } else {
-            $query = "select * from dict where  \"pali\" in {$strQueryWord}  " . $strOrderby;
+            $query = "select * from dict where   pali  in {$strQueryWord}  " . $strOrderby;
         }
 
         if ($debug) {

+ 8 - 8
app/studio/pc_get_book_res.php

@@ -22,7 +22,7 @@ $guid = GUIDv4();
 switch ($res_type) {
     case "wbw":
         if ($author == "templet") {
-            $db_file = _DIR_PALICANON_TEMPLET_ . "/" . $currBook . "_tpl.db3";
+            $db_file = _FILE_DB_PALICANON_TEMPLET_;
         } else {
             $db_file = "../appdata/palicanon/wbw/" . $currBook . "_wbw.db3";
         }
@@ -50,26 +50,26 @@ PDO_Connect("$db_file");
 switch ($res_type) {
     case "wbw":
         if ($author == "templet") {
-            $query = "SELECT * FROM \"main\" WHERE \"book\" = " . $PDO->quote($currBook) . " AND \"paragraph\" = " . $PDO->quote($currParagraph) . "  ORDER BY vri ";
+            $query = "SELECT * FROM "._TABLE_PALICANON_TEMPLET_." WHERE  book  = " . $PDO->quote($currBook) . " AND \"paragraph\" = " . $PDO->quote($currParagraph) . "  ORDER BY vri ";
         } else {
-            $query = "SELECT * FROM \"main\" WHERE \"book\" = " . $PDO->quote($currBook) . " AND \"paragraph\" = " . $PDO->quote($currParagraph) . " AND \"language\" = " . $PDO->quote($language) . " AND \"author\" = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver) . "  ORDER BY vri ";
+            $query = "SELECT * FROM  main  WHERE  book  = " . $PDO->quote($currBook) . " AND  paragraph  = " . $PDO->quote($currParagraph) . " AND language = " . $PDO->quote($language) . " AND \"author\" = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver) . "  ORDER BY vri ";
         }
         break;
     case "heading":
         if ($author == "templet") {
-            $query = "SELECT * FROM \"data\" WHERE \"book\" = " . $PDO->quote($currBook) . " AND \"paragraph\" = " . $PDO->quote($currParagraph);
+            $query = "SELECT * FROM  data  WHERE  book  = " . $PDO->quote($currBook) . " AND  paragraph  = " . $PDO->quote($currParagraph);
         } else {
-            $query = "SELECT * FROM \"data\" WHERE \"book\" = " . $PDO->quote($currBook) . " AND \"par_num\" = " . $PDO->quote($currParagraph) . " AND \"language\" = " . $PDO->quote($language) . " AND \"author\" = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
+            $query = "SELECT * FROM  data  WHERE  book  = " . $PDO->quote($currBook) . " AND  par_num  = " . $PDO->quote($currParagraph) . " AND language = " . $PDO->quote($language) . " AND \"author\" = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
         }
         break;
     case "translate":
-        $query = "SELECT * FROM \"data\" WHERE \"paragraph\" = " . $PDO->quote($currParagraph) . " AND \"language\" = " . $PDO->quote($language) . " AND \"author\" = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
+        $query = "SELECT * FROM  data  WHERE  paragraph  = " . $PDO->quote($currParagraph) . " AND  language  = " . $PDO->quote($language) . " AND  author  = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
         break;
     case "note":
-        $query = "SELECT * FROM \"data\" WHERE \"paragraph\" = " . $PDO->quote($currParagraph) . " AND \"language\" = " . $PDO->quote($language) . " AND \"author\" = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
+        $query = "SELECT * FROM  data  WHERE  paragraph  = " . $PDO->quote($currParagraph) . " AND  language  = " . $PDO->quote($language) . " AND  author  = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
         break;
     case "file":
-        $query = "SELECT * FROM \"data\" WHERE \"paragraph\" = " . $PDO->quote($currParagraph) . " AND \"language\" = " . $PDO->quote($language) . " AND \"author\" = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
+        $query = "SELECT * FROM  data  WHERE  paragraph  = " . $PDO->quote($currParagraph) . " AND  language  = " . $PDO->quote($language) . " AND author = " . $PDO->quote($author) . " AND \"editor\" = " . $PDO->quote($editor) . " AND \"edition\" = " . $PDO->quote($edition) . " AND \"subver\" = " . $PDO->quote($subver);
         break;
 }
 

+ 5 - 6
app/studio/pc_get_word_num.php

@@ -7,19 +7,18 @@ $get_book = (int)$_GET["book"];
 $get_par_begin = (int)$_GET["begin"];
 $get_par_end = (int)$_GET["end"];
 
-$db_file = _DIR_PALICANON_TEMPLET_ . "/p" . $get_book . "_tpl.db3";
 
 //open database
-PDO_Connect("sqlite:{$db_file}");
+PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
 if ($get_par_end == -1 || ($get_par_end - $get_par_begin) > 500) {
     echo "0,0,0,0";
     exit;
 } else {
-    $query1 = "SELECT count(*) FROM \"main\" WHERE paragraph BETWEEN $get_par_begin AND $get_par_end";
-    $query2 = "select count(*) from (SELECT count() FROM \"main\" WHERE (paragraph BETWEEN $get_par_begin AND $get_par_end ) group by real ) T";
+    $query1 = "SELECT count(*) FROM "._TABLE_PALICANON_TEMPLET_." WHERE paragraph BETWEEN $get_par_begin AND $get_par_end";
+    $query2 = "SELECT count(*) FROM (SELECT count() FROM "._TABLE_PALICANON_TEMPLET_." WHERE (paragraph BETWEEN $get_par_begin AND $get_par_end ) group by real ) T";
 
-    $query3 = "SELECT sum(length(real)) FROM \"main\" WHERE paragraph BETWEEN $get_par_begin AND $get_par_end";
-    $query4 = "select sum(length(real)) from (SELECT count(),real FROM \"main\" WHERE (paragraph BETWEEN $get_par_begin AND $get_par_end ) group by real ) T";
+    $query3 = "SELECT sum(length(real)) FROM "._TABLE_PALICANON_TEMPLET_." WHERE paragraph BETWEEN $get_par_begin AND $get_par_end";
+    $query4 = "SELECT sum(length(real)) FROM (SELECT count(),real FROM "._TABLE_PALICANON_TEMPLET_." WHERE (paragraph BETWEEN $get_par_begin AND $get_par_end ) group by real ) T";
 
     $allword = PDO_FetchOne($query1);
     $allword_token = PDO_FetchOne($query2);

+ 6 - 6
app/studio/project.php

@@ -131,7 +131,7 @@ switch ($op) {
                             //获取段落层级和标题
                             $para_title = array();
                             PDO_Connect(_FILE_DB_PALITEXT_);
-                            $query = "SELECT * FROM pali_text WHERE \"book\" = " . $PDO->quote($res_book) . " AND (\"paragraph\" in {$strQueryParaList} ) AND level>0 AND level<9";
+                            $query = "SELECT * FROM pali_text WHERE  book  = " . $PDO->quote($res_book) . " AND ( paragraph  in {$strQueryParaList} ) AND level>0 AND level<9";
                             $sth = $PDO->prepare($query);
                             $sth->execute();
                             while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
@@ -141,9 +141,9 @@ switch ($op) {
                             }
 
                             $db_file = _DIR_PALICANON_TEMPLET_ . "/p" . $res_book . "_tpl.db3";
-                            PDO_Connect("sqlite:{$db_file}");
+                            PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
                             foreach ($aParaList as $iPar) {
-                                $query = "SELECT * FROM 'main' WHERE (\"paragraph\" = " . $PDO->quote($iPar) . " ) ";
+                                $query = "SELECT * FROM "._TABLE_PALICANON_TEMPLET_." WHERE ( book = ".$PDO->quote($res_book)." AND  paragraph  = " . $PDO->quote($iPar) . " ) ";
 
                                 $sth = $PDO->prepare($query);
                                 $sth->execute();
@@ -665,7 +665,7 @@ switch ($op) {
                             //获取段落层级和标题
                             $para_title = array();
                             PDO_Connect(_FILE_DB_PALITEXT_);
-                            $query = "SELECT * FROM pali_text WHERE \"book\" = " . $PDO->quote($res_book) . " AND (\"paragraph\" in {$strQueryParaList} ) AND level>0 AND level<9";
+                            $query = "SELECT * FROM pali_text WHERE  book\" = " . $PDO->quote($res_book) . " AND (\"paragraph\" in {$strQueryParaList} ) AND level>0 AND level<9";
                             $sth = $PDO->prepare($query);
                             $sth->execute();
                             while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
@@ -675,9 +675,9 @@ switch ($op) {
                             }
 
                             $db_file = _DIR_PALICANON_TEMPLET_ . "/p" . $res_book . "_tpl.db3";
-                            PDO_Connect("sqlite:{$db_file}");
+                            PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
                             foreach ($aParaList as $iPar) {
-                                $query = "SELECT * FROM 'main' WHERE (\"paragraph\" = " . $PDO->quote($iPar) . " ) ";
+                                $query = "SELECT * FROM "._TABLE_PALICANON_TEMPLET_." WHERE ( book = ".$PDO->quote($res_book)." AND   paragraph  = " . $PDO->quote($iPar) . " ) ";
 
                                 $sth = $PDO->prepare($query);
                                 $sth->execute();

+ 14 - 6
app/uwbw/create_wbw.php

@@ -70,8 +70,8 @@ if($sum_len>MAX_LETTER){
 PDO_Connect(""._FILE_DB_USER_WBW_);
 
 //模板库
-$db_tpl = "sqlite:"._DIR_PALICANON_TEMPLET_."/p".$_book."_tpl.db3";
-$dbh_tpl = new PDO($db_tpl, "", "");
+PDO_Connect(_FILE_DB_PALICANON_TEMPLET_);
+$dbh_tpl = $PDO;
 $dbh_tpl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 #用户逐词译库
@@ -84,8 +84,16 @@ $channelInfo = $channelClass->getChannal($_channel);
 foreach ($_para as $key => $para) {
     # code...
     $query = "SELECT count(*) FROM "._TABLE_USER_WBW_BLOCK_." WHERE channal = ? AND book= ? and paragraph = ? ";
-    $FetchWBW = PDO_FetchOne($query,array($_channel,$_book,$para));
-    if($FetchWBW==0){
+    //$FetchWBW = PDO_FetchOne($query,array($_channel,$_book,$para));
+	$stmt = $dbh_wbw->prepare($query);
+	$stmt->execute(array($_channel,$_book,$para));
+	$row = $stmt->fetch(PDO::FETCH_NUM);
+    if ($row) {
+        $FetchWBW = $row[0];
+    } else {
+        $FetchWBW =  0;
+    }
+    if($FetchWBW == 0){
         #建立
         //写入数据库
         // 开始一个事务,关闭自动提交
@@ -137,10 +145,10 @@ foreach ($_para as $key => $para) {
         }
 
         #逐词解析库
-        $query="SELECT * FROM 'main' WHERE paragraph = ? ";
+        $query="SELECT * FROM "._TABLE_PALICANON_TEMPLET_." WHERE book = ? AND paragraph = ? ";
         
         $sth = $dbh_tpl->prepare($query);
-        $sth->execute(array($para));
+        $sth->execute(array($_book,$para));
         
         $level=100;
         $title="";