db_insert_bold.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. require_once "install_head.php";
  3. ?>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. </head>
  8. <body>
  9. <h2>Insert to bold</h2>
  10. <p><a href="index.php">Home</a></p>
  11. <div>
  12. 生成黑体字数据库。黑体字多数是义注复注里的单词(尤其是专有名词)解释。
  13. </div>
  14. <?php
  15. include "./_pdo.php";
  16. include "../path.php";
  17. if(isset($_GET["from"])==false){
  18. ?>
  19. <form action="db_insert_bold.php" method="get">
  20. From: <input type="text" name="from" value="0"><br>
  21. To: <input type="text" name="to" value="216"><br>
  22. <input type="submit">
  23. </form>
  24. <?php
  25. return;
  26. }
  27. $from=$_GET["from"];
  28. $to=$_GET["to"];
  29. $filelist=array();
  30. $fileNums=0;
  31. $log="";
  32. echo "<h2>$from</h2>";
  33. function getWordEn($strIn){
  34. $search = array('ā', 'ī', 'ū', 'ṅ', 'ñ' , 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
  35. $replace = array('a', 'i', 'u', 'n', 'n' , 't', 'd', 'n', 'l', 'm');
  36. return(str_replace($search,$replace,$strIn));
  37. }
  38. if(($handle=fopen("filelist.csv",'r'))!==FALSE){
  39. while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
  40. $fileNums++;
  41. }
  42. }
  43. if($to==0 || $to>=$fileNums) $to=$fileNums-1;
  44. $FileName=$filelist[$from][1].".htm";
  45. $fileId=$filelist[$from][0];
  46. $fileId=$filelist[$from][0];
  47. $dirLog=_DIR_LOG_;
  48. //输出文件夹
  49. $dirDb=_DIR_PALICANON_."/";
  50. $inputFileName=$FileName;
  51. $outputFileNameHead=$filelist[$from][1];
  52. $bookId=$filelist[$from][2];
  53. $vriParNum=0;
  54. $wordOrder=1;
  55. $dirXmlBase=_DIR_PALI_CSV_."/";
  56. $dirXml=$outputFileNameHead."/";
  57. $currChapter="";
  58. $currParNum="";
  59. $arrAllWords[0]=array("id","wid","book","paragraph","word","real","type","gramma","mean","note","part","partmean","bmc","bmt","un","style","vri","sya","si","ka","pi","pa","kam");
  60. $g_wordCounter=0;
  61. $arrUnPart[0]="word";
  62. $g_unPartCounter=-1;
  63. /*去掉标点符号的统计*/
  64. $arrAllPaliWordsCount=array();
  65. $g_paliWordCounter=0;
  66. $g_wordCounterInSutta=0;
  67. $g_paliWordCountCounter=0;
  68. $xmlfile = $inputFileName;
  69. echo "doing:".$xmlfile."<br>";
  70. $log=$log."$from,$FileName,open\r\n";
  71. $arrInserString=array();
  72. $db_file = _FILE_DB_BOLD_;
  73. PDO_Connect("sqlite:$db_file");
  74. // 打开文件并读取数据
  75. if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
  76. while(($data=fgetcsv($fp,0,','))!==FALSE){
  77. $params=$data;
  78. $arrInserString[count($arrInserString)]=$params;
  79. }
  80. fclose($fp);
  81. echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
  82. }
  83. else{
  84. echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
  85. }
  86. // 开始一个事务,关闭自动提交
  87. $PDO->beginTransaction();
  88. $query="INSERT INTO bold ('id','book','paragraph','word','word2','word_en') VALUES (NULL,?,?,?,?,?)";
  89. $stmt = $PDO->prepare($query);
  90. $allcount=1;
  91. $count=0;
  92. $count1=0;
  93. $sen="";
  94. $sen1="";
  95. $sen_en="";
  96. $sen_count=0;
  97. $book="";
  98. $paragraph="";
  99. foreach($arrInserString as $oneParam){
  100. if($oneParam[15]=="bld" ){
  101. if($oneParam[5]!=""){
  102. $sen_count++;
  103. }
  104. $sen.=$oneParam[4]." ";
  105. $sen1.=$oneParam[5]." ";
  106. $book=substr($oneParam[2],1);
  107. $paragraph=$oneParam[3];
  108. if($oneParam[5]!=""){
  109. $newWord=array($book,$paragraph,$oneParam[4],$oneParam[5],getWordEn($oneParam[5]));
  110. $stmt->execute($newWord);
  111. $count++;
  112. $allcount++;
  113. }
  114. }
  115. else{
  116. if($sen_count>1){
  117. $sen=rtrim($sen);
  118. $sen1=rtrim($sen1);
  119. $sen_en=getWordEn($sen1);
  120. $newWord=array($book,$paragraph,$sen,$sen1,$sen_en);
  121. $stmt->execute($newWord);
  122. $count1++;
  123. $allcount++;
  124. $sen="";
  125. $sen1="";
  126. $sen_en="";
  127. $sen_count=0;
  128. }
  129. else{
  130. $sen="";
  131. $sen1="";
  132. $sen_en="";
  133. $sen_count=0;
  134. }
  135. }
  136. }
  137. // 提交更改
  138. $PDO->commit();
  139. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  140. $error = PDO_ErrorInfo();
  141. echo "error - $error[2] <br>";
  142. $log=$log."$from, $FileName, error, $error[2] \r\n";
  143. }
  144. else{
  145. echo "updata $count-$count1 recorders.";
  146. }
  147. $myLogFile = fopen($dirLog."insert_bold.log", "a");
  148. fwrite($myLogFile, $log);
  149. fclose($myLogFile);
  150. ?>
  151. <?php
  152. if($from==$to){
  153. echo "<h2>齐活!功德无量!all done!</h2>";
  154. }
  155. else{
  156. echo "<script>";
  157. echo "window.location.assign(\"db_insert_bold.php?from=".($from+1)."&to=".$to."\")";
  158. echo "</script>";
  159. echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
  160. }
  161. ?>
  162. </body>
  163. </html>