dict_lookup.php 14 KB

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