comp_csv.php 2.2 KB

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