dict_lookup.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. _load_book_index();
  12. $op = $_GET["op"];
  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. global $PDO;
  19. function isExsit($word)
  20. {
  21. global $PDO;
  22. $query = "SELECT count(*) as co from " . _TABLE_DICT_REF_ . " where word = ? ";
  23. $row = PDO_FetchOne($query, array($word));
  24. if ($row[0] == 0) {
  25. return false;
  26. } else {
  27. return true;
  28. }
  29. }
  30. function myfunction($v1, $v2)
  31. {
  32. return $v1 . "+" . $v2;
  33. }
  34. function mySplit($strWord)
  35. {
  36. //echo("<br>".$strWord."<br>");
  37. $doubleword = "kkggccjjṭṭḍḍttddppbb";
  38. $len = mb_strlen($strWord, "UTF-8");
  39. if ($len > 5) {
  40. for ($i = $len - 1; $i > 3; $i--) {
  41. $str1 = mb_substr($strWord, 0, $i, "UTF-8");
  42. $str2 = mb_substr($strWord, $i, null, "UTF-8");
  43. //echo "$str1 + $str2 = ";
  44. if (isExsit($str1)) {
  45. //echo "match";
  46. $left2 = mb_substr($str2, 0, 2, "UTF-8");
  47. if (mb_strpos($doubleword, $left2, 0, "UTF-8") !== false) {
  48. $str2 = mb_substr($str2, 1, null, "UTF-8");
  49. }
  50. return array($str1, $str2);
  51. } else {
  52. $str1 = $str1 . "a";
  53. if (isExsit($str1)) {
  54. //echo "match";
  55. $left2 = mb_substr($str2, 0, 2, "UTF-8");
  56. if (mb_strpos($doubleword, $left2, 0, "UTF-8") !== false) {
  57. $str2 = mb_substr($str2, 1, null, "UTF-8");
  58. }
  59. return array($str1, $str2);
  60. }
  61. }
  62. }
  63. //not found
  64. if (mb_substr($strWord, 0, 1, "UTF-8") == "ā") {
  65. $strWord = 'a' . mb_substr($strWord, 1, null, "UTF-8");
  66. for ($i = $len - 1; $i > 3; $i--) {
  67. $str1 = mb_substr($strWord, 0, $i, "UTF-8");
  68. $str2 = mb_substr($strWord, $i, null, "UTF-8");
  69. //echo "$str1 + $str2 = ";
  70. if (isExsit($str1)) {
  71. //echo "match";
  72. $left2 = mb_substr($str2, 0, 2, "UTF-8");
  73. if (mb_strpos($doubleword, $left2, 0, "UTF-8") !== false) {
  74. $str2 = mb_substr($str2, 1, null, "UTF-8");
  75. }
  76. return array($str1, $str2);
  77. } else {
  78. $str1 = $str1 . "a";
  79. if (isExsit($str1)) {
  80. //echo "match";
  81. $left2 = mb_substr($str2, 0, 2, "UTF-8");
  82. if (mb_strpos($doubleword, $left2, 0, "UTF-8") !== false) {
  83. $str2 = mb_substr($str2, 1, null, "UTF-8");
  84. }
  85. return array($str1, $str2);
  86. }
  87. }
  88. }
  89. }
  90. //not found
  91. if (mb_substr($strWord, 0, 1, "UTF-8") == "e") {
  92. $strWord = 'i' . mb_substr($strWord, 1, null, "UTF-8");
  93. for ($i = $len - 1; $i > 3; $i--) {
  94. $str1 = mb_substr($strWord, 0, $i, "UTF-8");
  95. $str2 = mb_substr($strWord, $i, null, "UTF-8");
  96. //echo "$str1 + $str2 = ";
  97. if (isExsit($str1)) {
  98. //echo "match";
  99. $left2 = mb_substr($str2, 0, 2, "UTF-8");
  100. if (mb_strpos($doubleword, $left2, 0, "UTF-8") !== false) {
  101. $str2 = mb_substr($str2, 1, null, "UTF-8");
  102. }
  103. return array($str1, $str2);
  104. } else {
  105. $str1 = $str1 . "a";
  106. if (isExsit($str1)) {
  107. //echo "match";
  108. $left2 = mb_substr($str2, 0, 2, "UTF-8");
  109. if (mb_strpos($doubleword, $left2, 0, "UTF-8") !== false) {
  110. $str2 = mb_substr($str2, 1, null, "UTF-8");
  111. }
  112. return array($str1, $str2);
  113. }
  114. }
  115. }
  116. }
  117. }
  118. return (false);
  119. }
  120. add_edit_event(_DICT_LOOKUP_, $word);
  121. echo "<div id='dict_list_shell' onclick='setNaviVisibility()'><div id='dict_list' class='dict_list_off'></div></div>";
  122. echo "<div id='dict_ref'>";
  123. $dict_list_a = [];
  124. //社区字典开始
  125. PDO_Connect("" . _FILE_DB_WBW_);
  126. $query = "SELECT * from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
  127. $Fetch = PDO_FetchAll($query, array($word));
  128. $iFetch = count($Fetch);
  129. $count_return += $iFetch;
  130. if ($iFetch > 0) {
  131. $userlist = array();
  132. foreach ($Fetch as $value) {
  133. if (isset($userlist[$value["creator"]])) {
  134. $userlist[$value["creator"]] += 1;
  135. } else {
  136. $userlist[$value["creator"]] = 1;
  137. }
  138. $userwordcase = $value["type"] . "#" . $value["gramma"];
  139. if (isset($userdict["{$userwordcase}"])) {
  140. $userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
  141. $userdict["{$userwordcase}"]["factors"] .= $value["factors"];
  142. } else {
  143. $userdict["{$userwordcase}"]["mean"] = $value["mean"];
  144. $userdict["{$userwordcase}"]["factors"] = $value["factors"];
  145. }
  146. }
  147. echo "<div class='dict_word'>";
  148. echo "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
  149. $dict_list_a[] = array("net", $_local->gui->com_dict);
  150. foreach ($userdict as $key => $value) {
  151. echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
  152. }
  153. echo "<div><span>{$_local->gui->contributor}:</span>";
  154. foreach ($userlist as $key => $value) {
  155. echo $key . "[" . $value . "]";
  156. }
  157. echo "</div>";
  158. echo "</div>";
  159. }
  160. //社区字典结束
  161. PDO_Connect("" . _FILE_DB_REF_);
  162. //直接查询
  163. $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";
  164. $Fetch = PDO_FetchAll($query, array($word));
  165. $iFetch = count($Fetch);
  166. $count_return += $iFetch;
  167. if ($iFetch > 0) {
  168. for ($i = 0; $i < $iFetch; $i++) {
  169. $mean = $Fetch[$i]["mean"];
  170. $dictid = $Fetch[$i]["dict_id"];
  171. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  172. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  173. $outXml = "<div class='dict_word'>";
  174. $outXml = $outXml . "<a name='ref_dict_$dictid'></a>";
  175. $outXml = $outXml . "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  176. $outXml = $outXml . "<div class='mean'>" . $mean . "</div>";
  177. $outXml = $outXml . "</div>";
  178. echo $outXml;
  179. }
  180. }
  181. //去除尾查
  182. $newWord = array();
  183. for ($row = 0; $row < count($case); $row++) {
  184. $len = mb_strlen($case[$row][1], "UTF-8");
  185. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  186. if ($end == $case[$row][1]) {
  187. $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][0];
  188. if ($base != $word) {
  189. $thiscase = "";
  190. $arrCase = explode('$', $case[$row][2]);
  191. foreach ($arrCase as $value) {
  192. $caseid = "grammar_" . str_replace('.', '', $value);
  193. $thiscase .= "<guide gid='$caseid'>$value</guide>";
  194. }
  195. if (isset($newWord[$base])) {
  196. $newWord[$base] .= "<br />" . $thiscase;
  197. } else {
  198. $newWord[$base] = $thiscase;
  199. }
  200. }
  201. }
  202. }
  203. if (count($newWord) > 0) {
  204. foreach ($newWord as $x => $x_value) {
  205. $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";
  206. $Fetch = PDO_FetchAll($query, array($x));
  207. $iFetch = count($Fetch);
  208. $count_return += $iFetch;
  209. if ($iFetch > 0) {
  210. $dict_list_a[] = array("word_$x", $x);
  211. echo "<div style='font-size:120%;font-weight:700;'><a name='word_$x'></a>" . $x . "</div>";
  212. //语法信息
  213. foreach ($_local->grammastr as $gr) {
  214. $x_value = str_replace($gr->id, $gr->value, $x_value);
  215. }
  216. echo "<div class='dict_find_gramma'>" . $x_value . "</div>";
  217. for ($i = 0; $i < $iFetch; $i++) {
  218. $mean = $Fetch[$i]["mean"];
  219. $dictid = $Fetch[$i]["dict_id"];
  220. $dict_list[$dictid] = $Fetch[$i]["shortname"];
  221. $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
  222. echo "<div class='dict_word'>";
  223. echo "<a name='ref_dict_$dictid'></a>";
  224. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  225. echo "<div class='mean'>" . $mean . "</div>";
  226. echo "</div>";
  227. }
  228. }
  229. }
  230. }
  231. //去除尾查结束
  232. //查连读词
  233. if ($count_return < 2) {
  234. echo "<div>Junction</div>";
  235. $newWord = array();
  236. for ($row = 0; $row < count($un); $row++) {
  237. $len = mb_strlen($un[$row][1], "UTF-8");
  238. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  239. if ($end == $un[$row][1]) {
  240. $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $un[$row][0];
  241. $arr_un = explode("+", $base);
  242. foreach ($arr_un as $oneword) {
  243. echo "<a onclick='dict_pre_word_click(\"$oneword\")'>$oneword</a> + ";
  244. }
  245. echo "<br />";
  246. }
  247. }
  248. }
  249. //查内容
  250. if ($count_return < 2) {
  251. $word1 = $org_word;
  252. $wordInMean = "%$org_word%";
  253. echo "include $org_word:<br />";
  254. $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";
  255. $Fetch = PDO_FetchAll($query, array($wordInMean));
  256. $iFetch = count($Fetch);
  257. $count_return += $iFetch;
  258. if ($iFetch > 0) {
  259. for ($i = 0; $i < $iFetch; $i++) {
  260. $mean = $Fetch[$i]["mean"];
  261. $pos = mb_stripos($mean, $word, 0, "UTF-8");
  262. if ($pos) {
  263. if ($pos > 20) {
  264. $start = $pos - 20;
  265. } else {
  266. $start = 0;
  267. }
  268. $newmean = mb_substr($mean, $start, 100, "UTF-8");
  269. } else {
  270. $newmean = $mean;
  271. }
  272. $pos = mb_stripos($newmean, $word1, 0, "UTF-8");
  273. $head = mb_substr($newmean, 0, $pos, "UTF-8");
  274. $mid = mb_substr($newmean, $pos, mb_strlen($word1, "UTF-8"), "UTF-8");
  275. $end = mb_substr($newmean, $pos + mb_strlen($word1, "UTF-8"), null, "UTF-8");
  276. $heigh_light_mean = "$head<hl>$mid</hl>$end";
  277. echo "<div class='dict_word'>";
  278. echo "<div class='pali'>" . $Fetch[$i]["word"] . "</div>";
  279. echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
  280. echo "<div class='mean'>" . $heigh_light_mean . "</div>";
  281. echo "</div>";
  282. }
  283. }
  284. }
  285. //拆复合词
  286. $splitWord = $word;
  287. $part = array();
  288. if ($count_return < 2) {
  289. echo "Try to split comp:<br>";
  290. while (($split = mySplit($splitWord)) !== false) {
  291. array_push($part, $split[0]);
  292. $splitWord = $split[1];
  293. }
  294. if (count($part) > 0) {
  295. array_push($part, $splitWord);
  296. $newPart = ltrim(array_reduce($part, "myfunction"), "+");
  297. echo $newPart;
  298. }
  299. }
  300. #词典列表
  301. echo "<div id='dictlist'>";
  302. foreach ($dict_list_a as $x_value) {
  303. if (substr($x_value[0], 0, 4) == "word") {
  304. echo "<div style='font-size:120%;font-weight:700;margin-top:15px;'>";
  305. echo "<a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  306. } else {
  307. echo "<div><a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  308. }
  309. }
  310. echo "<div>";
  311. #在巴利文献中出现的次数
  312. $arrWords = countWordInPali($word, true);
  313. $weight = 0;
  314. foreach ($arrWords as $oneword) {
  315. $weight += $oneword["count"] * $oneword["len"];
  316. }
  317. //echo "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  318. //echo "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
  319. $right_word_list .= "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  320. $right_word_list .= "<div>{$_local->gui->real_declension}:" . count($arrWords) . " {$_local->gui->forms}</div>";
  321. foreach ($arrWords as $oneword) {
  322. if ($oneword["bold"] > 0) {
  323. //echo "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  324. $right_word_list .= "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  325. } else {
  326. //echo "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  327. $right_word_list .= "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  328. }
  329. }
  330. echo "</div>";
  331. echo "</div>";
  332. echo "</div>";
  333. //参考字典查询结束
  334. //用户词典编辑窗口
  335. echo "<div id='dict_user' >";
  336. echo "<div><a href='word_statistics.php?word={$word}'>";
  337. 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>";
  338. echo "<br>{$_local->gui->click_to_chart}</a></div>";
  339. echo $right_word_list;
  340. echo "<div class='dict_word' ><b>{$_local->gui->undone_function}</b>";
  341. echo "<div class='' onclick=\"dict_show_edit()\">{$_local->gui->edit}</div>";
  342. echo "<div class='pali'>{$word}</div>";
  343. if ($iFetch > 0) {
  344. echo "<div id='user_word_edit' style='display:none'>";
  345. } else {
  346. echo "<div id='user_word_edit'>";
  347. }
  348. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->wordtype}</legend>";
  349. echo "<select id=\"id_type\" name=\"type\" >";
  350. foreach ($_local->type_str as $type) {
  351. echo "<option value=\"{$type->id}\" >{$type->value}</option>";
  352. }
  353. echo "</select>";
  354. echo "</fieldset>";
  355. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->gramma}</legend><input type='input' value=''/></fieldset>";
  356. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->parent}</legend><input type='input' value=''/></fieldset>";
  357. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->g_mean}</legend><input type='input' value=''/></fieldset>";
  358. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->note}</legend><textarea></textarea></fieldset>";
  359. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->factor}</legend><input type='input' value=''/></fieldset>";
  360. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->f_mean}</legend><input type='input' value=''/></fieldset>";
  361. echo "<div class=''><button>{$_local->gui->add_to} {$_local->gui->my_dictionary}</button></div>";
  362. echo "</div>";
  363. echo "</div>";
  364. echo "</div>";
  365. //查用户词典结束