File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,9 @@ public function checkByClassifier(): bool
74
74
$ classifier = new Classifier ();
75
75
76
76
// 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 );
79
80
80
81
return $ classifier ->guess ($ this ->message ) === static ::SPAM ;
81
82
}
@@ -87,14 +88,17 @@ public function checkByClassifier(): bool
87
88
* @param string $fileName The path to the JSON file containing messages
88
89
* @param string $label The label to assign to the messages (spam or ham)
89
90
*
90
- * @return void
91
+ * @return self
91
92
*/
92
- private function trainClassifier (Classifier $ classifier , string $ fileName , string $ label ): void
93
+ private function trainClassifier (Classifier $ classifier , string $ fileName , string $ label ): self
93
94
{
94
95
$ messages = json_decode (file_get_contents (storage_path ($ fileName )));
96
+
95
97
foreach ($ messages as $ message ) {
96
98
$ classifier ->learn ($ message , $ label );
97
99
}
100
+
101
+ return $ this ;
98
102
}
99
103
100
104
/**
You can’t perform that action at this time.
0 commit comments