comp_csv.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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=1;
  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_DICT_TEXT_ . "/comp.csv", "a");
  19. $filefail = fopen(_DIR_TEMP_DICT_TEXT_ . "/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. while($word = $redis->hGet("pali://wordindex.hash",$start))
  36. {
  37. # code...
  38. if($start>$end){
  39. echo "all done";
  40. exit;
  41. }
  42. {
  43. # code...
  44. $arrword = split_diphthong($word);
  45. if (count($arrword) > 1) {
  46. $data = array($start,$word,'.comp.','','','','',implode("+", $arrword),'',1,50,6,'comp','en');
  47. fputcsv($myfile, $data);
  48. }
  49. foreach ($arrword as $oneword) {
  50. $result = array(); //全局变量,递归程序的输出容器
  51. $min_result = 1;
  52. if(mb_strlen($oneword)>35){
  53. mySplit2($oneword, 0, true, 0.8, 0.9, 0, true, false);
  54. }
  55. else{
  56. mySplit2($oneword, 0, false, 0.8, 0.9, 0, true, false);
  57. $min_result=3;
  58. }
  59. if(count($result)<$min_result){
  60. mySplit2($oneword, 0, false, 0.2, 0.8, 0, true, true);
  61. if (isset($_POST["debug"])) {
  62. echo "正切:" . count($result) . "\n";
  63. }
  64. if(count($result)<2){
  65. mySplit2($oneword, 0, false, 0.2, 0.8, 0, false, true);
  66. if (isset($_POST["debug"])) {
  67. echo "反切:" . count($result) . "\n";
  68. }
  69. }
  70. }
  71. /*
  72. #正向切分
  73. mySplit2($oneword, 0, false);
  74. if (count($result) == 0) {
  75. #如果没有 逆向切分
  76. mySplit2($oneword, 0, false, 0, 0.8, 0.8, true);
  77. }
  78. */
  79. echo "{$start}-{$oneword}:" . count($result) . "\n";
  80. if (count($result) > 0) {
  81. arsort($result); //按信心指数排序
  82. $iCount = 0;
  83. foreach ($result as $row => $value) {
  84. $data = array($start,$oneword,'.comp.','','','','',$row,'',1,round($value*70),6,'comp','en');
  85. fputcsv($myfile, $data);
  86. //后处理 进一步切分没有意思的长词
  87. $new = split2($row);
  88. if($new!==$row){
  89. $data = array($start,$oneword,'.comp.','','','','',$new,'',1,round($value*70),6,'comp','en');
  90. fputcsv($myfile, $data);
  91. #再处理一次
  92. $new2 = split2($new);
  93. if($new2!==$new){
  94. $data = array($start,$oneword,'.comp.','','','','',$new2,'',1,round($value*70),6,'comp','en');
  95. fputcsv($myfile, $data);
  96. }
  97. }
  98. $iCount++;
  99. if ($iCount > $iMax) {
  100. break;
  101. }
  102. }
  103. } else {
  104. fwrite($filefail, $oneword . "\n");
  105. }
  106. }
  107. }
  108. $start++;
  109. }