2
0

page_index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /*
  3. 用拆分好的三藏数据 导出cs6段落编号
  4. */
  5. ?>
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. </head>
  10. <body>
  11. <h2>Export Paragraph No.</h2>
  12. <p>用拆分好的三藏数据 导出cs6段落编号</p>
  13. <?php
  14. require_once '../public/_pdo.php';
  15. require_once '../config.php';
  16. if (isset($_GET["run"]) == false) {
  17. ?>
  18. <form action="db_insert_templet.php" method="get">
  19. From: <input type="text" value="0" name="from"><br>
  20. To: <input type="text" value="216" name="to"><br>
  21. <input type="submit">
  22. </form>
  23. <?php
  24. return;
  25. }
  26. $from = 0;
  27. $to = 216;
  28. $filelist = array();
  29. $fileNums = 0;
  30. $log = "";
  31. echo "<h2>$from</h2>";
  32. if (($handle = fopen("filelist.csv", 'r')) !== false) {
  33. while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
  34. $fileNums++;
  35. }
  36. }
  37. if ($to == 0 || $to >= $fileNums) {
  38. $to = $fileNums - 1;
  39. }
  40. $FileName = $filelist[$from][1] . ".htm";
  41. $fileId = $filelist[$from][0];
  42. $fileId = $filelist[$from][0];
  43. $dirLog = _DIR_LOG_;
  44. $dirDb = _DIR_PALICANON_TEMPLET_;
  45. $inputFileName = $FileName;
  46. $outputFileNameHead = $filelist[$from][1];
  47. $bookId = $filelist[$from][2];
  48. $vriParNum = 0;
  49. $wordOrder = 1;
  50. $dirXmlBase = _DIR_PALI_CSV_ . "/";
  51. $dirXml = $outputFileNameHead . "/";
  52. $currChapter = "";
  53. $currParNum = "";
  54. $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");
  55. $g_wordCounter = 0;
  56. $arrUnWords[0] = array("id", "word", "type", "gramma", "parent", "mean", "note", "part", "partmean", "cf", "state", "delete", "tag", "len");
  57. $g_unWordCounter = 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 = $dirDb . "/" . $bookId . '_tpl.db3';
  70. PDO_Connect("sqlite:{$db_file}");
  71. PDO_Execute("DROP TABLE IF EXISTS main;");
  72. $query = "CREATE TABLE 'main' ( 'id' TEXT PRIMARY KEY NOT NULL,
  73. 'book' INTEGER,
  74. 'paragraph' INTEGER,
  75. 'wid' INTEGER,
  76. 'word' TEXT,
  77. 'real' TEXT,
  78. 'type' TEXT,
  79. 'gramma' TEXT,
  80. 'part' TEXT,
  81. 'style' TEXT)";
  82. $stmt = @PDO_Execute($query);
  83. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  84. $error = PDO_ErrorInfo();
  85. print_r($error[2]);
  86. }
  87. PDO_Execute("DROP INDEX IF EXISTS search;");
  88. $query = "CREATE INDEX 'search' ON \"main\" (\"book\", \"paragraph\", \"wid\" ASC)";
  89. $stmt = @PDO_Execute($query);
  90. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  91. $error = PDO_ErrorInfo();
  92. print_r($error[2]);
  93. $log = $log . "$from, $FileName, error, $error[2] \r\n";
  94. }
  95. // 打开文件并读取数据
  96. if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
  97. while (($data = fgetcsv($fp, 0, ',')) !== false) {
  98. //id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
  99. $params = array($data[0],
  100. mb_substr($data[2], 1),
  101. $data[3],
  102. $data[16],
  103. $data[4],
  104. $data[5],
  105. $data[6],
  106. $data[7],
  107. $data[10],
  108. $data[15]);
  109. $arrInserString[] = $params;
  110. }
  111. fclose($fp);
  112. echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
  113. } else {
  114. echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
  115. }
  116. // 开始一个事务,关闭自动提交
  117. $PDO->beginTransaction();
  118. $query = "INSERT INTO main ('id','book','paragraph','wid','word','real','type','gramma','part','style') VALUES (?,?,?,?,?,?,?,?,?,?)";
  119. $stmt = $PDO->prepare($query);
  120. foreach ($arrInserString as $oneParam) {
  121. $stmt->execute($oneParam);
  122. }
  123. // 提交更改
  124. $PDO->commit();
  125. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  126. $error = PDO_ErrorInfo();
  127. echo "error - $error[2] <br>";
  128. $log = $log . "$from, $FileName, error, $error[2] \r\n";
  129. } else {
  130. $count = count($arrInserString);
  131. echo "updata $count recorders.";
  132. }
  133. $myLogFile = fopen($dirLog . "insert_db.log", "a");
  134. fwrite($myLogFile, $log);
  135. fclose($myLogFile);
  136. ?>
  137. <?php
  138. if ($from == $to) {
  139. echo "<h2>齐活!功德无量!all done!</h2>";
  140. } else {
  141. echo "<script>";
  142. echo "window.location.assign(\"db_insert_templet.php?from=" . ($from + 1) . "&to=" . $to . "\")";
  143. echo "</script>";
  144. echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
  145. }
  146. ?>
  147. </body>
  148. </html>