X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FChatLib.php;fp=app%2FModels%2FChatLib.php;h=cf5d7dd6c825f6d8f37451dbfe7136bd0c91b787;hb=a45648fa8ecf7712c7fd00eb2b93e862b5264f04;hp=417b18f3dd6b01f1cbeb5b923d71148ebb995cd3;hpb=c2cc99020eee56f7790d1358abb44df078f2e655;p=alttp.git diff --git a/app/Models/ChatLib.php b/app/Models/ChatLib.php index 417b18f..cf5d7dd 100644 --- a/app/Models/ChatLib.php +++ b/app/Models/ChatLib.php @@ -2,6 +2,8 @@ namespace App\Models; +use Illuminate\Support\Facades\Storage; + class ChatLib { public function addMessage($msg) { @@ -29,7 +31,6 @@ class ChatLib { unset($this->transitions[$key]); } } - echo 'size: ', number_format(strlen(json_encode($this->transitions)), 0), PHP_EOL; } public function generate($limit = 100) { @@ -44,6 +45,20 @@ class ChatLib { return $generated; } + public function saveAs($name) { + $data = [ + 'size' => $this->size, + 'transitions' => $this->transitions, + ]; + Storage::disk('chatlib')->put($name.'.json', json_encode($data)); + } + + public function loadFrom($name) { + $data = json_decode(Storage::disk('chatlib')->get($name.'.json'), true); + $this->size = $data['size']; + $this->transitions = $data['transitions']; + } + private function index($arr) { $result = []; $sum = 0; @@ -132,7 +147,11 @@ class ChatLib { } private function tokenize($str) { - return array_values(array_filter(preg_split('/\b/u', $str))); + return array_values(array_filter(preg_split('/\b/u', $str), function($token) { + if (empty($token)) return false; + if (preg_match('/cheer\d+/u', strtolower($token))) return false; + return true; + })); } private function generalize($tokens) {