dict_lookup.php 15 KB

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