InitCs6sentence.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. $start = time();
  40. $channelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
  41. if($channelId === false){
  42. $this->error('no channel');
  43. return 1;
  44. }
  45. $pali = new PaliSentence;
  46. if(!empty($this->argument('book'))){
  47. $pali = $pali->where('book',$this->argument('book'));
  48. }
  49. if(!empty($this->argument('para'))){
  50. $pali = $pali->where('paragraph',$this->argument('para'));
  51. }
  52. $bar = $this->output->createProgressBar($pali->count());
  53. $pali = $pali->select('book','paragraph','word_begin','word_end')->cursor();
  54. foreach ($pali as $value) {
  55. # code...
  56. $words = WbwTemplate::where("book",$value->book)
  57. ->where("paragraph",$value->paragraph)
  58. ->where("wid",">=",$value->word_begin)
  59. ->where("wid","<=",$value->word_end)
  60. ->orderBy('wid','asc')
  61. ->get();
  62. $sent = '';
  63. $boldStart = false;
  64. $boldCount = 0;
  65. foreach ($words as $word) {
  66. # code...
  67. //if($word->style != "note" && $word->type != '.ctl.')
  68. if( $word->type != '.ctl.')
  69. {
  70. if($word->style=='bld'){
  71. if(!$boldStart){
  72. #黑体字开始
  73. $boldStart = true;
  74. $sent .= ' <b>';
  75. }
  76. }else{
  77. if($boldStart){
  78. #黑体字结束
  79. $boldStart = false;
  80. $boldCount = 0;
  81. $sent .= '</b>';
  82. }
  83. }
  84. if($boldStart){
  85. $boldCount++;
  86. }
  87. if(!empty($word->real) && $boldCount != 1){
  88. #如果不是标点符号,在词的前面加空格 。第一个黑体字前不加空格
  89. $sent .= " ";
  90. }
  91. if(strpos($word->word,'{') >=0 ){
  92. //一个单词里面含有黑体字的
  93. $paliWord = \str_replace("{","<b>",$word->word) ;
  94. $paliWord = \str_replace("}","</b>",$paliWord) ;
  95. }else{
  96. $paliWord = $word->word;
  97. }
  98. $sent .= $paliWord;
  99. }
  100. }
  101. if($boldStart){
  102. #句子结尾是黑体字 加黑体结束符号
  103. $boldStart = false;
  104. $sent .= '** ';
  105. }
  106. #将wikipali风格的引用 改为缅文风格
  107. /*
  108. $sent = \str_replace('n’’’ ti','’’’nti',$sent);
  109. $sent = \str_replace('n’’ ti','’’nti',$sent);
  110. $sent = \str_replace('n’ ti','’nti',$sent);
  111. $sent = \str_replace('**ti**','**ti',$sent);
  112. $sent = \str_replace('‘ ','‘',$sent);
  113. */
  114. $sent = trim($sent);
  115. $snowId = app('snowflake')->id();
  116. $newRow = Sentence::updateOrCreate(
  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' =>$snowId,
  126. 'uid' =>Str::uuid(),
  127. ]
  128. );
  129. $newRow->editor_uid = config("app.admin.root_uuid");
  130. $newRow->content = trim($sent);
  131. $newRow->strlen = mb_strlen($sent,"UTF-8");
  132. $newRow->status = 30;
  133. $newRow->create_time = time()*1000;
  134. $newRow->modify_time = time()*1000;
  135. $newRow->language = 'en';
  136. $newRow->save();
  137. $bar->advance();
  138. }
  139. $bar->finish();
  140. $this->info("finished ".(time()-$start)."s");
  141. return 0;
  142. }
  143. }