aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat/classifiers/classifiers.h
blob: 32473cdd1fe94dc5608a557f9c411e569bffd40a (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef CLASSIFIERS_H
#define CLASSIFIERS_H

#include "config.h"
#include "mem_pool.h"
#include "contrib/libev/ev.h"

#define RSPAMD_DEFAULT_CLASSIFIER "bayes"
/* Consider this value as 0 */
#define ALPHA 0.0001

#ifdef  __cplusplus
extern "C" {
#endif

struct rspamd_classifier_config;
struct rspamd_task;
struct rspamd_config;
struct rspamd_classifier;

struct token_node_s;

struct rspamd_stat_classifier {
	char *name;

	gboolean (*init_func) (struct rspamd_config *cfg,
						   struct ev_loop *ev_base,
						   struct rspamd_classifier *cl);

	gboolean (*classify_func) (struct rspamd_classifier *ctx,
							   GPtrArray *tokens,
							   struct rspamd_task *task);

	gboolean (*learn_spam_func) (struct rspamd_classifier *ctx,
								 GPtrArray *input,
								 struct rspamd_task *task,
								 gboolean is_spam,
								 gboolean unlearn,
								 GError **err);

	void (*fin_func) (struct rspamd_classifier *cl);
};

/* Bayes algorithm */
gboolean bayes_init (struct rspamd_config *cfg,
					 struct ev_loop *ev_base,
					 struct rspamd_classifier *);

gboolean bayes_classify (struct rspamd_classifier *ctx,
						 GPtrArray *tokens,
						 struct rspamd_task *task);

gboolean bayes_learn_spam (struct rspamd_classifier *ctx,
						   GPtrArray *tokens,
						   struct rspamd_task *task,
						   gboolean is_spam,
						   gboolean unlearn,
						   GError **err);

void bayes_fin (struct rspamd_classifier *);

/* Generic lua classifier */
gboolean lua_classifier_init (struct rspamd_config *cfg,
							  struct ev_loop *ev_base,
							  struct rspamd_classifier *);

gboolean lua_classifier_classify (struct rspamd_classifier *ctx,
								  GPtrArray *tokens,
								  struct rspamd_task *task);

gboolean lua_classifier_learn_spam (struct rspamd_classifier *ctx,
									GPtrArray *tokens,
									struct rspamd_task *task,
									gboolean is_spam,
									gboolean unlearn,
									GError **err);

extern gint rspamd_bayes_log_id;
#define msg_debug_bayes(...)  rspamd_conditional_debug_fast (NULL, task->from_addr, \
        rspamd_bayes_log_id, "bayes", task->task_pool->tag.uid, \
        G_STRFUNC, \
        __VA_ARGS__)


#ifdef  __cplusplus
}
#endif

#endif