Skip to content

Commit

Permalink
Changed SpamDetector to usage storage and more stop words
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Mar 20, 2024
1 parent 2e21790 commit 0ae7652
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/Services/SpamDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Services;

use AssistedMindfulness\NaiveBayes\Classifier;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class SpamDetector
Expand Down Expand Up @@ -42,7 +43,8 @@ class SpamDetector
'финансовая защита', 'инвестиции в будущее', 'реальный заработок',
'финансовый инструментарий', 'инвестиции в золото', 'инвестиции в криптовалютные фонды',
'увеличение прибыли в интернете', 'инвестирование в акции',
'финансовая безопасность',
'финансовая безопасность', 'нужен только телефон', 'стабильный доход',
'бесплатное обучение',
];

/**
Expand Down Expand Up @@ -75,8 +77,8 @@ public function checkByClassifier(): bool

// Train the classifier with spam and ham messages
$this
->trainClassifier($classifier, 'classifiers/spam.json', static::SPAM)
->trainClassifier($classifier, 'classifiers/ham.json', static::HAM);
->trainClassifier($classifier, 'spam.json', static::SPAM)
->trainClassifier($classifier, 'ham.json', static::HAM);

return $classifier->guess($this->message) === static::SPAM;
}
Expand All @@ -92,7 +94,7 @@ public function checkByClassifier(): bool
*/
private function trainClassifier(Classifier $classifier, string $fileName, string $label): self
{
$messages = json_decode(file_get_contents(storage_path($fileName)));
$messages = json_decode(Storage::disk('classifiers')->get($fileName));

foreach ($messages as $message) {
$classifier->learn($message, $label);
Expand Down
6 changes: 6 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
'throw' => false,
],

'classifiers' => [
'driver' => 'local',
'root' => storage_path('classifiers'),
'throw' => false,
],

'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
Expand Down

0 comments on commit 0ae7652

Please sign in to comment.