dict_lookup.php 14 KB

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