wbw_analyse.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/load_lang.php';
  5. require_once '../public/function.php';
  6. global $PDO;
  7. PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
  8. $query = "SELECT * from wbw where 1";
  9. $sth = $PDO->prepare($query);
  10. $sth->execute();
  11. $udict = new PDO("sqlite:"._FILE_DB_USER_DICT_, "", "",array(PDO::ATTR_PERSISTENT=>true));
  12. $udict->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  13. /* 开始一个事务,关闭自动提交 */
  14. $udict->beginTransaction();
  15. $query="INSERT INTO udict ('userid',
  16. 'pali',
  17. 'book',
  18. 'paragraph',
  19. 'wid',
  20. 'type',
  21. 'data',
  22. 'confidence',
  23. 'lang',
  24. 'modify_time')
  25. VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
  26. $stmt = $udict->prepare($query);
  27. $i=0;
  28. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  29. {
  30. try {
  31. $xmlString = "<root>".$result["data"]."</root>";
  32. //echo $xmlString."<br>";
  33. $xmlWord = simplexml_load_string($xmlString);
  34. $wordsList = $xmlWord->xpath('//word');
  35. foreach ($wordsList as $word) {
  36. $pali = $word->real->__toString();
  37. foreach ($word as $key => $value) {
  38. $strValue = $value->__toString();
  39. if($strValue !== "?" && $strValue !== "" && $strValue !== ".ctl." && $strValue !== ".a." && $strValue !== " " && mb_substr($strValue,0,3,"UTF-8") !== "[a]" && $strValue !== "_un_auto_factormean_" && $strValue !== "_un_auto_mean_"){
  40. $iType = 0;
  41. $lang = 'pali';
  42. switch ($key) {
  43. case 'type':
  44. $iType = 1;
  45. break;
  46. case 'gramma':
  47. $iType = 2;
  48. break;
  49. case 'mean':
  50. $iType = 3;
  51. $lang = getLanguageCode($strValue);
  52. break;
  53. case 'org':
  54. $iType = 4;
  55. break;
  56. case 'om':
  57. $iType = 5;
  58. $lang = getLanguageCode($strValue);
  59. break;
  60. case 'parent':
  61. $iType = 6;
  62. break;
  63. }
  64. if($iType>0){
  65. $wordData = array($result["owner"],
  66. $pali,$result["book"],
  67. $result["paragraph"],
  68. $result["wid"],
  69. $iType,
  70. $strValue,
  71. 100,
  72. $lang,
  73. $result["modify_time"]
  74. );
  75. //print_r($wordData);
  76. $stmt->execute( $wordData);
  77. }
  78. }
  79. }
  80. }
  81. } catch ( Throwable $e) {
  82. echo "Captured Throwable: " . $e->getMessage();
  83. }
  84. $i++;
  85. if($i>10){
  86. //break;
  87. }
  88. }
  89. //其他字典
  90. $db_file_list=array();
  91. array_push($db_file_list , _DIR_DICT_SYSTEM_."/sys_regular.db");
  92. array_push($db_file_list , _DIR_DICT_SYSTEM_."/sys_irregular.db");
  93. array_push($db_file_list , _DIR_DICT_SYSTEM_."/union.db");
  94. array_push($db_file_list , _DIR_DICT_SYSTEM_."/comp.db");
  95. array_push($db_file_list , _DIR_DICT_3RD_."/pm.db");
  96. array_push($db_file_list , _DIR_DICT_3RD_."/bhmf.db");
  97. array_push($db_file_list , _DIR_DICT_3RD_."/shuihan.db");
  98. array_push($db_file_list , _DIR_DICT_3RD_."/concise.db");
  99. array_push($db_file_list , _DIR_DICT_3RD_."/uhan_en.db");
  100. foreach($db_file_list as $db_file){
  101. if($debug){
  102. echo "dict connect:$db_file<br>";
  103. }
  104. $dbh = new PDO("sqlite:".$db_file, "", "",array(PDO::ATTR_PERSISTENT=>true));
  105. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  106. $query = "select * from dict where 1";
  107. $sth = $dbh->prepare($query);
  108. $sth->execute();
  109. $i=0;
  110. while($result = $sth->fetch(PDO::FETCH_ASSOC)){
  111. if(!empty($result["mean"])){
  112. $arrMean = explode('$',$result["mean"]);
  113. foreach ($arrMean as $key => $value) {
  114. $word = trim($value," \t\n\r\0\x0B\.");
  115. if(!empty($word)){
  116. $wordData = array($result["dict_name"],
  117. $result["pali"],
  118. 0,
  119. 0,
  120. 0,
  121. 3,
  122. $word,
  123. $result["confidence"],
  124. $result["lang"],
  125. 1
  126. );
  127. //print_r($wordData);
  128. $stmt->execute( $wordData);
  129. }
  130. }
  131. }
  132. if(!empty($result["type"])){
  133. $wordData = array($result["dict_name"],
  134. $result["pali"],
  135. 0,
  136. 0,
  137. 0,
  138. 1,
  139. $result["type"],
  140. $result["confidence"],
  141. 'pali',
  142. 1
  143. );
  144. $stmt->execute( $wordData);
  145. //print_r($wordData);
  146. }
  147. if(!empty($result["gramma"])){
  148. $wordData = array($result["dict_name"],
  149. $result["pali"],
  150. 0,
  151. 0,
  152. 0,
  153. 2,
  154. $result["gramma"],
  155. $result["confidence"],
  156. 'pali',
  157. 1
  158. );
  159. $stmt->execute( $wordData);
  160. //print_r($wordData);
  161. }
  162. if(!empty($result["parts"])){
  163. $wordData = array($result["dict_name"],
  164. $result["pali"],
  165. 0,
  166. 0,
  167. 0,
  168. 4,
  169. $result["parts"],
  170. $result["confidence"],
  171. 'pali',
  172. 1
  173. );
  174. //print_r($wordData);
  175. $stmt->execute( $wordData);
  176. }
  177. if(!empty($result["partmean"])){
  178. $wordData = array($result["dict_name"],
  179. $result["pali"],
  180. 0,
  181. 0,
  182. 0,
  183. 5,
  184. $result["partmean"],
  185. $result["confidence"],
  186. $result["lang"],
  187. 1
  188. );
  189. //print_r($wordData);
  190. $stmt->execute( $wordData);
  191. }
  192. if(!empty($result["parent"])){
  193. $wordData = array($result["dict_name"],
  194. $result["pali"],
  195. 0,
  196. 0,
  197. 0,
  198. 6,
  199. $result["parent"],
  200. $result["confidence"],
  201. 'pali',
  202. 1
  203. );
  204. //print_r($wordData);
  205. $stmt->execute( $wordData);
  206. }
  207. if($i>10){
  208. //break;
  209. }
  210. $i++;
  211. }
  212. }
  213. /* 提交更改 */
  214. $udict->commit();
  215. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  216. $error = $udict->errorInfo();
  217. echo "error - $error[2] <br>";
  218. }
  219. else{
  220. echo "updata index $i recorders.";
  221. }
  222. ?>