]> source.dussan.org Git - rspamd.git/commitdiff
* Add classifiers pre-selection script
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 19 Jul 2011 13:51:28 +0000 (17:51 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 19 Jul 2011 13:51:28 +0000 (17:51 +0400)
conf/lua/rspamd.classifiers.lua [new file with mode: 0644]
conf/lua/rspamd.lua

diff --git a/conf/lua/rspamd.classifiers.lua b/conf/lua/rspamd.classifiers.lua
new file mode 100644 (file)
index 0000000..e158a29
--- /dev/null
@@ -0,0 +1,48 @@
+-- Detect language of message and selects appropriate statfiles for it
+
+classifiers['bayes'] = function(classifier, task, is_learn, is_spam)
+       -- Subfunction for detection of message's language
+       local detect_language = function(task)
+               local parts = task:get_text_parts()
+               for _,p in ipairs(parts) do
+                       local l = p:get_language()
+                       if l then
+                               return l
+                       end
+               end
+               return nil
+       end
+
+       -- Main procedure
+       language = detect_language(task)
+       if language then
+               -- Find statfiles with specified language
+               local selected = {}
+               for _,st in pairs(classifier:get_statfiles()) do
+                       local st_l = st:get_param('language')
+                       if st_l and st_l == language then
+                           -- Insert statfile with specified language    
+                           table.insert(selected, st)
+                       end
+               end
+               if table.maxn(selected) > 1 then
+                       return selected
+               end
+       else
+               -- Language not detected
+               local selected = {}
+               for _,st in ipairs(classifier:get_statfiles()) do
+                       local st_l = st:get_param('language')
+                       -- Insert only statfiles without language
+                       if not st_l then
+                               table.insert(selected, st)
+                       end
+               end
+               if table.maxn(selected) > 1 then
+                       return selected
+               end
+       end
+
+       return nil
+end
+
index 203862776f53f319d02b20a7d90f3c0c60a09faf..822f6447fe617fe2d76c2932c551ce7a95ef3428 100644 (file)
@@ -82,3 +82,7 @@ end
 if file_exists('rspamd.local.lua') then
        dofile('rspamd.local.lua')
 end
+
+if file_exists('rspamd.classifiers.lua') then
+       dofile('rspamd.classifiers.lua')
+end