word_function.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. require_once '../public/casesuf.inc';
  3. require_once '../public/union.inc';
  4. require_once "../config.php";
  5. require_once "../public/_pdo.php";
  6. require_once "../public/load_lang.php"; //语言文件
  7. require_once "../public/function.php";
  8. function get_new_book_list($strWordlist, $booklist = null)
  9. {
  10. //查找这些词出现在哪些书中
  11. $arrBookType = json_decode(file_get_contents("../public/book_name/booktype.json"));
  12. PDO_Connect(_FILE_DB_BOOK_WORD_);
  13. if (isset($booklist)) {
  14. foreach ($booklist as $oneBook) {
  15. $aInputBook["{$oneBook}"] = 1;
  16. }
  17. }
  18. $query = "SELECT book,sum(count) as co from "._TABLE_BOOK_WORD_." where \"wordindex\" in $strWordlist group by book order by co DESC";
  19. $Fetch = PDO_FetchAll($query);
  20. $iFetch = count($Fetch);
  21. $newBookList = array();
  22. if ($iFetch > 0) {
  23. $booktypesum["vinaya"] = array(0, 0);
  24. $booktypesum["sutta"] = array(0, 0);
  25. $booktypesum["abhidhamma"] = array(0, 0);
  26. $booktypesum["anna"] = array(0, 0);
  27. $booktypesum["mula"] = array(0, 0);
  28. $booktypesum["atthakattha"] = array(0, 0);
  29. $booktypesum["tika"] = array(0, 0);
  30. $booktypesum["anna2"] = array(0, 0);
  31. for ($i = 0; $i < $iFetch; $i++) {
  32. $book = $Fetch[$i]["book"];
  33. $title = _get_book_info($book)->title;
  34. $sum = $Fetch[$i]["co"];
  35. array_push($newBookList, array("book" => $book, "count" => $sum, "title" => $title));
  36. $t1 = $arrBookType[$book - 1]->c1;
  37. $t2 = $arrBookType[$book - 1]->c2;
  38. if (isset($booktypesum[$t1])) {
  39. $booktypesum[$t1][0]++;
  40. $booktypesum[$t1][1] += $sum;
  41. } else {
  42. $booktypesum[$t1][0] = 1;
  43. $booktypesum[$t1][1] = $sum;
  44. }
  45. if (isset($booktypesum[$t2])) {
  46. $booktypesum[$t2][0]++;
  47. $booktypesum[$t2][1] += $sum;
  48. } else {
  49. $booktypesum[$t2][0] = 1;
  50. $booktypesum[$t2][1] = $sum;
  51. }
  52. }
  53. }
  54. return ($newBookList);
  55. //查找这些词出现在哪些书中结束
  56. }
  57. function get_book_tag($strWordlist, $booklist = null)
  58. {
  59. //查找这些词出现在哪些书中
  60. $arrBookType = json_decode(file_get_contents("../public/book_name/booktype.json"));
  61. PDO_Connect(_FILE_DB_BOOK_WORD_);
  62. if (isset($booklist)) {
  63. foreach ($booklist as $oneBook) {
  64. $aInputBook["{$oneBook}"] = 1;
  65. }
  66. }
  67. $query = "SELECT book,sum(count) as co from "._TABLE_BOOK_WORD_." where \"wordindex\" in $strWordlist group by book order by co DESC";
  68. $Fetch = PDO_FetchAll($query);
  69. $iFetch = count($Fetch);
  70. $newBookList = array();
  71. if ($iFetch > 0) {
  72. $booktypesum["vinaya"] = array(0, 0);
  73. $booktypesum["sutta"] = array(0, 0);
  74. $booktypesum["abhidhamma"] = array(0, 0);
  75. $booktypesum["anna"] = array(0, 0);
  76. $booktypesum["mula"] = array(0, 0);
  77. $booktypesum["atthakattha"] = array(0, 0);
  78. $booktypesum["tika"] = array(0, 0);
  79. $booktypesum["anna2"] = array(0, 0);
  80. for ($i = 0; $i < $iFetch; $i++) {
  81. $book = $Fetch[$i]["book"];
  82. $sum = $Fetch[$i]["co"];
  83. array_push($newBookList, array($book, $sum));
  84. $t1 = $arrBookType[$book - 1]->c1;
  85. $t2 = $arrBookType[$book - 1]->c2;
  86. if (isset($booktypesum[$t1])) {
  87. $booktypesum[$t1][0]++;
  88. $booktypesum[$t1][1] += $sum;
  89. } else {
  90. $booktypesum[$t1][0] = 1;
  91. $booktypesum[$t1][1] = $sum;
  92. }
  93. if (isset($booktypesum[$t2])) {
  94. $booktypesum[$t2][0]++;
  95. $booktypesum[$t2][1] += $sum;
  96. } else {
  97. $booktypesum[$t2][0] = 1;
  98. $booktypesum[$t2][1] = $sum;
  99. }
  100. }
  101. $output = array();
  102. $output[] = array("tag" => "vinaya", "title" => "律藏", "count" => $booktypesum["vinaya"][0]);
  103. $output[] = array("tag" => "sutta", "title" => "经藏", "count" => $booktypesum["sutta"][0]);
  104. $output[] = array("tag" => "abhidhamma", "title" => "阿毗达摩藏", "count" => $booktypesum["abhidhamma"][0]);
  105. $output[] = array("tag" => "anna", "title" => "其他", "count" => $booktypesum["anna"][0]);
  106. $output[] = array("tag" => "mula", "title" => "根本", "count" => $booktypesum["mula"][0]);
  107. $output[] = array("tag" => "atthakattha", "title" => "义注", "count" => $booktypesum["atthakattha"][0]);
  108. $output[] = array("tag" => "tika", "title" => "复注", "count" => $booktypesum["tika"][0]);
  109. $output[] = array("tag" => "anna2", "title" => "其他", "count" => $booktypesum["anna2"][0]);
  110. return $output;
  111. }
  112. }
  113. function render_book_list($strWordlist, $booklist = null)
  114. {
  115. //查找这些词出现在哪些书中
  116. $arrBookType = json_decode(file_get_contents("../public/book_name/booktype.json"));
  117. PDO_Connect(_FILE_DB_BOOK_WORD_);
  118. if (isset($booklist)) {
  119. foreach ($booklist as $oneBook) {
  120. $aInputBook["{$oneBook}"] = 1;
  121. }
  122. }
  123. $query = "SELECT book,sum(count) as co from "._TABLE_BOOK_WORD_." where \"wordindex\" in $strWordlist group by book order by co DESC";
  124. $Fetch = PDO_FetchAll($query);
  125. $iFetch = count($Fetch);
  126. $newBookList = array();
  127. if ($iFetch > 0) {
  128. $booktypesum["vinaya"] = array(0, 0);
  129. $booktypesum["sutta"] = array(0, 0);
  130. $booktypesum["abhidhamma"] = array(0, 0);
  131. $booktypesum["anna"] = array(0, 0);
  132. $booktypesum["mula"] = array(0, 0);
  133. $booktypesum["atthakattha"] = array(0, 0);
  134. $booktypesum["tika"] = array(0, 0);
  135. $booktypesum["anna2"] = array(0, 0);
  136. for ($i = 0; $i < $iFetch; $i++) {
  137. $book = $Fetch[$i]["book"];
  138. $sum = $Fetch[$i]["co"];
  139. array_push($newBookList, array($book, $sum));
  140. $t1 = $arrBookType[$book - 1]->c1;
  141. $t2 = $arrBookType[$book - 1]->c2;
  142. if (isset($booktypesum[$t1])) {
  143. $booktypesum[$t1][0]++;
  144. $booktypesum[$t1][1] += $sum;
  145. } else {
  146. $booktypesum[$t1][0] = 1;
  147. $booktypesum[$t1][1] = $sum;
  148. }
  149. if (isset($booktypesum[$t2])) {
  150. $booktypesum[$t2][0]++;
  151. $booktypesum[$t2][1] += $sum;
  152. } else {
  153. $booktypesum[$t2][0] = 1;
  154. $booktypesum[$t2][1] = $sum;
  155. }
  156. }
  157. echo "<div id='bold_book_list_new' style='margin:1em;0'>";
  158. echo "<div>出现在{$iFetch}本书中:</div>";
  159. echo "<div>全选<input id='bold_all_book' type='checkbox' checked onclick=\"dict_bold_book_all_select()\" /></div>";
  160. echo "<div>律藏-{$booktypesum["vinaya"][0]}-{$booktypesum["vinaya"][1]}<input id='id_book_filter_vinaya' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_vinaya','vinaya')\" /></div>";
  161. echo "<div>经藏-{$booktypesum["sutta"][0]}-{$booktypesum["sutta"][1]}<input id='id_book_filter_sutta' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_sutta','sutta')\" /></div>";
  162. echo "<div>阿毗达摩藏-{$booktypesum["abhidhamma"][0]}-{$booktypesum["abhidhamma"][1]}<input id='id_book_filter_abhidhamma' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_abhidhamma','abhidhamma')\" /></div>";
  163. echo "<div >其他-{$booktypesum["anna"][0]}-{$booktypesum["anna"][1]}<input id='id_book_filter_anna' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_anna','anna')\" /></div>";
  164. echo "<div style='margin-bottom:1em';></div>";
  165. echo "<div>根本-{$booktypesum["mula"][0]}-{$booktypesum["mula"][1]}<input id='id_book_filter_mula' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_mula','mula')\" /></div>";
  166. echo "<div>义注-{$booktypesum["atthakattha"][0]}-{$booktypesum["atthakattha"][1]}<input id='id_book_filter_atthakattha' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_atthakattha','atthakattha')\" /></div>";
  167. echo "<div>复注-{$booktypesum["tika"][0]}-{$booktypesum["tika"][1]}<input id='id_book_filter_tika' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_tika','tika')\" /></div>";
  168. echo "<div>其他-{$booktypesum["anna2"][0]}-{$booktypesum["anna2"][1]}<input id='id_book_filter_anna2' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_anna2','anna2')\" /></div>";
  169. for ($i = 0; $i < $iFetch; $i++) {
  170. $book = $Fetch[$i]["book"];
  171. $bookname = _get_book_info($book)->title;
  172. if (isset($booklist)) {
  173. if (isset($aInputBook["{$book}"])) {
  174. $bookcheck = "checked";
  175. } else {
  176. $bookcheck = "";
  177. }
  178. } else {
  179. $bookcheck = "checked";
  180. }
  181. $t1 = $arrBookType[$book - 1]->c1;
  182. $t2 = $arrBookType[$book - 1]->c2;
  183. echo "<div class='{$t1}'>";
  184. echo "<div class='{$t2}'>";
  185. echo "<input id='bold_book_{$i}' type='checkbox' $bookcheck value='{$book}'/>";
  186. echo "<a onclick=\"dict_bold_book_select({$i})\">";
  187. echo "《{$bookname}》({$Fetch[$i]["co"]})<br />";
  188. echo "</a>";
  189. echo "</div></div>";
  190. }
  191. echo "<input id='bold_book_count' type='hidden' value='{$iFetch}' />";
  192. echo "</div>";
  193. }
  194. return ($newBookList);
  195. //查找这些词出现在哪些书中结束
  196. }
  197. function countWordInPali($word, $sort = false, $limit = 0)
  198. {
  199. //加语尾
  200. $case = $GLOBALS['case'];
  201. $union = $GLOBALS['union'];
  202. $arrNewWord = array();
  203. for ($row = 0; $row < count($case); $row++) {
  204. $len = mb_strlen($case[$row][0], "UTF-8");
  205. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  206. if ($end == $case[$row][0]) {
  207. $newWord = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][1];
  208. $arrNewWord[$newWord] = 1;
  209. }
  210. }
  211. //加连读词尾
  212. $arrUnWord = array();
  213. for ($i = 0; $i < 2; $i++) {
  214. for ($row = 0; $row < count($union); $row++) {
  215. $len = mb_strlen($union[$row][0], "UTF-8");
  216. foreach ($arrNewWord as $x => $x_value) {
  217. $end = mb_substr($x, 0 - $len, null, "UTF-8");
  218. if ($end == $union[$row][0]) {
  219. $newWord = mb_substr($x, 0, mb_strlen($x, "UTF-8") - $len, "UTF-8") . $union[$row][1];
  220. $arrUnWord[$newWord] = 1;
  221. }
  222. }
  223. }
  224. }
  225. //将连读词和$arrNewWord混合
  226. foreach ($arrUnWord as $x => $x_value) {
  227. $arrNewWord[$x] = 1;
  228. }
  229. if (count($arrNewWord) > 0) {
  230. $strQueryWord = "(";
  231. foreach ($arrNewWord as $x => $x_value) {
  232. $strQueryWord .= "'{$x}',";
  233. }
  234. $strQueryWord = mb_substr($strQueryWord, 0, mb_strlen($strQueryWord, "UTF-8") - 1, "UTF-8");
  235. $strQueryWord .= ")";
  236. } else {
  237. $strQueryWord = "('{$word}')";
  238. }
  239. //查找实际出现的拼写
  240. $dsn = _FILE_DB_WORD_INDEX_;
  241. $PDO = new PDO($dsn, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  242. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  243. if ($limit == 0) {
  244. $sSqlLimit = "";
  245. } else {
  246. $sSqlLimit = "limit " . $limit;
  247. }
  248. if ($sort) {
  249. $sSqlSort = "order by count DESC";
  250. } else {
  251. $sSqlSort = "";
  252. }
  253. $query = "SELECT id,word,count,bold,len from "._TABLE_WORD_INDEX_." where \"word\" in $strQueryWord " . $sSqlSort . " " . $sSqlLimit;
  254. $stmt = $PDO->query($query);
  255. $arrRealWordList = $stmt->fetchAll(PDO::FETCH_ASSOC);
  256. return ($arrRealWordList);
  257. }