InitCs6sentence.php 4.5 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. $this->info($channelId);
  46. $pali = new PaliSentence;
  47. if(!empty($this->argument('book'))){
  48. $pali = $pali->where('book',$this->argument('book'));
  49. }
  50. if(!empty($this->argument('para'))){
  51. $pali = $pali->where('paragraph',$this->argument('para'));
  52. }
  53. $bar = $this->output->createProgressBar($pali->count());
  54. $pali = $pali->select('book','paragraph','word_begin','word_end')->cursor();
  55. $pageHead = ['M','P','T','V','O'];
  56. foreach ($pali as $value) {
  57. # code...
  58. $words = WbwTemplate::where("book",$value->book)
  59. ->where("paragraph",$value->paragraph)
  60. ->where("wid",">=",$value->word_begin)
  61. ->where("wid","<=",$value->word_end)
  62. ->orderBy('wid','asc')
  63. ->get();
  64. $sent = '';
  65. $boldStart = false;
  66. $boldCount = 0;
  67. $lastWord = null;
  68. foreach ($words as $word) {
  69. # code...
  70. //if($word->style != "note" && $word->type != '.ctl.')
  71. if( $word->type != '.ctl.'){
  72. if($lastWord !== null){
  73. if($word->real !== "ti" ){
  74. if(!(empty($word->real) && empty($lastWord->real))) {
  75. #如果不是标点符号,在词的前面加空格 。
  76. $sent .= " ";
  77. }
  78. }
  79. }
  80. if(strpos($word->word,'{') !== false ){
  81. //一个单词里面含有黑体字的
  82. $paliWord = \str_replace("{","<strong>",$word->word) ;
  83. $paliWord = \str_replace("}","</strong>",$paliWord) ;
  84. $sent .= $paliWord;
  85. }else{
  86. if($word->style=='bld'){
  87. $sent .= "<strong>{$word->word}</strong>";
  88. }else{
  89. $sent .= $word->word;
  90. }
  91. }
  92. }else{
  93. $type = substr($word->word,0,1);
  94. if(in_array($type,$pageHead)){
  95. $arrPage = explode('.',$word->word);
  96. if(count($arrPage)===2){
  97. $pageNumber = $arrPage[0].'.'.(int)$arrPage[1];
  98. $sent .= "<code>{$pageNumber}</code>";
  99. }
  100. }
  101. }
  102. $lastWord = $word;
  103. }
  104. #将wikipali风格的引用 改为缅文风格
  105. /*
  106. $sent = \str_replace('n’’’ ti','’’’nti',$sent);
  107. $sent = \str_replace('n’’ ti','’’nti',$sent);
  108. $sent = \str_replace('n’ ti','’nti',$sent);
  109. $sent = \str_replace('**ti**','**ti',$sent);
  110. $sent = \str_replace('‘ ','‘',$sent);
  111. */
  112. $newRow = Sentence::firstOrNew(
  113. [
  114. "book_id" => $value->book,
  115. "paragraph" => $value->paragraph,
  116. "word_start" => $value->word_begin,
  117. "word_end" => $value->word_end,
  118. "channel_uid" => $channelId,
  119. ],
  120. [
  121. 'id' =>app('snowflake')->id(),
  122. 'uid' =>Str::uuid(),
  123. 'create_time' => time()*1000,
  124. ]
  125. );
  126. $newRow->editor_uid = config("app.admin.root_uuid");
  127. $newRow->content = "<span>{$sent}</span>";
  128. $newRow->strlen = mb_strlen($sent,"UTF-8");
  129. $newRow->status = 10;
  130. $newRow->content_type = "html";
  131. $newRow->modify_time = time()*1000;
  132. $newRow->language = 'en';
  133. $newRow->save();
  134. $bar->advance();
  135. }
  136. $bar->finish();
  137. $this->info("finished ".(time()-$start)."s");
  138. return 0;
  139. }
  140. }