dict_find_one.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. require 'checklogin.inc';
  3. include "../public/config.php";
  4. include "../public/_pdo.php";
  5. include "../public/function.php";
  6. if(isset($_GET["book"])){
  7. $in_book=$_GET["book"];
  8. }
  9. if(isset($_GET["paragraph"])){
  10. $in_para=$_GET["paragraph"];
  11. }
  12. if(isset($_GET["sn"])){
  13. $in_sn=$_GET["sn"];
  14. }
  15. if(isset($_GET["type"])){
  16. $type=$_GET["type"];
  17. }
  18. else{
  19. $type="wbw";
  20. }
  21. if(isset($_GET["dict_name"])){
  22. $dict_name=$_GET["dict_name"];
  23. }
  24. else{
  25. $dict_name="";
  26. }
  27. if($type=="part"){
  28. $lookup_loop=3;
  29. }
  30. else{
  31. $lookup_loop=3;
  32. }
  33. if(isset($_GET["deep"])){
  34. $lookup_loop=$_GET["deep"];
  35. }
  36. else{
  37. $lookup_loop=3;
  38. }
  39. $in_word=$_GET["word"];
  40. if(isset($_GET["debug"])){
  41. $debug=true;;
  42. }
  43. else{
  44. $debug=false;
  45. }
  46. if(mb_strlen($in_word)==0){
  47. exit;
  48. }
  49. function microtime_float()
  50. {
  51. list($usec, $sec) = explode(" ", microtime());
  52. return ((float)$usec + (float)$sec);
  53. }
  54. $time_start = microtime_float();
  55. $dict_file_user=$dir_user_base.$userid.$dir_dict_user.'/';
  56. $dict_file_sys=$dir_dict_system;
  57. $dict_file_third=$dir_dict_3rd;
  58. //open database
  59. global $PDO;
  60. $word_list=str_getcsv($in_word);
  61. $dict_word_spell=array();
  62. $output=array();
  63. $db_file_list=array();
  64. //用户词典
  65. if($dict_name==""){
  66. array_push($db_file_list , $_file_db_wbw);
  67. array_push($db_file_list , $dict_file_sys."sys_regular.db");
  68. array_push($db_file_list , $dict_file_sys."sys_irregular.db");
  69. array_push($db_file_list , $dict_file_sys."union.db");
  70. array_push($db_file_list , $dict_file_sys."comp.db");
  71. array_push($db_file_list , $dict_file_third."pm.db");
  72. array_push($db_file_list , $dict_file_third."bhmf.db");
  73. array_push($db_file_list , $dict_file_third."shuihan.db");
  74. array_push($db_file_list , $dict_file_third."concise.db");
  75. array_push($db_file_list , $dict_file_third."uhan_en.db");
  76. }
  77. else{
  78. $dict_list=str_getcsv($dict_name,',');
  79. foreach($dict_list as $dict){
  80. array_push($db_file_list , $dict);
  81. }
  82. }
  83. for($i=0;$i<$lookup_loop;$i++)
  84. {
  85. $parent_list=array();
  86. $strQueryWord="(";//单词查询字串
  87. foreach($word_list as $word){
  88. $word=str_replace("'","’",$word);
  89. $strQueryWord.="'{$word}',";
  90. }
  91. $strQueryWord=mb_substr($strQueryWord, 0,mb_strlen($strQueryWord,"UTF-8")-1,"UTF-8");
  92. $strQueryWord.=")";
  93. if($debug){
  94. echo "<h2>第".($i+1)."轮查询:".count($word_list)."</h2>";
  95. }
  96. foreach($db_file_list as $db_file){
  97. if($debug){
  98. echo "dict connect:$db_file<br>";
  99. }
  100. PDO_Connect("sqlite:$db_file");
  101. if($i==0){
  102. $query = "select * from dict where \"pali\" in $strQueryWord ORDER BY rowid DESC";
  103. }
  104. else{
  105. $query = "select * from dict where \"pali\" in $strQueryWord AND ( type <> '.n.' AND type <> '.ti.' AND type <> '.adj.' AND type <> '.pron.' AND type <> '.v.' ) ORDER BY rowid DESC";
  106. }
  107. if($debug){
  108. //echo $query."<br>";
  109. }
  110. $Fetch = PDO_FetchAll($query);
  111. $iFetch=count($Fetch);
  112. if($debug){
  113. echo "count:$iFetch<br>";
  114. }
  115. if($iFetch>0){
  116. foreach($Fetch as $one){
  117. $id = $one["id"];
  118. if(isset($one["guid"])){
  119. $guid = $one["guid"];
  120. }
  121. else{
  122. $guid = "";
  123. }
  124. $pali = $one["pali"];
  125. $dict_word_spell["{$pali}"]=1;
  126. $type = $one["type"];
  127. $gramma = $one["gramma"];
  128. $parent = $one["parent"];
  129. $mean = $one["mean"];
  130. $note = $one["note"];
  131. if(isset($one["factors"])){
  132. $parts = $one["factors"];
  133. }
  134. else if(isset($one["parts"])){
  135. $parts = $one["parts"];
  136. }
  137. else{
  138. $parts = "";
  139. }
  140. if(isset($one["factormean"])){
  141. $partmean = $one["factormean"];
  142. }
  143. else if(isset($one["partmean"])){
  144. $partmean = $one["partmean"];
  145. }
  146. else{
  147. $partmean = "";
  148. }
  149. $status = $one["status"];
  150. if(isset($one["confidence"])){
  151. $confidence = $one["confidence"];
  152. }
  153. else{
  154. $confidence = 100;
  155. }
  156. if(isset($one["dict_name"])){
  157. $dict_name = $one["dict_name"];
  158. }
  159. else{
  160. $dict_name = "";
  161. }
  162. if(isset($one["language"])){
  163. $language = $one["language"];
  164. }
  165. else{
  166. $language = "en";
  167. }
  168. array_push($output,array(
  169. "id"=>$id,
  170. "guid"=>$guid,
  171. "pali"=>$pali,
  172. "type"=>$type,
  173. "gramma"=>$gramma,
  174. "parent"=>$parent,
  175. "mean"=>$mean,
  176. "note"=>$note,
  177. "parts"=>$parts,
  178. "partmean"=>$partmean,
  179. "status"=>$status,
  180. "confidence"=>$confidence,
  181. "dict_name"=>$dict_name,
  182. "language"=>$language
  183. ));
  184. //将语基插入下次查询的列表
  185. if(!empty($parent)){
  186. if($pali != $parent){
  187. $parent_list[$parent]=1;
  188. }
  189. }
  190. //将拆分插入下次查询的列表
  191. if($type!=".part."){
  192. if(!empty($parts)){
  193. $wordparts=str_getcsv($parts,'+');
  194. foreach($wordparts as $x){
  195. if(!empty($x)){
  196. if($x != $pali){
  197. $parent_list[$x]=1;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. /*
  207. if($i==0){
  208. //自动查找单词词干
  209. $word_base=getPaliWordBase($in_word);
  210. foreach($word_base as $x=>$infolist){
  211. foreach($infolist as $gramma){
  212. array_push($output,
  213. array("pali"=>$in_word,
  214. "parent"=>$x,
  215. "type"=>$gramma["type"],
  216. "gramma"=>$gramma["gramma"],
  217. "parts"=>$gramma["parts"],
  218. "partmean"=>"",
  219. "mean"=>"",
  220. "language"=>"en",
  221. "dict_name"=>"auto",
  222. "status"=>128
  223. ));
  224. $part_list=str_getcsv($gramma["parts"],"+");
  225. foreach($part_list as $part){
  226. $parent_list[$part]=1;
  227. }
  228. }
  229. }
  230. }
  231. */
  232. if($debug){
  233. echo "parent:".count($parent_list)."<br>";
  234. print_r($parent_list)."<br>";
  235. }
  236. if(count($parent_list)==0){
  237. break;
  238. }
  239. else{
  240. $word_list=array();
  241. foreach($parent_list as $x=>$value){
  242. array_push($word_list,$x);
  243. }
  244. }
  245. }
  246. //删除无效数据
  247. $newOutput = array();
  248. foreach($output as $value){
  249. if($value["dict_name"]=="auto"){
  250. if(isset($dict_word_spell["{$value["parent"]}"])){
  251. array_push($newOutput,$value);
  252. }
  253. }
  254. else
  255. {
  256. array_push($newOutput,$value);
  257. }
  258. }
  259. if($debug){
  260. echo "<textarea width=\"100%\" >";
  261. }
  262. echo json_encode($newOutput, JSON_UNESCAPED_UNICODE);
  263. if($debug){
  264. echo "</textarea>";
  265. }
  266. if($debug){
  267. echo "生成:".count($output)."<br>";
  268. echo "有效:".count($newOutput)."<br>";
  269. foreach($newOutput as $result){
  270. echo "{$result["pali"]}-{$result["parent"]}-{$result["mean"]}<br>";
  271. }
  272. $queryTime=(microtime_float()-$time_start)*1000;
  273. echo "<div >搜索时间:$queryTime 毫秒</div>";
  274. }
  275. ?>