comp_csv.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. require_once "../path.php";
  3. require_once "../dict/turbo_split.php";
  4. require_once "../redis/function.php";
  5. if (isset($argv[1])) {
  6. $start = (int)$argv[1];
  7. }
  8. else{
  9. $start=0;
  10. }
  11. if (isset($argv[2])) {
  12. $end = (int)$argv[2];
  13. }
  14. else{
  15. $end=1000000;
  16. }
  17. global $result;
  18. $myfile = fopen(_DIR_TEMP_ . "/comp.csv", "a");
  19. $filefail = fopen(_DIR_TEMP_ . "/comp_fail.txt", "a");
  20. $iMax = 2;//输出前三个结果
  21. /*
  22. $dns = "" . _FILE_DB_WORD_INDEX_;
  23. $dbh_word = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  24. $dbh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  25. $query = "SELECT * from wordindex where 1";
  26. $stmt = $dbh_word->query($query);
  27. while ($word = $stmt->fetch(PDO::FETCH_ASSOC))
  28. */
  29. $redis = redis_connect();
  30. if ($redis == false) {
  31. echo "no redis connect\n";
  32. exit;
  33. }
  34. $i = null;
  35. $counter = 0;
  36. while ($words = $redis->sscan("pali_word", $i)) {
  37. # code...
  38. if($counter<$start){
  39. $counter+=10;
  40. continue;
  41. }
  42. if($counter>$end){
  43. echo "all done";
  44. exit;
  45. }
  46. foreach ($words as $key => $word) {
  47. # code...
  48. $arrword = split_diphthong($word);
  49. if (count($arrword) > 1) {
  50. fputcsv($myfile, array($word, implode("+", $arrword), 0.99));
  51. }
  52. foreach ($arrword as $oneword) {
  53. $counter++;
  54. $result = array(); //全局变量,递归程序的输出容器
  55. mySplit2($oneword, 0, true, 0.5, 0.9, 0, true, false);
  56. if(count($result)<2){
  57. mySplit2($oneword, 0, $_express, 0.2, 0.9, 0, true, true);
  58. if (isset($_POST["debug"])) {
  59. echo "正切:" . count($result) . "\n";
  60. }
  61. if(count($result)<2){
  62. mySplit2($oneword, 0, $_express, 0.2, 0.8, 0, false, true);
  63. if (isset($_POST["debug"])) {
  64. echo "反切:" . count($result) . "\n";
  65. }
  66. }
  67. }
  68. /*
  69. #正向切分
  70. mySplit2($oneword, 0, false);
  71. if (count($result) == 0) {
  72. #如果没有 逆向切分
  73. mySplit2($oneword, 0, false, 0, 0.8, 0.8, true);
  74. }
  75. */
  76. echo "{$counter}-{$oneword}:" . count($result) . "\n";
  77. if (count($result) > 0) {
  78. arsort($result); //按信心指数排序
  79. $iCount = 0;
  80. foreach ($result as $row => $value) {
  81. fputcsv($myfile, array($oneword, $row, $value));
  82. $iCount++;
  83. if ($iCount > $iMax) {
  84. break;
  85. }
  86. }
  87. } else {
  88. fwrite($filefail, $oneword . "\n");
  89. }
  90. }
  91. }
  92. }