You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2011/05/09 02:46:35 UTC

svn commit: r1100854 - in /spamassassin/branches/3.3/lib/Mail/SpamAssassin: Conf.pm Plugin/AutoLearnThreshold.pm

Author: mmartinec
Date: Mon May  9 00:46:35 2011
New Revision: 1100854

URL: http://svn.apache.org/viewvc?rev=1100854&view=rev
Log:
Bug 6447: new feature to bayes autolearning: learn-on-error

Modified:
    spamassassin/branches/3.3/lib/Mail/SpamAssassin/Conf.pm
    spamassassin/branches/3.3/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm

Modified: spamassassin/branches/3.3/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.3/lib/Mail/SpamAssassin/Conf.pm?rev=1100854&r1=1100853&r2=1100854&view=diff
==============================================================================
--- spamassassin/branches/3.3/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/branches/3.3/lib/Mail/SpamAssassin/Conf.pm Mon May  9 00:46:35 2011
@@ -4000,6 +4000,7 @@ sub sa_die { Mail::SpamAssassin::sa_die(
 #   if (can(Mail::SpamAssassin::Conf::feature_originating_ip_headers))
 
 sub feature_originating_ip_headers { 1 }
+sub feature_bayes_auto_learn_on_error { 1 }
 sub feature_bug6558_free { 1 }
 
 ###########################################################################

Modified: spamassassin/branches/3.3/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.3/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm?rev=1100854&r1=1100853&r2=1100854&view=diff
==============================================================================
--- spamassassin/branches/3.3/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm (original)
+++ spamassassin/branches/3.3/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm Mon May  9 00:46:35 2011
@@ -114,6 +114,29 @@ working value for this option is 6.
     type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
   });
 
+=item bayes_auto_learn_on_error (0 | 1)        (default: 0)
+
+With C<bayes_auto_learn_on_error> off, autolearning will be performed
+even if bayes classifier already agrees with the new classification (i.e.
+yielded BAYES_00 for what we are now trying to teach it as ham, or yielded
+BAYES_99 for spam). This is a traditional setting, the default was chosen
+to retain backwards compatibility.
+
+With C<bayes_auto_learn_on_error> turned on, autolearning will be performed
+only when a bayes classifier had a different opinion from what the autolearner
+is now trying to teach it (i.e. it made an error in judgement). This strategy
+may or may not produce better future classifications, but usually works
+very well, while also preventing unnecessary overlearning and slows down
+database growth.
+
+=cut
+
+  push (@cmds, {
+    setting => 'bayes_auto_learn_on_error',
+    default => 0,
+    type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL
+  });
+
   $conf->{parser}->register_commands(\@cmds);
 }
 
@@ -190,6 +213,22 @@ sub autolearn_discriminator {
     }
   }
 
+  if ($conf->{bayes_auto_learn_on_error}) {
+    # learn-on-error strategy chosen:
+    # only allow learning if the autolearning classifier was unsure or
+    # had a different opinion from what we are trying to make it learn
+    #
+    my $tests = $scan->get_tag('TESTS');
+    if (defined $tests && $tests ne 'none') {
+      my %t = map { ($_,1) } split(/,/, $tests);
+      if ($isspam && $t{'BAYES_99'} || !$isspam && $t{'BAYES_00'}) {
+        dbg("learn: auto-learn? no: learn-on-error, %s, already classified ".
+            "as such",  $isspam ? 'spam' : 'ham');
+        return;
+      }
+    }
+  }
+
   dbg("learn: auto-learn? yes, ".($isspam?"spam ($score > $max)":"ham ($score < $min)"));
   return $isspam;
 }