dict_lookup.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 "../dict/p_ending.php";
  12. _load_book_index();
  13. $word = mb_strtolower($_GET["word"], 'UTF-8');
  14. $org_word = $word;
  15. $count_return = 0;
  16. $dict_list = array();
  17. $right_word_list = "";
  18. add_edit_event(_DICT_LOOKUP_, $word);
  19. echo "<div id='dict_list_shell' onclick='setNaviVisibility()'>";
  20. echo "<div id='dict_list' class='dict_list_off'></div>";
  21. echo "</div>";
  22. echo "<div id='dict_ref'>";
  23. echo "<div id='search_result_shell'></div>";
  24. echo "<div class='pali_spell'><a name='{word_$word}'></a>" . $word . "</div>";
  25. $dict_list_a = [];
  26. //社区字典开始
  27. PDO_Connect("" . _FILE_DB_WBW_);
  28. $query = "SELECT * from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
  29. $Fetch = PDO_FetchAll($query, array($word));
  30. $iFetch = count($Fetch);
  31. $count_return += $iFetch;
  32. if ($iFetch > 0) {
  33. $userlist = array();
  34. foreach ($Fetch as $value) {
  35. if (isset($userlist[$value["creator"]])) {
  36. $userlist[$value["creator"]] += 1;
  37. } else {
  38. $userlist[$value["creator"]] = 1;
  39. }
  40. $userwordcase = $value["type"] . "#" . $value["gramma"];
  41. if (isset($userdict["{$userwordcase}"])) {
  42. $userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
  43. $userdict["{$userwordcase}"]["factors"] .= $value["factors"];
  44. } else {
  45. $userdict["{$userwordcase}"]["mean"] = $value["mean"];
  46. $userdict["{$userwordcase}"]["factors"] = $value["factors"];
  47. }
  48. }
  49. echo "<div class='dict_word'>";
  50. echo "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
  51. $dict_list_a[] = array("net", $_local->gui->com_dict);
  52. foreach ($userdict as $key => $value) {
  53. echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
  54. }
  55. echo "<div><span>{$_local->gui->contributor}:</span>";
  56. foreach ($userlist as $key => $value) {
  57. echo $key . "[" . $value . "]";
  58. }
  59. echo "</div>";
  60. echo "</div>";
  61. }
  62. //社区字典结束
  63. PDO_Connect("" . _FILE_DB_REF_);
  64. //直接查询
  65. $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";
  66. $Fetch = PDO_FetchAll($query, array($word));
  67. $iFetch = count($Fetch);
  68. $count_return += $iFetch;
  69. if ($iFetch > 0) {
  70. for ($i = 0; $i < $iFetch; $i++) {
  71. $mean = $Fetch[$i]["mean"];
  72. $dictid = $Fetch[$i]["dict_id"];
  73. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  74. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  75. $outXml = "<div class='dict_word'>";
  76. $outXml = $outXml . "<a name='ref_dict_$dictid'></a>";
  77. $outXml = $outXml . "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  78. $outXml = $outXml . "<div class='mean'>" . $mean . "</div>";
  79. $outXml = $outXml . "</div>";
  80. echo $outXml;
  81. }
  82. }
  83. //去格位除尾查
  84. $newWord = array();
  85. for ($row = 0; $row < count($case); $row++) {
  86. $len = mb_strlen($case[$row][1], "UTF-8");
  87. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  88. if ($end == $case[$row][1]) {
  89. $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][0];
  90. if ($base != $word) {
  91. $thiscase = "";
  92. $arrCase = explode('$', $case[$row][2]);
  93. foreach ($arrCase as $value) {
  94. $caseid = "grammar_" . str_replace('.', '', $value);
  95. $thiscase .= "<guide gid='$caseid'>$value</guide>";
  96. }
  97. if (isset($newWord[$base])) {
  98. $newWord[$base] .= "<br />" . $thiscase;
  99. } else {
  100. $newWord[$base] = $thiscase;
  101. }
  102. }
  103. }
  104. }
  105. $base_list = array();
  106. if (count($newWord) > 0) {
  107. foreach ($newWord as $x => $x_value) {
  108. $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";
  109. $Fetch = PDO_FetchAll($query, array($x));
  110. $iFetch = count($Fetch);
  111. $count_return += $iFetch;
  112. if ($iFetch > 0) {
  113. $base_list[] = $x;
  114. $dict_list_a[] = array("word_$x", $x);
  115. echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
  116. //语法信息
  117. foreach ($_local->grammastr as $gr) {
  118. $x_value = str_replace($gr->id, $gr->value, $x_value);
  119. }
  120. echo "<div class='dict_find_gramma'>" . $x_value . "</div>";
  121. for ($i = 0; $i < $iFetch; $i++) {
  122. $mean = $Fetch[$i]["mean"];
  123. $dictid = $Fetch[$i]["dict_id"];
  124. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  125. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  126. echo "<div class='dict_word'>";
  127. echo "<a name='ref_dict_$dictid'></a>";
  128. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  129. echo "<div class='mean'>" . $mean . "</div>";
  130. echo "</div>";
  131. }
  132. }
  133. }
  134. }
  135. //去除尾查结束
  136. //去分词除尾查
  137. $arrBase = array();
  138. if (count($newWord) > 0) {
  139. foreach ($newWord as $base => $grammar){
  140. for ($row = 0; $row < count($p_ending); $row++) {
  141. $len = mb_strlen($case[$row][1], "UTF-8");
  142. $end = mb_substr($base, 0 - $len, null, "UTF-8");
  143. if ($end == $p_ending[$row][1]) {
  144. $newbase = mb_substr($base, 0, mb_strlen($base, "UTF-8") - $len, "UTF-8") . $p_ending[$row][0];
  145. if ($newbase != $base) {
  146. $thiscase = "";
  147. $arrCase = explode('$', $p_ending[$row][2]);
  148. foreach ($arrCase as $value) {
  149. $caseid = "grammar_" . str_replace('.', '', $value);
  150. $thiscase .= "<guide gid='$caseid'>$value</guide>";
  151. }
  152. if (isset($arrBase[$newbase])) {
  153. $arrBase[$newbase]['grammar'] .= "<br />" . $thiscase;
  154. } else {
  155. $arrBase[$newbase]['grammar'] = $thiscase;
  156. $arrBase[$newbase]['parent'] = $base;
  157. }
  158. }
  159. }
  160. }
  161. }
  162. $base_list = array();
  163. if (count($arrBase) > 0) {
  164. foreach ($arrBase as $x => $x_value) {
  165. $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";
  166. $Fetch = PDO_FetchAll($query, array($x));
  167. $iFetch = count($Fetch);
  168. $count_return += $iFetch;
  169. if ($iFetch > 0) {
  170. $base_list[] = $x;
  171. $dict_list_a[] = array("word_$x", $x);
  172. echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
  173. echo "<div style='color:gray;'>{$x}->{$x_value["parent"]}->{$word}</div>";
  174. //语法信息
  175. foreach ($_local->grammastr as $gr) {
  176. $x_value['grammar'] = str_replace($gr->id, $gr->value, $x_value['grammar']);
  177. }
  178. echo "<div class='dict_find_gramma'>" . $x_value['grammar'] . "</div>";
  179. for ($i = 0; $i < $iFetch; $i++) {
  180. $mean = $Fetch[$i]["mean"];
  181. $dictid = $Fetch[$i]["dict_id"];
  182. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  183. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  184. echo "<div class='dict_word'>";
  185. echo "<a name='ref_dict_$dictid'></a>";
  186. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  187. echo "<div class='mean'>" . $mean . "</div>";
  188. echo "</div>";
  189. }
  190. }
  191. }
  192. }
  193. }
  194. //去除尾查结束
  195. echo "<div id='search_summary'>";
  196. echo "查询{$word} 共{$count_return}条 ";
  197. if(count($base_list)>0){
  198. echo "找到可能的拼写: ";
  199. foreach ($base_list as $key => $value) {
  200. # code...
  201. echo "<a>{$value}</a> ";
  202. }
  203. }
  204. echo "</div>";
  205. echo "<input type='hidden' id='word_count' value='{$count_return}' />";
  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. echo "<div id='auto_split'></div>";
  225. /*
  226. //查内容
  227. if ($count_return < 2) {
  228. $word1 = $org_word;
  229. $wordInMean = "%$org_word%";
  230. echo "包含 $org_word 的:<br />";
  231. $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";
  232. $Fetch = PDO_FetchAll($query, array($wordInMean));
  233. $iFetch = count($Fetch);
  234. $count_return += $iFetch;
  235. if ($iFetch > 0) {
  236. for ($i = 0; $i < $iFetch; $i++) {
  237. $mean = $Fetch[$i]["mean"];
  238. $pos = mb_stripos($mean, $word, 0, "UTF-8");
  239. if ($pos) {
  240. if ($pos > 20) {
  241. $start = $pos - 20;
  242. } else {
  243. $start = 0;
  244. }
  245. $newmean = mb_substr($mean, $start, 100, "UTF-8");
  246. } else {
  247. $newmean = $mean;
  248. }
  249. $pos = mb_stripos($newmean, $word1, 0, "UTF-8");
  250. $head = mb_substr($newmean, 0, $pos, "UTF-8");
  251. $mid = mb_substr($newmean, $pos, mb_strlen($word1, "UTF-8"), "UTF-8");
  252. $end = mb_substr($newmean, $pos + mb_strlen($word1, "UTF-8"), null, "UTF-8");
  253. $heigh_light_mean = "$head<hl>$mid</hl>$end";
  254. echo "<div class='dict_word'>";
  255. echo "<div class='pali'>" . $Fetch[$i]["word"] . "</div>";
  256. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  257. echo "<div class='mean'>" . $heigh_light_mean . "</div>";
  258. echo "</div>";
  259. }
  260. }
  261. }
  262. */
  263. echo "<div id='dictlist'>";
  264. foreach ($dict_list_a as $x_value) {
  265. if (substr($x_value[0], 0, 4) == "word") {
  266. echo "<div class='pali_spell'>";
  267. echo "<a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  268. } else {
  269. echo "<div><a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  270. }
  271. }
  272. echo "<div>";
  273. $arrWords = countWordInPali($word, true);
  274. $weight = 0;
  275. foreach ($arrWords as $oneword) {
  276. $weight += $oneword["count"] * $oneword["len"];
  277. }
  278. //echo "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  279. //echo "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
  280. $right_word_list .= "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  281. $right_word_list .= "<div>{$_local->gui->real_declension}:" . count($arrWords) . " {$_local->gui->forms}</div>";
  282. foreach ($arrWords as $oneword) {
  283. if ($oneword["bold"] > 0) {
  284. //echo "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  285. $right_word_list .= "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  286. } else {
  287. //echo "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  288. $right_word_list .= "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  289. }
  290. }
  291. echo "</div>";
  292. echo "</div>";
  293. echo "</div>";
  294. //参考字典查询结束
  295. //用户词典编辑窗口
  296. echo "<div id='dict_user' >";
  297. echo "<div><a href='word_statistics.php?word={$word}'>";
  298. 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>";
  299. echo "<span>{$_local->gui->click_to_chart}</span></a></div>";
  300. echo $right_word_list;
  301. echo "<div class='dict_word' ><b>{$_local->gui->undone_function}</b>";
  302. echo "<div class='' onclick=\"dict_show_edit()\">{$_local->gui->edit}</div>";
  303. echo "<div class='pali'>{$word}</div>";
  304. if ($iFetch > 0) {
  305. echo "<div id='user_word_edit' style='display:none'>";
  306. } else {
  307. echo "<div id='user_word_edit'>";
  308. }
  309. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->wordtype}</legend>";
  310. echo "<select id=\"id_type\" name=\"type\" >";
  311. foreach ($_local->type_str as $type) {
  312. echo "<option value=\"{$type->id}\" >{$type->value}</option>";
  313. }
  314. echo "</select>";
  315. echo "</fieldset>";
  316. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->gramma}</legend><input type='input' value=''/></fieldset>";
  317. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->parent}</legend><input type='input' value=''/></fieldset>";
  318. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->g_mean}</legend><input type='input' value=''/></fieldset>";
  319. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->note}</legend><textarea></textarea></fieldset>";
  320. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->factor}</legend><input type='input' value=''/></fieldset>";
  321. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->f_mean}</legend><input type='input' value=''/></fieldset>";
  322. echo "<div class=''><button>{$_local->gui->add_to} {$_local->gui->my_dictionary}</button></div>";
  323. echo "</div>";
  324. echo "</div>";
  325. echo "</div>";
  326. //查用户词典结束