なんもわからんわー

This commit is contained in:
shibafu 2020-07-30 00:46:33 +09:00
parent d69fe6a22a
commit c7aa002625
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,50 @@
<?php
namespace App\Console\Commands;
use App\Tag;
use App\Utilities\Formatter;
use Illuminate\Console\Command;
class NormalizeTags extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tissue:tag:normalize';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Normalize tags';
private $formatter;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Formatter $formatter)
{
parent::__construct();
$this->formatter = $formatter;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
foreach (Tag::query()->orderBy('name')->cursor() as $tag) {
$normalizedName = $this->formatter->normalizeToSearchIndex($tag->name);
$this->line("{$tag->name} : {$normalizedName}");
}
}
}

View File

@ -132,4 +132,15 @@ class Formatter
return $bytes . 'B'; return $bytes . 'B';
} }
public function normalizeToSearchIndex(string $text): string
{
$text = \Normalizer::normalize($text, \Normalizer::FORM_KC);
// $text = \Transliterator::create('Katakana-Hiragana')->transliterate($text);
$text = mb_convert_kana($text, 'c');
$text = preg_replace('/[^\p{L}\p{N}]/u', '', $text);
$text = mb_strtolower($text);
return $text;
}
} }