dict_lookup.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. //社区字典开始
  149. PDO_Connect("sqlite:"._FILE_DB_WBW_);
  150. $query = "select * from dict where \"pali\"= ".$PDO->quote($word)." limit 0,100";
  151. $Fetch = PDO_FetchAll($query);
  152. $iFetch=count($Fetch);
  153. $count_return+=$iFetch;
  154. if($iFetch>0){
  155. $userlist = array();
  156. foreach($Fetch as $value){
  157. if(isset($userlist[$value["creator"]])){
  158. $userlist[$value["creator"]] += 1;
  159. }
  160. else{
  161. $userlist[$value["creator"]] = 1;
  162. }
  163. $userwordcase = $value["type"]."#".$value["gramma"];
  164. if(isset($userdict["{$userwordcase}"])){
  165. $userdict["{$userwordcase}"]["mean"] .= $value["mean"].";";
  166. $userdict["{$userwordcase}"]["factors"] .= $value["factors"];
  167. }
  168. else{
  169. $userdict["{$userwordcase}"]["mean"] = $value["mean"];
  170. $userdict["{$userwordcase}"]["factors"] = $value["factors"];
  171. }
  172. /*
  173. $mean=$Fetch[$i]["mean"];
  174. echo "<div class='dict_word'>";
  175. echo "<div class='pali'>{$word}</div>";
  176. echo "<div class=''>语法:{$Fetch[$i]["type"]}-{$Fetch[$i]["gramma"]}</div>";
  177. if(strlen($Fetch[$i]["parent"])>0){
  178. echo "<div class=''>语基:{$Fetch[$i]["parent"]}</div>";
  179. }
  180. echo "<div class=''>意思:{$Fetch[$i]["mean"]}</div>";
  181. if(strlen($Fetch[$i]["note"]>0)){
  182. echo "<div class=''>注解:{$Fetch[$i]["note"]}</div>";
  183. }
  184. echo "<div class=''>组分:{$Fetch[$i]["factors"]}</div>";
  185. echo "<div class=''>组分意思:{$Fetch[$i]["factormean"]}</div>";
  186. echo "<div class=''>贡献者:{$Fetch[$i]["creator"]}</div>";
  187. echo "<div class=''>收藏:{$Fetch[$i]["ref_counter"]}次</div>";
  188. echo "</div>";
  189. */
  190. }
  191. echo "<div class='dict_word'>";
  192. echo "<div class='dict'>社区字典</div>";
  193. foreach($userdict as $key => $value){
  194. echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
  195. }
  196. echo "<div><span>贡献者:</span>";
  197. foreach ($userlist as $key => $value) {
  198. echo $key."[".$value."]";
  199. }
  200. echo "</div>";
  201. echo "</div>";
  202. }
  203. //社区字典结束
  204. PDO_Connect("sqlite:"._FILE_DB_REF_);
  205. //直接查询
  206. $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";
  207. $Fetch = PDO_FetchAll($query);
  208. $iFetch=count($Fetch);
  209. $count_return+=$iFetch;
  210. if($iFetch>0){
  211. for($i=0;$i<$iFetch;$i++){
  212. $mean=$Fetch[$i]["mean"];
  213. $dictid=$Fetch[$i]["dict_id"];
  214. $dict_list[$dictid]=$Fetch[$i]["shortname"];
  215. $outXml = "<div class='dict_word'>";
  216. $outXml = $outXml."<a name='ref_dict_$dictid'></a>";
  217. $outXml = $outXml."<div class='dict'>".$Fetch[$i]["shortname"]."</div>";
  218. $outXml = $outXml."<div class='mean'>".$mean."</div>";
  219. $outXml = $outXml."</div>";
  220. echo $outXml;
  221. }
  222. }
  223. //去除尾查
  224. $newWord=array();
  225. for ($row = 0; $row < count($case); $row++) {
  226. $len=mb_strlen($case[$row][1],"UTF-8");
  227. $end=mb_substr($word, 0-$len,NULL,"UTF-8");
  228. if($end==$case[$row][1]){
  229. $base=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$case[$row][0];
  230. if($base!=$word){
  231. if(isset($newWord[$base])){
  232. $newWord[$base] .= "<br />".$case[$row][2];
  233. }
  234. else{
  235. $newWord[$base] = $case[$row][2];
  236. }
  237. }
  238. }
  239. }
  240. if(count($newWord)>0){
  241. foreach($newWord as $x=>$x_value) {
  242. $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";
  243. $Fetch = PDO_FetchAll($query);
  244. $iFetch=count($Fetch);
  245. $count_return+=$iFetch;
  246. if($iFetch>0){
  247. echo $x . ":<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. 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 "Junction:<br />";
  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 as $x=>$x_value) {
  335. echo "<div><a href='#ref_dict_$x'>$x_value</a></div>";
  336. }
  337. echo "<div>";
  338. $arrWords = countWordInPali($word,true);
  339. echo "<div>".count($arrWords)."个相关单词</div>";
  340. $weight = 0;
  341. foreach($arrWords as $oneword){
  342. $weight += $oneword["count"] * $oneword["len"];
  343. }
  344. echo "<div>单词总重量:$weight</div>";
  345. echo "<div><a href='word_statistics.php?word={$word}' target='_blank'>单词分析</a></div>";
  346. foreach($arrWords as $oneword){
  347. if($oneword["bold"]>0){
  348. echo "<div><b>{$oneword["word"]}</b>[{$oneword["count"]}]</div>";
  349. }
  350. else{
  351. echo "<div>{$oneword["word"]}[{$oneword["count"]}]</div>";
  352. }
  353. }
  354. echo "</div>";
  355. echo "</div>";
  356. echo "</div>";
  357. //参考字典查询结束
  358. //用户词典
  359. echo "<div id='dict_user' >";
  360. echo "<div class='dict_word'>";
  361. echo "<div class='' onclick=\"dict_show_edit()\">编辑并收藏</div>";
  362. echo "<div class='pali'>{$word}</div>";
  363. if($iFetch>0){
  364. echo "<div id='user_word_edit' style='display:none'>";
  365. }
  366. else{
  367. echo "<div id='user_word_edit'>";
  368. }
  369. echo "<fieldset class='broder-1 broder-r'><legend>Type</legend>";
  370. echo "<select id=\"id_type\" name=\"type\" >";
  371. foreach($_local->type_str as $type){
  372. echo "<option value=\"{$type->id}\" >{$type->value}</option>";
  373. }
  374. echo "</select>";
  375. echo "</fieldset>";
  376. echo "<fieldset class='broder-1 broder-r'><legend>Gramma</legend><input type='input' value=''/></fieldset>";
  377. echo "<fieldset class='broder-1 broder-r'><legend>语基</legend><input type='input' value=''/></fieldset>";
  378. echo "<fieldset class='broder-1 broder-r'><legend>意思</legend><input type='input' value=''/></fieldset>";
  379. echo "<fieldset class='broder-1 broder-r'><legend>注解</legend><textarea></textarea></fieldset>";
  380. echo "<fieldset class='broder-1 broder-r'><legend>组分</legend><input type='input' value=''/></fieldset>";
  381. echo "<fieldset class='broder-1 broder-r'><legend>组分意思</legend><input type='input' value=''/></fieldset>";
  382. echo "<div class=''><button>添加到我的单词本</button></div>";
  383. echo "</div>";
  384. echo "</div>";
  385. echo "</div>";
  386. //查用户词典结束
  387. break;
  388. }
  389. ?>