dict_find_one.php 6.1 KB

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