aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-26 16:17:33 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-26 16:17:33 +0000
commit9fe6930420bbe6bfa84d3571804661f734cd203f (patch)
treeb3dd06ac375c165ef5c7e5f71686c41a56442e0b /src
parenta9db62e8a83293caf5f93ce94e2ab4d9b52426c0 (diff)
downloadrspamd-9fe6930420bbe6bfa84d3571804661f734cd203f.tar.gz
rspamd-9fe6930420bbe6bfa84d3571804661f734cd203f.zip
Implement learning function.
Diffstat (limited to 'src')
-rw-r--r--src/libstat/stat_process.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 59c349f73..e00c0aaa8 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -370,3 +370,73 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err)
return ret;
}
+
+gboolean
+rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L,
+ GError **err)
+{
+ struct rspamd_stat_classifier *cls;
+ struct rspamd_classifier_config *clcf;
+ struct rspamd_stat_ctx *st_ctx;
+ struct rspamd_tokenizer_runtime *tklist = NULL, *tok;
+ struct rspamd_classifier_runtime *cl_run;
+ struct classifier_ctx *cl_ctx;
+ GList *cl_runtimes;
+ GList *cur;
+ gboolean ret = FALSE;
+
+ st_ctx = rspamd_stat_get_ctx ();
+ g_assert (st_ctx != NULL);
+
+ cur = g_list_first (task->cfg->classifiers);
+
+ /* Tokenization */
+ while (cur) {
+ clcf = (struct rspamd_classifier_config *)cur->data;
+ cls = rspamd_stat_get_classifier (clcf->classifier);
+
+ if (cls == NULL) {
+ g_set_error (err, rspamd_stat_quark (), 500, "type %s is not defined"
+ "for classifiers", clcf->classifier);
+ return FALSE;
+ }
+
+ tok = rspamd_stat_get_tokenizer_runtime (clcf->tokenizer, task->task_pool,
+ &tklist);
+
+ if (tok == NULL) {
+ g_set_error (err, rspamd_stat_quark (), 500, "type %s is not defined"
+ "for tokenizers", clcf->tokenizer);
+ return FALSE;
+ }
+
+ rspamd_stat_process_tokenize (st_ctx, task, tok);
+
+ cur = g_list_next (cur);
+ }
+
+ /* Initialize classifiers and statfiles runtime */
+ if ((cl_runtimes = rspamd_stat_preprocess (st_ctx, task, tklist, L, err))
+ == NULL) {
+ return FALSE;
+ }
+
+ cur = cl_runtimes;
+
+ while (cur) {
+ cl_run = (struct rspamd_classifier_runtime *)cur->data;
+
+ if (cl_run->cl) {
+ cl_ctx = cl_run->cl->init_func (task->task_pool, cl_run->clcf);
+
+ if (cl_ctx != NULL) {
+ ret |= cl_run->cl->learn_spam_func (cl_ctx, cl_run->tok->tokens,
+ cl_run, task, spam, err);
+ }
+ }
+
+ cur = g_list_next (cur);
+ }
+
+ return ret;
+}