dict_lookup.php 14 KB

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