dict_lookup.php 12 KB

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