diff options
Diffstat (limited to 'src/libstat/classifiers')
-rw-r--r-- | src/libstat/classifiers/classifiers.c | 56 | ||||
-rw-r--r-- | src/libstat/classifiers/classifiers.h | 49 |
2 files changed, 49 insertions, 56 deletions
diff --git a/src/libstat/classifiers/classifiers.c b/src/libstat/classifiers/classifiers.c deleted file mode 100644 index 4d78f1f81..000000000 --- a/src/libstat/classifiers/classifiers.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2009-2012, Vsevolod Stakhov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Common classifier functions - */ - -#include "classifiers.h" - -struct classifier classifiers[] = { - { - .name = "bayes", - .init_func = bayes_init, - .classify_func = bayes_classify, - .learn_spam_func = bayes_learn_spam, - } -}; - -struct classifier * -rspamd_stat_get_classifier (const char *name) -{ - guint i; - - for (i = 0; i < sizeof (classifiers) / sizeof (classifiers[0]); i++) { - if (strcmp (classifiers[i].name, name) == 0) { - return &classifiers[i]; - } - } - - return NULL; -} - -/* - * vi:ts=4 - */ diff --git a/src/libstat/classifiers/classifiers.h b/src/libstat/classifiers/classifiers.h new file mode 100644 index 000000000..4ae1ba23d --- /dev/null +++ b/src/libstat/classifiers/classifiers.h @@ -0,0 +1,49 @@ +#ifndef CLASSIFIERS_H +#define CLASSIFIERS_H + +#include "config.h" + +/* Consider this value as 0 */ +#define ALPHA 0.0001 + +struct rspamd_classifier_config; +struct rspamd_task; + +/* Common classifier structure */ +struct classifier_ctx { + rspamd_mempool_t *pool; + GHashTable *results; + gboolean debug; + struct rspamd_classifier_config *cfg; +}; + +struct classifier { + char *name; + struct classifier_ctx * (*init_func)(rspamd_mempool_t *pool, + struct rspamd_classifier_config *cf); + gboolean (*classify_func)(struct classifier_ctx * ctx, + GTree *input, struct rspamd_task *task, + lua_State *L); + gboolean (*learn_spam_func)(struct classifier_ctx * ctx, + GTree *input, struct rspamd_task *task, gboolean is_spam, lua_State *L, + GError **err); +}; + +/* Bayes algorithm */ +struct classifier_ctx * bayes_init (rspamd_mempool_t *pool, + struct rspamd_classifier_config *cf); +gboolean bayes_classify (struct classifier_ctx * ctx, + GTree *input, + struct rspamd_task *task, + lua_State *L); +gboolean bayes_learn_spam (struct classifier_ctx * ctx, + GTree *input, + struct rspamd_task *task, + gboolean is_spam, + lua_State *L, + GError **err); + +#endif +/* + * vi:ts=4 + */ |