dict_lookup.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. echo "<div id='dict_list_shell' onclick='setNaviVisibility()'><div id='dict_list' class='dict_list_off'></div></div>";
  149. echo "<div id='dict_ref'>";
  150. $dict_list_a = [];
  151. //社区字典开始
  152. PDO_Connect("sqlite:"._FILE_DB_WBW_);
  153. $query = "select * from dict where \"pali\"= ".$PDO->quote($word)." limit 0,100";
  154. $Fetch = PDO_FetchAll($query);
  155. $iFetch=count($Fetch);
  156. $count_return+=$iFetch;
  157. if($iFetch>0){
  158. $userlist = array();
  159. foreach($Fetch as $value){
  160. if(isset($userlist[$value["creator"]])){
  161. $userlist[$value["creator"]] += 1;
  162. }
  163. else{
  164. $userlist[$value["creator"]] = 1;
  165. }
  166. $userwordcase = $value["type"]."#".$value["gramma"];
  167. if(isset($userdict["{$userwordcase}"])){
  168. $userdict["{$userwordcase}"]["mean"] .= $value["mean"].";";
  169. $userdict["{$userwordcase}"]["factors"] .= $value["factors"];
  170. }
  171. else{
  172. $userdict["{$userwordcase}"]["mean"] = $value["mean"];
  173. $userdict["{$userwordcase}"]["factors"] = $value["factors"];
  174. }
  175. }
  176. echo "<div class='dict_word'>";
  177. echo "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
  178. $dict_list_a[] = array("net",$_local->gui->com_dict);
  179. foreach($userdict as $key => $value){
  180. echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
  181. }
  182. echo "<div><span>{$_local->gui->contributor}:</span>";
  183. foreach ($userlist as $key => $value) {
  184. echo $key."[".$value."]";
  185. }
  186. echo "</div>";
  187. echo "</div>";
  188. }
  189. //社区字典结束
  190. PDO_Connect("sqlite:"._FILE_DB_REF_);
  191. //直接查询
  192. $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";
  193. $Fetch = PDO_FetchAll($query);
  194. $iFetch=count($Fetch);
  195. $count_return+=$iFetch;
  196. if($iFetch>0){
  197. for($i=0;$i<$iFetch;$i++){
  198. $mean=$Fetch[$i]["mean"];
  199. $dictid=$Fetch[$i]["dict_id"];
  200. $dict_list[$dictid]=$Fetch[$i]["shortname"];
  201. $dict_list_a[] = array("ref_dict_$dictid",$Fetch[$i]["shortname"]);
  202. $outXml = "<div class='dict_word'>";
  203. $outXml = $outXml."<a name='ref_dict_$dictid'></a>";
  204. $outXml = $outXml."<div class='dict'>".$Fetch[$i]["shortname"]."</div>";
  205. $outXml = $outXml."<div class='mean'>".$mean."</div>";
  206. $outXml = $outXml."</div>";
  207. echo $outXml;
  208. }
  209. }
  210. //去除尾查
  211. $newWord=array();
  212. for ($row = 0; $row < count($case); $row++) {
  213. $len=mb_strlen($case[$row][1],"UTF-8");
  214. $end=mb_substr($word, 0-$len,NULL,"UTF-8");
  215. if($end==$case[$row][1]){
  216. $base=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$case[$row][0];
  217. if($base!=$word){
  218. $thiscase = "";
  219. $arrCase = explode('$',$case[$row][2]);
  220. foreach($arrCase as $value){
  221. $caseid = "grammar_".str_replace('.','',$value);
  222. $thiscase .= "<guide gid='$caseid'>$value</guide>";
  223. }
  224. if(isset($newWord[$base])){
  225. $newWord[$base] .= "<br />".$thiscase;
  226. }
  227. else{
  228. $newWord[$base] = $thiscase;
  229. }
  230. }
  231. }
  232. }
  233. if(count($newWord)>0){
  234. foreach($newWord as $x=>$x_value) {
  235. $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";
  236. $Fetch = PDO_FetchAll($query);
  237. $iFetch=count($Fetch);
  238. $count_return+=$iFetch;
  239. if($iFetch>0){
  240. $dict_list_a[] = array("word_$x",$x);
  241. echo "<div style='font-size:120%;font-weight:700;'><a name='word_$x'></a>".$x."</div>" ;
  242. //语法信息
  243. foreach($_local->grammastr as $gr){
  244. $x_value = str_replace($gr->id,$gr->value,$x_value);
  245. }
  246. echo "<div class='dict_find_gramma'>" . $x_value . "</div>";
  247. for($i=0;$i<$iFetch;$i++){
  248. $mean=$Fetch[$i]["mean"];
  249. $dictid=$Fetch[$i]["dict_id"];
  250. $dict_list[$dictid]=$Fetch[$i]["shortname"];
  251. $dict_list_a[] = array("ref_dict_$dictid",$Fetch[$i]["shortname"]);
  252. echo "<div class='dict_word'>";
  253. echo "<a name='ref_dict_$dictid'></a>";
  254. echo "<div class='dict'>".$Fetch[$i]["shortname"]."</div>";
  255. echo "<div class='mean'>".$mean."</div>";
  256. echo "</div>";
  257. }
  258. }
  259. }
  260. }
  261. //去除尾查结束
  262. //查连读词
  263. if($count_return<2){
  264. echo "<div>Junction</div>";
  265. $newWord=array();
  266. for ($row = 0; $row < count($un); $row++) {
  267. $len=mb_strlen($un[$row][1],"UTF-8");
  268. $end=mb_substr($word, 0-$len,NULL,"UTF-8");
  269. if($end==$un[$row][1]){
  270. $base=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$un[$row][0];
  271. $arr_un=explode("+",$base);
  272. foreach ($arr_un as $oneword)
  273. {
  274. echo "<a onclick='dict_pre_word_click(\"$oneword\")'>$oneword</a> + ";
  275. }
  276. echo "<br />";
  277. }
  278. }
  279. }
  280. //查内容
  281. if($count_return<2){
  282. $word1=$org_word;
  283. $wordInMean="%$org_word%";
  284. echo "include $org_word:<br />";
  285. $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";
  286. $Fetch = PDO_FetchAll($query);
  287. $iFetch=count($Fetch);
  288. $count_return+=$iFetch;
  289. if($iFetch>0){
  290. for($i=0;$i<$iFetch;$i++){
  291. $mean=$Fetch[$i]["mean"];
  292. $pos=mb_stripos($mean,$word,0,"UTF-8");
  293. if($pos){
  294. if($pos>20){
  295. $start=$pos-20;
  296. }
  297. else{
  298. $start=0;
  299. }
  300. $newmean=mb_substr($mean,$start,100,"UTF-8");
  301. }
  302. else{
  303. $newmean=$mean;
  304. }
  305. $pos=mb_stripos($newmean,$word1,0,"UTF-8");
  306. $head=mb_substr($newmean,0,$pos,"UTF-8");
  307. $mid=mb_substr($newmean,$pos,mb_strlen($word1,"UTF-8"),"UTF-8");
  308. $end=mb_substr($newmean,$pos+mb_strlen($word1,"UTF-8"),NULL,"UTF-8");
  309. $heigh_light_mean="$head<hl>$mid</hl>$end";
  310. echo "<div class='dict_word'>";
  311. echo "<div class='pali'>".$Fetch[$i]["word"]."</div>";
  312. echo "<div class='dict'>".$Fetch[$i]["shortname"]."</div>";
  313. echo "<div class='mean'>".$heigh_light_mean."</div>";
  314. echo "</div>";
  315. }
  316. }
  317. }
  318. //拆复合词
  319. $splitWord=$word;
  320. $part=array();
  321. if($count_return<2){
  322. echo "Try to split comp:<br>";
  323. while(($split=mySplit($splitWord))!==FALSE){
  324. array_push($part,$split[0]);
  325. $splitWord=$split[1];
  326. }
  327. if(count($part)>0){
  328. array_push($part,$splitWord);
  329. $newPart=ltrim(array_reduce($part,"myfunction"),"+");
  330. echo $newPart;
  331. }
  332. }
  333. echo "<div id='dictlist'>";
  334. foreach($dict_list_a as $x_value) {
  335. if(substr($x_value[0],0,4)=="word"){
  336. echo "<div style='font-size:120%;font-weight:700;margin-top:15px;'>";
  337. echo "<a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  338. }
  339. else{
  340. echo "<div><a href='#{$x_value[0]}'>$x_value[1]</a></div>";
  341. }
  342. }
  343. echo "<div>";
  344. $arrWords = countWordInPali($word,true);
  345. $weight = 0;
  346. foreach($arrWords as $oneword){
  347. $weight += $oneword["count"] * $oneword["len"];
  348. }
  349. //echo "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  350. //echo "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
  351. $right_word_list .= "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
  352. $right_word_list .= "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
  353. foreach($arrWords as $oneword){
  354. if($oneword["bold"]>0){
  355. //echo "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  356. $right_word_list .= "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
  357. }
  358. else{
  359. //echo "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  360. $right_word_list .= "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
  361. }
  362. }
  363. echo "</div>";
  364. echo "</div>";
  365. echo "</div>";
  366. //参考字典查询结束
  367. //用户词典编辑窗口
  368. echo "<div id='dict_user' >";
  369. echo "<div><a href='word_statistics.php?word={$word}'>";
  370. 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>";
  371. echo "<br>{$_local->gui->click_to_chart}</a></div>";
  372. echo $right_word_list;
  373. echo "<div class='dict_word' ><b>{$_local->gui->undone_function}</b>";
  374. echo "<div class='' onclick=\"dict_show_edit()\">{$_local->gui->edit}</div>";
  375. echo "<div class='pali'>{$word}</div>";
  376. if($iFetch>0){
  377. echo "<div id='user_word_edit' style='display:none'>";
  378. }
  379. else{
  380. echo "<div id='user_word_edit'>";
  381. }
  382. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->wordtype}</legend>";
  383. echo "<select id=\"id_type\" name=\"type\" >";
  384. foreach($_local->type_str as $type){
  385. echo "<option value=\"{$type->id}\" >{$type->value}</option>";
  386. }
  387. echo "</select>";
  388. echo "</fieldset>";
  389. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->gramma}</legend><input type='input' value=''/></fieldset>";
  390. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->parent}</legend><input type='input' value=''/></fieldset>";
  391. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->g_mean}</legend><input type='input' value=''/></fieldset>";
  392. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->note}</legend><textarea></textarea></fieldset>";
  393. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->factor}</legend><input type='input' value=''/></fieldset>";
  394. echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->f_mean}</legend><input type='input' value=''/></fieldset>";
  395. echo "<div class=''><button>{$_local->gui->add_to} {$_local->gui->my_dictionary}</button></div>";
  396. echo "</div>";
  397. echo "</div>";
  398. echo "</div>";
  399. //查用户词典结束
  400. break;
  401. }
  402. ?>