UpgradeCompound.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Console\Commands;
  3. require_once __DIR__."/../../../public/app/dict/turbo_split.php";
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Storage;
  6. use App\Models\WordIndex;
  7. use App\Tools\TurboSplit;
  8. class UpgradeCompound extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'upgrade:compound';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Command description';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return int
  35. */
  36. public function handle()
  37. {
  38. $ts = new TurboSplit();
  39. $start = \microtime(true);
  40. //var_dump($ts->splitA('aparimitanirupamasīlādiguṇasamaṅgītāya'));
  41. Storage::disk('local')->put("tmp/compound.md", "# Turbo Split");
  42. //获取需要拆的词
  43. $list = [
  44. [5,20,20],
  45. [21,30,20],
  46. [31,40,10],
  47. [41,60,10],
  48. ];
  49. foreach ($list as $take) {
  50. # code...
  51. $words = WordIndex::where('final',0)->whereBetween('len',[$take[0],$take[1]])->select('word')->take($take[2])->get();
  52. foreach ($words as $word) {
  53. $this->info($word->word);
  54. Storage::disk('local')->append("tmp/compound.md", "## {$word->word}");
  55. $parts = $ts->splitA($word->word);
  56. foreach ($parts as $part) {
  57. # code...
  58. $this->info("{$part['word']},{$part['factors']},{$part['confidence']}");
  59. Storage::disk('local')->append("tmp/compound.md", "- `{$part['word']}`,{$part['factors']},{$part['confidence']}");
  60. }
  61. }
  62. }
  63. $this->info("耗时:".\microtime(true)-$start);
  64. return 0;
  65. }
  66. }