word_function.php 12 KB

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