dict_find_one.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once "../public/function.php";
  5. require_once '../ucenter/setting_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. $user_setting = get_setting();
  56. //open database
  57. global $PDO;
  58. $word_list=str_getcsv($in_word);
  59. $dict_word_spell=array();
  60. $output=array();
  61. $db_file_list=array();
  62. //用户词典
  63. if($dict_name==""){
  64. array_push($db_file_list , _FILE_DB_WBW_);
  65. array_push($db_file_list , _DIR_DICT_SYSTEM_."/sys_regular.db");
  66. array_push($db_file_list , _DIR_DICT_SYSTEM_."/sys_irregular.db");
  67. array_push($db_file_list , _DIR_DICT_SYSTEM_."/union.db");
  68. array_push($db_file_list , _DIR_DICT_SYSTEM_."/comp.db");
  69. array_push($db_file_list , _DIR_DICT_3RD_."/pm.db");
  70. array_push($db_file_list , _DIR_DICT_3RD_."/bhmf.db");
  71. array_push($db_file_list , _DIR_DICT_3RD_."/shuihan.db");
  72. array_push($db_file_list , _DIR_DICT_3RD_."/concise.db");
  73. array_push($db_file_list , _DIR_DICT_3RD_."/uhan_en.db");
  74. }
  75. else{
  76. $dict_list=str_getcsv($dict_name,',');
  77. foreach($dict_list as $dict){
  78. array_push($db_file_list , $dict);
  79. }
  80. }
  81. for($i=0;$i<$lookup_loop;$i++)
  82. {
  83. $parent_list=array();
  84. $strQueryWord="(";//单词查询字串
  85. foreach($word_list as $word){
  86. $word=str_replace("'","’",$word);
  87. $strQueryWord.="'{$word}',";
  88. }
  89. $strQueryWord=mb_substr($strQueryWord, 0,mb_strlen($strQueryWord,"UTF-8")-1,"UTF-8");
  90. $strQueryWord.=")";
  91. if($debug){
  92. echo "<h2>第".($i+1)."轮查询:".count($word_list)."</h2>";
  93. }
  94. foreach($db_file_list as $db_file){
  95. if($debug){
  96. echo "dict connect:$db_file<br>";
  97. }
  98. PDO_Connect("sqlite:$db_file");
  99. if($i==0){
  100. $query = "select * from dict where \"pali\" in $strQueryWord ORDER BY rowid DESC";
  101. }
  102. else{
  103. $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";
  104. }
  105. if($debug){
  106. //echo $query."<br>";
  107. }
  108. $Fetch = PDO_FetchAll($query);
  109. $iFetch=count($Fetch);
  110. if($debug){
  111. echo "count:$iFetch<br>";
  112. }
  113. if($iFetch>0){
  114. foreach($Fetch as $one){
  115. $id = $one["id"];
  116. if(isset($one["guid"])){
  117. $guid = $one["guid"];
  118. }
  119. else{
  120. $guid = "";
  121. }
  122. $pali = $one["pali"];
  123. $dict_word_spell["{$pali}"]=1;
  124. $type = $one["type"];
  125. $gramma = $one["gramma"];
  126. $parent = $one["parent"];
  127. if(inLangSetting($one["lang"],$user_setting["dict.lang"])){
  128. $mean = $one["mean"];
  129. }
  130. else{
  131. $mean = "";
  132. }
  133. $note = $one["note"];
  134. if(isset($one["factors"])){
  135. $parts = $one["factors"];
  136. }
  137. else if(isset($one["parts"])){
  138. $parts = $one["parts"];
  139. }
  140. else{
  141. $parts = "";
  142. }
  143. if(isset($one["factormean"])){
  144. $partmean = $one["factormean"];
  145. }
  146. else if(isset($one["partmean"])){
  147. $partmean = $one["partmean"];
  148. }
  149. else{
  150. $partmean = "";
  151. }
  152. if(inLangSetting($one["lang"],$user_setting["dict.lang"])==false){
  153. $partmean = "";
  154. }
  155. $status = $one["status"];
  156. if(isset($one["confidence"])){
  157. $confidence = $one["confidence"];
  158. }
  159. else{
  160. $confidence = 100;
  161. }
  162. if(isset($one["dict_name"])){
  163. $dict_name = $one["dict_name"];
  164. }
  165. else{
  166. $dict_name = "";
  167. }
  168. if(isset($one["lang"])){
  169. $language = $one["lang"];
  170. }
  171. else{
  172. $language = "en";
  173. }
  174. array_push($output,array(
  175. "id"=>$id,
  176. "guid"=>$guid,
  177. "pali"=>$pali,
  178. "type"=>$type,
  179. "gramma"=>$gramma,
  180. "parent"=>$parent,
  181. "mean"=>$mean,
  182. "note"=>$note,
  183. "parts"=>$parts,
  184. "partmean"=>$partmean,
  185. "status"=>$status,
  186. "confidence"=>$confidence,
  187. "dict_name"=>$dict_name,
  188. "language"=>$language
  189. ));
  190. //将语基插入下次查询的列表
  191. if(!empty($parent)){
  192. if($pali != $parent){
  193. $parent_list[$parent]=1;
  194. }
  195. }
  196. //将拆分插入下次查询的列表
  197. if($type!=".part."){
  198. if(!empty($parts)){
  199. $wordparts=str_getcsv($parts,'+');
  200. foreach($wordparts as $x){
  201. if(!empty($x)){
  202. if($x != $pali){
  203. $parent_list[$x]=1;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. /*
  213. if($i==0){
  214. //自动查找单词词干
  215. $word_base=getPaliWordBase($in_word);
  216. foreach($word_base as $x=>$infolist){
  217. foreach($infolist as $gramma){
  218. array_push($output,
  219. array("pali"=>$in_word,
  220. "parent"=>$x,
  221. "type"=>$gramma["type"],
  222. "gramma"=>$gramma["gramma"],
  223. "parts"=>$gramma["parts"],
  224. "partmean"=>"",
  225. "mean"=>"",
  226. "language"=>"en",
  227. "dict_name"=>"auto",
  228. "status"=>128
  229. ));
  230. $part_list=str_getcsv($gramma["parts"],"+");
  231. foreach($part_list as $part){
  232. $parent_list[$part]=1;
  233. }
  234. }
  235. }
  236. }
  237. */
  238. if($debug){
  239. echo "parent:".count($parent_list)."<br>";
  240. print_r($parent_list)."<br>";
  241. }
  242. if(count($parent_list)==0){
  243. break;
  244. }
  245. else{
  246. $word_list=array();
  247. foreach($parent_list as $x=>$value){
  248. array_push($word_list,$x);
  249. }
  250. }
  251. }
  252. //删除无效数据
  253. $newOutput = array();
  254. foreach($output as $value){
  255. if($value["dict_name"]=="auto"){
  256. if(isset($dict_word_spell["{$value["parent"]}"])){
  257. array_push($newOutput,$value);
  258. }
  259. }
  260. else
  261. {
  262. array_push($newOutput,$value);
  263. }
  264. }
  265. if($debug){
  266. echo "<textarea width=\"100%\" >";
  267. }
  268. echo json_encode($newOutput, JSON_UNESCAPED_UNICODE);
  269. if($debug){
  270. echo "</textarea>";
  271. }
  272. if($debug){
  273. echo "生成:".count($output)."<br>";
  274. echo "有效:".count($newOutput)."<br>";
  275. foreach($newOutput as $result){
  276. echo "{$result["pali"]}-{$result["parent"]}-{$result["mean"]}<br>";
  277. }
  278. $queryTime=(microtime_float()-$time_start)*1000;
  279. echo "<div >搜索时间:$queryTime 毫秒</div>";
  280. }
  281. ?>