word_function.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 render_book_list($strWordlist,$booklist=null){
  9. //查找这些词出现在哪些书中
  10. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  11. $dictFileName=_FILE_DB_BOOK_WORD_;
  12. PDO_Connect("sqlite:$dictFileName");
  13. if(isset($booklist)){
  14. foreach($booklist as $oneBook){
  15. $aInputBook["{$oneBook}"]=1;
  16. }
  17. }
  18. $query = "select book,sum(count) as co from bookword 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. $sum=$Fetch[$i]["co"];
  34. array_push($newBookList,array($book,$sum));
  35. $t1=$arrBookType[$book-1]->c1;
  36. $t2=$arrBookType[$book-1]->c2;
  37. if(isset($booktypesum[$t1])){
  38. $booktypesum[$t1][0]++;
  39. $booktypesum[$t1][1]+=$sum;
  40. }
  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. }
  49. else{
  50. $booktypesum[$t2][0]=1;
  51. $booktypesum[$t2][1]=$sum;
  52. }
  53. }
  54. echo "<div id='bold_book_list_new' style='margin:1em;0'>";
  55. echo "<div>出现在{$iFetch}本书中:</div>";
  56. echo "<div>全选<input id='bold_all_book' type='checkbox' checked onclick=\"dict_bold_book_all_select()\" /></div>";
  57. 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>";
  58. 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>";
  59. 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>";
  60. 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>";
  61. echo "<div style='margin-bottom:1em';></div>";
  62. 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>";
  63. 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>";
  64. 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>";
  65. 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>";
  66. for($i=0;$i<$iFetch;$i++){
  67. $book=$Fetch[$i]["book"];
  68. $bookname=_get_book_info($book)->title;
  69. if(isset($booklist)){
  70. if(isset($aInputBook["{$book}"])){
  71. $bookcheck="checked";
  72. }
  73. else{
  74. $bookcheck="";
  75. }
  76. }
  77. else{
  78. $bookcheck="checked";
  79. }
  80. $t1=$arrBookType[$book-1]->c1;
  81. $t2=$arrBookType[$book-1]->c2;
  82. echo "<div class='{$t1}'>";
  83. echo "<div class='{$t2}'>";
  84. echo "<input id='bold_book_{$i}' type='checkbox' $bookcheck value='{$book}'/>";
  85. echo "<a onclick=\"dict_bold_book_select({$i})\">";
  86. echo "《{$bookname}》({$Fetch[$i]["co"]})<br />";
  87. echo "</a>";
  88. echo "</div></div>";
  89. }
  90. echo "<input id='bold_book_count' type='hidden' value='{$iFetch}' />";
  91. echo "</div>";
  92. }
  93. return($newBookList);
  94. //查找这些词出现在哪些书中结束
  95. }
  96. function countWordInPali($word,$sort=false,$limit = 0){
  97. //加语尾
  98. $case = $GLOBALS['case'];
  99. $union = $GLOBALS['union'];
  100. $arrNewWord=array();
  101. for ($row = 0; $row < count($case); $row++) {
  102. $len=mb_strlen($case[$row][0],"UTF-8");
  103. $end=mb_substr($word, 0-$len,NULL,"UTF-8");
  104. if($end==$case[$row][0]){
  105. $newWord=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$case[$row][1];
  106. $arrNewWord[$newWord]=1;
  107. }
  108. }
  109. //加连读词尾
  110. $arrUnWord=array();
  111. for ($row = 0; $row < count($union); $row++) {
  112. $len=mb_strlen($union[$row][0],"UTF-8");
  113. foreach($arrNewWord as $x=>$x_value){
  114. $end=mb_substr($x, 0-$len,NULL,"UTF-8");
  115. if($end==$union[$row][0]){
  116. $newWord=mb_substr($x, 0,mb_strlen($x,"UTF-8")-$len,"UTF-8").$union[$row][1];
  117. $arrUnWord[$newWord]=1;
  118. }
  119. }
  120. }
  121. //将连读词和$arrNewWord混合
  122. foreach($arrUnWord as $x=>$x_value){
  123. $arrNewWord[$x]=1;
  124. }
  125. if(count($arrNewWord)>0){
  126. $strQueryWord="(";
  127. foreach($arrNewWord as $x=>$x_value) {
  128. $strQueryWord.="'{$x}',";
  129. }
  130. $strQueryWord=mb_substr($strQueryWord, 0,mb_strlen($strQueryWord,"UTF-8")-1,"UTF-8");
  131. $strQueryWord.=")";
  132. }
  133. else{
  134. $strQueryWord="('{$word}')";
  135. }
  136. //查找实际出现的拼写
  137. $dsn = "sqlite:"._FILE_DB_WORD_INDEX_;
  138. $user = "";
  139. $password = "";
  140. $PDO = new PDO($dsn, $user, $password,array(PDO::ATTR_PERSISTENT=>true));
  141. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  142. if($limit==0){
  143. $sSqlLimit = "";
  144. }
  145. else{
  146. $sSqlLimit = "limit 0 , ".$limit;
  147. }
  148. if($sort){
  149. $sSqlSort = "order by count DESC";
  150. }
  151. else{
  152. $sSqlSort = "";
  153. }
  154. $query = "select id,word,count,bold,len from wordindex where \"word\" in $strQueryWord ".$sSqlSort . " ".$sSqlLimit;
  155. $stmt = $PDO->query($query);
  156. $arrRealWordList = $stmt->fetchAll(PDO::FETCH_ASSOC);
  157. return($arrRealWordList);
  158. }
  159. ?>