InitCs6sentence.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\PaliSentence;
  5. use App\Models\WbwTemplate;
  6. use App\Models\Sentence;
  7. use Illuminate\Support\Str;
  8. use App\Http\Api\ChannelApi;
  9. class InitCs6sentence extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'init:cs6sentence {book?} {para?}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '按照分句数据库,填充cs6的巴利原文句子';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return int
  36. */
  37. public function handle()
  38. {
  39. if (\App\Tools\Tools::isStop()) {
  40. return 0;
  41. }
  42. $start = time();
  43. $channelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
  44. if ($channelId === false) {
  45. $this->error('no channel');
  46. return 1;
  47. }
  48. $this->info($channelId);
  49. $pali = new PaliSentence;
  50. if (!empty($this->argument('book'))) {
  51. $pali = $pali->where('book', $this->argument('book'));
  52. }
  53. if (!empty($this->argument('para'))) {
  54. $pali = $pali->where('paragraph', $this->argument('para'));
  55. }
  56. $bar = $this->output->createProgressBar($pali->count());
  57. $pali = $pali->select('book', 'paragraph', 'word_begin', 'word_end')->cursor();
  58. $pageHead = ['M', 'P', 'T', 'V', 'O'];
  59. foreach ($pali as $value) {
  60. # code...
  61. $words = WbwTemplate::where("book", $value->book)
  62. ->where("paragraph", $value->paragraph)
  63. ->where("wid", ">=", $value->word_begin)
  64. ->where("wid", "<=", $value->word_end)
  65. ->orderBy('wid', 'asc')
  66. ->get();
  67. $sent = '';
  68. $boldStart = false;
  69. $boldCount = 0;
  70. $lastWord = null;
  71. foreach ($words as $word) {
  72. # code...
  73. //if($word->style != "note" && $word->type != '.ctl.')
  74. if ($word->type != '.ctl.') {
  75. if ($lastWord !== null) {
  76. if ($word->real !== "ti") {
  77. if (!(empty($word->real) && empty($lastWord->real))) {
  78. #如果不是标点符号,在词的前面加空格 。
  79. $sent .= " ";
  80. }
  81. }
  82. }
  83. if (strpos($word->word, '{') !== false) {
  84. //一个单词里面含有黑体字的
  85. $paliWord = \str_replace("{", "<strong>", $word->word);
  86. $paliWord = \str_replace("}", "</strong>", $paliWord);
  87. $sent .= $paliWord;
  88. } else {
  89. if ($word->style == 'bld') {
  90. $sent .= "<strong>{$word->word}</strong>";
  91. } else {
  92. $sent .= $word->word;
  93. }
  94. }
  95. } else {
  96. $type = substr($word->word, 0, 1);
  97. if (in_array($type, $pageHead)) {
  98. $arrPage = explode('.', $word->word);
  99. if (count($arrPage) === 2) {
  100. $pageNumber = $arrPage[0] . '.' . (int)$arrPage[1];
  101. $sent .= "<code>{$pageNumber}</code>";
  102. }
  103. }
  104. }
  105. $lastWord = $word;
  106. }
  107. #将wikipali风格的引用 改为缅文风格
  108. /*
  109. $sent = \str_replace('n’’’ ti','’’’nti',$sent);
  110. $sent = \str_replace('n’’ ti','’’nti',$sent);
  111. $sent = \str_replace('n’ ti','’nti',$sent);
  112. $sent = \str_replace('**ti**','**ti',$sent);
  113. $sent = \str_replace('‘ ','‘',$sent);
  114. */
  115. $sent = \str_replace(' ti', 'ti', $sent);
  116. $newRow = Sentence::firstOrNew(
  117. [
  118. "book_id" => $value->book,
  119. "paragraph" => $value->paragraph,
  120. "word_start" => $value->word_begin,
  121. "word_end" => $value->word_end,
  122. "channel_uid" => $channelId,
  123. ],
  124. [
  125. 'id' => app('snowflake')->id(),
  126. 'uid' => Str::uuid(),
  127. 'create_time' => time() * 1000,
  128. ]
  129. );
  130. $newRow->editor_uid = config("mint.admin.root_uuid");
  131. $newRow->content = "<span>{$sent}</span>";
  132. $newRow->strlen = mb_strlen($sent, "UTF-8");
  133. $newRow->status = 10;
  134. $newRow->content_type = "html";
  135. $newRow->modify_time = time() * 1000;
  136. $newRow->language = 'en';
  137. $newRow->save();
  138. $bar->advance();
  139. }
  140. $bar->finish();
  141. $this->info("finished " . (time() - $start) . "s");
  142. return 0;
  143. }
  144. }