]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Insert two symbols: FANN_HAM and FANN_SPAM instead of one
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 5 Sep 2016 16:18:05 +0000 (17:18 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 5 Sep 2016 16:18:05 +0000 (17:18 +0100)
src/plugins/lua/fann_scores.lua

index cafa5befa73a20a9e7ce181ecf97587fb74f6970..4d5c9a1567f3ec9d72d9cda86523f83df5ed07d2 100644 (file)
@@ -20,7 +20,8 @@ limitations under the License.
 local rspamd_logger = require "rspamd_logger"
 local rspamd_fann = require "rspamd_fann"
 local rspamd_util = require "rspamd_util"
-local fann_symbol = 'FANN_SCORE'
+local fann_symbol_spam = 'FANN_SPAM'
+local fann_symbol_ham = 'FANN_HAM'
 require "fun" ()
 local ucl = require "ucl"
 
@@ -161,7 +162,11 @@ local function fann_scores_filter(task)
     local symscore = string.format('%.3f', out[1])
     rspamd_logger.infox(task, 'fann score: %s', symscore)
 
-    task:insert_result(fann_symbol, result, symscore, id)
+    if symscore > 0 then
+      task:insert_result(fann_symbol_spam, result, symscore, id)
+    else
+      task:insert_result(fann_symbol_ham, result, -(symscore), id)
+    end
   else
     if load_fann(id) then
       fann_scores_filter(task)
@@ -262,11 +267,16 @@ else
     fann_file = opts['fann_file']
     use_settings = opts['use_settings']
     rspamd_config:set_metric_symbol(fann_symbol, 3.0, 'Experimental FANN adjustment')
-    rspamd_config:register_symbol({
-      name = fann_symbol,
+    local id = rspamd_config:register_symbol({
+      name = fann_symbol_spam,
       type = 'postfilter',
       callback = fann_scores_filter
     })
+    rspamd_config:register_symbol({
+      name = fann_symbol_ham,
+      type = 'virtual',
+      parent = id
+    })
     if opts['train'] then
       rspamd_config:add_on_load(function(cfg)
         if opts['train']['max_train'] then