InitCs6sentence.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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(strpos($word->word,'{') >=0 ){
  71. //一个单词里面含有黑体字的
  72. $paliWord = \str_replace("{","<strong>",$word->word) ;
  73. $paliWord = \str_replace("}","</strong>",$paliWord) ;
  74. $sent .= $paliWord;
  75. }else{
  76. if($word->style=='bld'){
  77. $sent .= "<strong>{$word->word}</strong>";
  78. }else{
  79. $sent .= $word->word;
  80. }
  81. }
  82. if(!empty($word->real) ){
  83. #如果不是标点符号,在词的前面加空格 。
  84. $sent .= " ";
  85. }
  86. }
  87. }
  88. #将wikipali风格的引用 改为缅文风格
  89. /*
  90. $sent = \str_replace('n’’’ ti','’’’nti',$sent);
  91. $sent = \str_replace('n’’ ti','’’nti',$sent);
  92. $sent = \str_replace('n’ ti','’nti',$sent);
  93. $sent = \str_replace('**ti**','**ti',$sent);
  94. $sent = \str_replace('‘ ','‘',$sent);
  95. */
  96. $newRow = Sentence::firstOrNew(
  97. [
  98. "book_id" => $value->book,
  99. "paragraph" => $value->paragraph,
  100. "word_start" => $value->word_begin,
  101. "word_end" => $value->word_end,
  102. "channel_uid" => $channelId,
  103. ],
  104. [
  105. 'id' =>app('snowflake')->id(),
  106. 'uid' =>Str::uuid(),
  107. ]
  108. );
  109. $newRow->editor_uid = config("app.admin.root_uuid");
  110. $newRow->content = "<span>{$sent}</span>";
  111. $newRow->strlen = mb_strlen($sent,"UTF-8");
  112. $newRow->status = 10;
  113. $newRow->content_type = "html";
  114. $newRow->create_time = time()*1000;
  115. $newRow->modify_time = time()*1000;
  116. $newRow->language = 'en';
  117. $newRow->save();
  118. $bar->advance();
  119. }
  120. $bar->finish();
  121. $this->info("finished ".(time()-$start)."s");
  122. return 0;
  123. }
  124. }