dict_lookup.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. //查询参考字典
  3. require_once '../path.php';
  4. require_once '../public/casesuf.inc';
  5. require_once '../public/union.inc';
  6. require_once "../public/_pdo.php";
  7. require_once "../public/load_lang.php"; //语言文件
  8. require_once "../public/function.php";
  9. require_once "../search/word_function.php";
  10. require_once "../ucenter/active.php";
  11. require_once "../ucenter/function.php";
  12. require_once "../dict/p_ending.php";
  13. _load_book_index();
  14. $word = mb_strtolower($_GET["word"], 'UTF-8');
  15. $org_word = $word;
  16. $count_return = 0;
  17. $dict_list = array();
  18. $right_word_list = "";
  19. add_edit_event(_DICT_LOOKUP_, $word);
  20. echo "<div id='dict_ref'>";
  21. echo "<div class='pali_spell'><a name='{word_$word}'></a>" . $word . "</div>";
  22. $dict_list_a = [];
  23. //社区字典开始
  24. PDO_Connect("" . _FILE_DB_WBW_);
  25. $query = "SELECT * from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
  26. $Fetch = PDO_FetchAll($query, array($word));
  27. $iFetch = count($Fetch);
  28. $count_return += $iFetch;
  29. if ($iFetch > 0) {
  30. $userlist = array();
  31. foreach ($Fetch as $value) {
  32. if (isset($userlist[$value["creator"]])) {
  33. $userlist[$value["creator"]] += 1;
  34. } else {
  35. $userlist[$value["creator"]] = 1;
  36. }
  37. $userwordcase = $value["type"] . "#" . $value["gramma"];
  38. if (isset($userdict["{$userwordcase}"])) {
  39. $userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
  40. $userdict["{$userwordcase}"]["factors"] .= $value["factors"];
  41. } else {
  42. $userdict["{$userwordcase}"]["mean"] = $value["mean"];
  43. $userdict["{$userwordcase}"]["factors"] = $value["factors"];
  44. }
  45. }
  46. echo "<div class='dict_word'>";
  47. echo "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
  48. $dict_list_a[] = array("net", $_local->gui->com_dict);
  49. foreach ($userdict as $key => $value) {
  50. echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
  51. }
  52. echo "<div><span>{$_local->gui->contributor}:</span>";
  53. $userinfo = new UserInfo();
  54. foreach ($userlist as $key => $value) {
  55. $user = $userinfo->getName($key);
  56. echo $user["nickname"] . "[" . $value . "]";
  57. }
  58. echo "</div>";
  59. echo "</div>";
  60. }
  61. //社区字典结束
  62. PDO_Connect("" . _FILE_DB_REF_);
  63. //直接查询
  64. $query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,100";
  65. $Fetch = PDO_FetchAll($query, array($word));
  66. $iFetch = count($Fetch);
  67. $count_return += $iFetch;
  68. if ($iFetch > 0) {
  69. for ($i = 0; $i < $iFetch; $i++) {
  70. $mean = $Fetch[$i]["mean"];
  71. $dictid = $Fetch[$i]["dict_id"];
  72. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  73. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  74. $outXml = "<div class='dict_word'>";
  75. $outXml = $outXml . "<a name='ref_dict_$dictid'></a>";
  76. $outXml = $outXml . "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  77. $outXml = $outXml . "<div class='mean'>" . $mean . "</div>";
  78. $outXml = $outXml . "</div>";
  79. echo $outXml;
  80. }
  81. }
  82. //去格位除尾查
  83. $newWord = array();
  84. for ($row = 0; $row < count($case); $row++) {
  85. $len = mb_strlen($case[$row][1], "UTF-8");
  86. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  87. if ($end == $case[$row][1]) {
  88. $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][0];
  89. if ($base != $word) {
  90. $thiscase = "";
  91. $arrCase = explode('$', $case[$row][2]);
  92. foreach ($arrCase as $value) {
  93. $caseid = "grammar_" . str_replace('.', '', $value);
  94. $thiscase .= "<guide gid='$caseid'>$value</guide>";
  95. }
  96. if (isset($newWord[$base])) {
  97. $newWord[$base] .= "<br />" . $thiscase;
  98. } else {
  99. $newWord[$base] = $thiscase;
  100. }
  101. }
  102. }
  103. }
  104. $base_list = array();
  105. if (count($newWord) > 0) {
  106. foreach ($newWord as $x => $x_value) {
  107. $query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,30";
  108. $Fetch = PDO_FetchAll($query, array($x));
  109. $iFetch = count($Fetch);
  110. $count_return += $iFetch;
  111. if ($iFetch > 0) {
  112. $base_list[] = $x;
  113. $dict_list_a[] = array("word_$x", $x);
  114. echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
  115. //语法信息
  116. foreach ($_local->grammastr as $gr) {
  117. $x_value = str_replace($gr->id, $gr->value, $x_value);
  118. }
  119. echo "<div class='dict_find_gramma'>" . $x_value . "</div>";
  120. for ($i = 0; $i < $iFetch; $i++) {
  121. $mean = $Fetch[$i]["mean"];
  122. $dictid = $Fetch[$i]["dict_id"];
  123. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  124. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  125. echo "<div class='dict_word'>";
  126. echo "<a name='ref_dict_$dictid'></a>";
  127. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  128. echo "<div class='mean'>" . $mean . "</div>";
  129. echo "</div>";
  130. }
  131. }
  132. }
  133. }
  134. //去除尾查结束
  135. //去分词除尾查
  136. $arrBase = array();
  137. if (count($newWord) > 0) {
  138. foreach ($newWord as $base => $grammar){
  139. for ($row = 0; $row < count($p_ending); $row++) {
  140. $len = mb_strlen($case[$row][1], "UTF-8");
  141. $end = mb_substr($base, 0 - $len, null, "UTF-8");
  142. if ($end == $p_ending[$row][1]) {
  143. $newbase = mb_substr($base, 0, mb_strlen($base, "UTF-8") - $len, "UTF-8") . $p_ending[$row][0];
  144. if ($newbase != $base) {
  145. $thiscase = "";
  146. $arrCase = explode('$', $p_ending[$row][2]);
  147. foreach ($arrCase as $value) {
  148. $caseid = "grammar_" . str_replace('.', '', $value);
  149. $thiscase .= "<guide gid='$caseid'>$value</guide>";
  150. }
  151. if (isset($arrBase[$newbase])) {
  152. $arrBase[$newbase]['grammar'] .= "<br />" . $thiscase;
  153. } else {
  154. $arrBase[$newbase]['grammar'] = $thiscase;
  155. $arrBase[$newbase]['parent'] = $base;
  156. }
  157. }
  158. }
  159. }
  160. }
  161. $base_list = array();
  162. if (count($arrBase) > 0) {
  163. foreach ($arrBase as $x => $x_value) {
  164. $query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,30";
  165. $Fetch = PDO_FetchAll($query, array($x));
  166. $iFetch = count($Fetch);
  167. $count_return += $iFetch;
  168. if ($iFetch > 0) {
  169. $base_list[] = $x;
  170. $dict_list_a[] = array("word_$x", $x);
  171. echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
  172. echo "<div style='color:gray;'>{$x}->{$x_value["parent"]}->{$word}</div>";
  173. //语法信息
  174. foreach ($_local->grammastr as $gr) {
  175. $x_value['grammar'] = str_replace($gr->id, $gr->value, $x_value['grammar']);
  176. }
  177. echo "<div class='dict_find_gramma'>" . $x_value['grammar'] . "</div>";
  178. for ($i = 0; $i < $iFetch; $i++) {
  179. $mean = $Fetch[$i]["mean"];
  180. $dictid = $Fetch[$i]["dict_id"];
  181. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  182. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  183. echo "<div class='dict_word'>";
  184. echo "<a name='ref_dict_$dictid'></a>";
  185. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  186. echo "<div class='mean'>" . $mean . "</div>";
  187. echo "</div>";
  188. }
  189. }
  190. }
  191. }
  192. }
  193. //去除尾查结束
  194. echo "<div id='search_summary'>";
  195. echo "查询{$word} 共{$count_return}条 ";
  196. if(count($base_list)>0){
  197. echo "找到可能的拼写: ";
  198. foreach ($base_list as $key => $value) {
  199. # code...
  200. echo "<a>{$value}</a> ";
  201. }
  202. }
  203. echo "</div>";
  204. echo "<input type='hidden' id='word_count' value='{$count_return}' />";
  205. //查连读词
  206. /*
  207. if ($count_return < 2) {
  208. echo "<div>Junction</div>";
  209. $newWord = array();
  210. for ($row = 0; $row < count($un); $row++) {
  211. $len = mb_strlen($un[$row][1], "UTF-8");
  212. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  213. if ($end == $un[$row][1]) {
  214. $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $un[$row][0];
  215. $arr_un = explode("+", $base);
  216. foreach ($arr_un as $oneword) {
  217. echo "<a onclick='dict_pre_word_click(\"$oneword\")'>$oneword</a> + ";
  218. }
  219. echo "<br />";
  220. }
  221. }
  222. }
  223. */
  224. //拆复合词
  225. echo "<div id='auto_split'></div>";
  226. /*
  227. //查内容
  228. if ($count_return < 2) {
  229. $word1 = $org_word;
  230. $wordInMean = "%$org_word%";
  231. echo "包含 $org_word 的:<br />";
  232. $query = "SELECT dict.dict_id,dict.word,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where mean like ? limit 0,30";
  233. $Fetch = PDO_FetchAll($query, array($wordInMean));
  234. $iFetch = count($Fetch);
  235. $count_return += $iFetch;
  236. if ($iFetch > 0) {
  237. for ($i = 0; $i < $iFetch; $i++) {
  238. $mean = $Fetch[$i]["mean"];
  239. $pos = mb_stripos($mean, $word, 0, "UTF-8");
  240. if ($pos) {
  241. if ($pos > 20) {
  242. $start = $pos - 20;
  243. } else {
  244. $start = 0;
  245. }
  246. $newmean = mb_substr($mean, $start, 100, "UTF-8");
  247. } else {
  248. $newmean = $mean;
  249. }
  250. $pos = mb_stripos($newmean, $word1, 0, "UTF-8");
  251. $head = mb_substr($newmean, 0, $pos, "UTF-8");
  252. $mid = mb_substr($newmean, $pos, mb_strlen($word1, "UTF-8"), "UTF-8");
  253. $end = mb_substr($newmean, $pos + mb_strlen($word1, "UTF-8"), null, "UTF-8");
  254. $heigh_light_mean = "$head<hl>$mid</hl>$end";
  255. echo "<div class='dict_word'>";
  256. echo "<div class='pali'>" . $Fetch[$i]["word"] . "</div>";
  257. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  258. echo "<div class='mean'>" . $heigh_light_mean . "</div>";
  259. echo "</div>";
  260. }
  261. }
  262. }
  263. */
  264. echo "<div id='dictlist'>";
  265. foreach ($dict_list_a as $x_value) {
  266. if (substr($x_value[0], 0, 4) == "word") {
  267. echo "<div class='pali_spell'>";
  268. echo "<a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  269. } else {
  270. echo "<div><a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  271. }
  272. }
  273. echo "<div>";
  274. $arrWords = countWordInPali($word, true);
  275. $weight = 0;
  276. foreach ($arrWords as $oneword) {
  277. $weight += $oneword["count"] * $oneword["len"];
  278. }
  279. //echo "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  280. //echo "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
  281. $right_word_list .= "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  282. $right_word_list .= "<div>{$_local->gui->real_declension}:" . count($arrWords) . " {$_local->gui->forms}</div>";
  283. foreach ($arrWords as $oneword) {
  284. if ($oneword["bold"] > 0) {
  285. //echo "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  286. $right_word_list .= "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  287. } else {
  288. //echo "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  289. $right_word_list .= "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  290. }
  291. }
  292. echo "</div>";
  293. echo "</div>";
  294. echo "</div>";
  295. //参考字典查询结束
  296. //用户词典编辑窗口
  297. echo "<div id='dict_user' >";
  298. echo "<div><a href='word_statistics.php?word={$word}'>";
  299. echo "<svg t='1596783175334' class='icon' style='font-size: xxx-large; fill: var(--link-hover-color); margin: 5px;' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='7755' width='200' height='200'><path d='M1019.904 450.56L536.576 557.056l417.792 208.896C999.424 692.224 1024 606.208 1024 512c0-20.48 0-40.96-4.096-61.44z m-12.288-61.44C958.464 184.32 786.432 28.672 573.44 4.096L446.464 512l561.152-122.88zM737.28 970.752c73.728-36.864 139.264-90.112 188.416-159.744L507.904 602.112l229.376 368.64zM512 0C229.376 0 0 229.376 0 512s229.376 512 512 512c61.44 0 118.784-12.288 172.032-28.672L385.024 512 512 0z' p-id='7756'></path></svg>";
  300. echo "<span>{$_local->gui->click_to_chart}</span></a></div>";
  301. echo $right_word_list;
  302. /*
  303. echo "<div class='dict_word' ><b>{$_local->gui->undone_function}</b>";
  304. echo "<div class='' onclick=\"dict_show_edit()\">{$_local->gui->edit}</div>";
  305. echo "<div class='pali'>{$word}</div>";
  306. if ($iFetch > 0) {
  307. echo "<div id='user_word_edit' style='display:none'>";
  308. } else {
  309. echo "<div id='user_word_edit'>";
  310. }
  311. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->wordtype}</legend>";
  312. echo "<select id=\"id_type\" name=\"type\" >";
  313. foreach ($_local->type_str as $type) {
  314. echo "<option value=\"{$type->id}\" >{$type->value}</option>";
  315. }
  316. echo "</select>";
  317. echo "</fieldset>";
  318. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->gramma}</legend><input type='input' value=''/></fieldset>";
  319. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->parent}</legend><input type='input' value=''/></fieldset>";
  320. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->g_mean}</legend><input type='input' value=''/></fieldset>";
  321. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->note}</legend><textarea></textarea></fieldset>";
  322. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->factor}</legend><input type='input' value=''/></fieldset>";
  323. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->f_mean}</legend><input type='input' value=''/></fieldset>";
  324. echo "<div class=''><button>{$_local->gui->add_to} {$_local->gui->my_dictionary}</button></div>";
  325. echo "</div>";
  326. echo "</div>";
  327. */
  328. echo "</div>";
  329. //查用户词典结束