aboutsummaryrefslogtreecommitdiffstats
path: root/conf/lua/rspamd.classifiers.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-07-19 17:51:28 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-07-19 17:51:28 +0400
commit4335e5a8ce4e23abd9c2977df7f1b13665b80202 (patch)
tree80283ee9604b850763fb3b3bf9339f694a5c6374 /conf/lua/rspamd.classifiers.lua
parentfd4de5a9277d8d4a75b2258b4e1f8cf20c8e0e1d (diff)
downloadrspamd-4335e5a8ce4e23abd9c2977df7f1b13665b80202.tar.gz
rspamd-4335e5a8ce4e23abd9c2977df7f1b13665b80202.zip
* Add classifiers pre-selection script
Diffstat (limited to 'conf/lua/rspamd.classifiers.lua')
-rw-r--r--conf/lua/rspamd.classifiers.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/conf/lua/rspamd.classifiers.lua b/conf/lua/rspamd.classifiers.lua
new file mode 100644
index 000000000..e158a29a6
--- /dev/null
+++ b/conf/lua/rspamd.classifiers.lua
@@ -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
+