UpgradeWbwWeight.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\WbwTemplate;
  5. class UpgradeWbwWeight extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. * php artisan upgrade:wbw.weight 66
  10. * @var string
  11. */
  12. protected $signature = 'upgrade:wbw.weight {book?} {para?}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'upgrade wbw template weight by word bold ';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. $book = $this->argument('book');
  36. $para = $this->argument('para');
  37. for ($iBook=1; $iBook <= 217 ; $iBook++) {
  38. if($book && $book != $iBook ){
  39. continue;
  40. }
  41. $this->info('running book='.$iBook);
  42. $maxPara = WbwTemplate::where("book",$iBook)->max('paragraph');
  43. $bar = $this->output->createProgressBar($maxPara);
  44. for ($iPara=1; $iPara <= $maxPara ; $iPara++) {
  45. if($para && $para != $iPara ){
  46. continue;
  47. }
  48. $bar->advance();
  49. $words = WbwTemplate::where("book",$iBook)
  50. ->where("paragraph",$iPara)
  51. ->orderBy('wid','asc')
  52. ->get();
  53. $start = -1;
  54. $bold = 0;
  55. $katama = false;
  56. $katamaDis = 0;
  57. $katamaWeight = 1;
  58. $arrKatama = array();//katama 权重结果
  59. //先计算katama权重
  60. for ($iWord=0; $iWord < count($words); $iWord++) {
  61. //计算katama加分
  62. if(empty($words[$iWord]->real)){
  63. $katama = false;
  64. $katamaWeight = 0;
  65. }
  66. if($katama){
  67. $katamaDis++;
  68. $katamaWeight = 463 * (pow(0.2, ($katamaDis-1))+1);
  69. }
  70. $arrKatama[] = $katamaWeight;
  71. if(mb_substr($words[$iWord]->real,0,5,"UTF-8") === 'katam'){
  72. $katama = true;
  73. $katamaDis = 0;
  74. }
  75. }
  76. for ($iWord=0; $iWord < count($words); $iWord++) {
  77. $wid = $words[$iWord]->wid;
  78. $weight = 1.01;
  79. WbwTemplate::where('id',$words[$iWord]->id)->update(['weight'=>$weight*1000]);
  80. if($words[$iWord]->style === 'bld' && !empty($words[$iWord]->real)){
  81. if($start === -1){
  82. $start = $iWord;
  83. $bold = 1;
  84. }else{
  85. $bold++;
  86. }
  87. }else{
  88. if($start>=0){
  89. //前面的词是黑体字
  90. $result = WbwTemplate::where('id',$words[$iWord]->id)
  91. ->update(['weight'=>floor(($weight+$arrKatama[$iWord])*1000)]);
  92. $weight = 1.01+23*pow(10,(2-$bold));
  93. for ($i=$start; $i < $iWord ; $i++) {
  94. $result = WbwTemplate::where('id',$words[$i]->id)
  95. ->update(['weight'=>floor(($weight+$arrKatama[$i])*1000)]);
  96. }
  97. $start = -1;
  98. $bold = 0;
  99. }else{
  100. $result = WbwTemplate::where('id',$words[$iWord]->id)
  101. ->update(['weight'=>floor(($weight+$arrKatama[$iWord])*1000)]);
  102. }
  103. }
  104. }
  105. }
  106. $bar->finish();
  107. }
  108. return 0;
  109. }
  110. }