blob: e158a29a6cffe7f384c043425bf6d4790f0a8858 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
|