db_insert_bold.php 4.0 KB

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