]> git.wh0rd.org - tt-rss.git/commitdiff
classifier: add workaround for division by zero
authorAndrew Dolgov <noreply@fakecake.org>
Wed, 17 Jun 2015 16:26:50 +0000 (19:26 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Wed, 17 Jun 2015 16:26:50 +0000 (19:26 +0300)
plugins/af_sort_bayes/lib/class.naivebayesian.php

index c80c3f2151b27ac71a2156ca08a29ea58a8efc43..da81f2aabe5cebfc56041b7f3b213cd3a97f2514 100644 (file)
                                $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);