Skip to content

Commit 801d769

Browse files
committed
Changed SpamDetector
1 parent c5f9092 commit 801d769

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/Services/SpamDetector.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ public function checkByClassifier(): bool
7474
$classifier = new Classifier();
7575

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

8081
return $classifier->guess($this->message) === static::SPAM;
8182
}
@@ -87,14 +88,17 @@ public function checkByClassifier(): bool
8788
* @param string $fileName The path to the JSON file containing messages
8889
* @param string $label The label to assign to the messages (spam or ham)
8990
*
90-
* @return void
91+
* @return self
9192
*/
92-
private function trainClassifier(Classifier $classifier, string $fileName, string $label): void
93+
private function trainClassifier(Classifier $classifier, string $fileName, string $label): self
9394
{
9495
$messages = json_decode(file_get_contents(storage_path($fileName)));
96+
9597
foreach ($messages as $message) {
9698
$classifier->learn($message, $label);
9799
}
100+
101+
return $this;
98102
}
99103

100104
/**

0 commit comments

Comments
 (0)