From 4da0cb323f8b8450185a9cde9861bb01448935bd Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Jun 2015 19:26:50 +0300 Subject: [PATCH] classifier: add workaround for division by zero --- plugins/af_sort_bayes/lib/class.naivebayesian.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/af_sort_bayes/lib/class.naivebayesian.php b/plugins/af_sort_bayes/lib/class.naivebayesian.php index c80c3f21..da81f2aa 100644 --- a/plugins/af_sort_bayes/lib/class.naivebayesian.php +++ b/plugins/af_sort_bayes/lib/class.naivebayesian.php @@ -80,7 +80,11 @@ $scores[$category] = $data['probability']; // small probability for a word not in the category // maybe putting 1.0 as a 'no effect' word can also be good - $small_proba = 1.0 / ($data['word_count'] * 2); + + if ($data['word_count'] > 0) + $small_proba = 1.0 / ($data['word_count'] * 2); + else + $small_proba = 0; reset($tokens); -- 2.39.5