[cvs] bogofilter/src datastore.c,1.59,1.60 robx.c,1.16,1.17
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2005-01-16 05:04:56
|
Update of /cvsroot/bogofilter/bogofilter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17051 Modified Files: datastore.c robx.c Log Message: Implement msg_count_first code in ds_oper and use it for compute_robinson_x. Index: datastore.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/datastore.c,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- datastore.c 16 Jan 2005 04:54:11 -0000 1.59 +++ datastore.c 16 Jan 2005 05:04:46 -0000 1.60 @@ -339,8 +339,17 @@ } if (DST_OK == ds_txn_begin(dsh)) { - ret = ds_foreach(dsh, hook, userdata); - if (ret) { ds_txn_abort(dsh); } + if (msg_count_first) { + dsv_t dsv_data; + ret = ds_get_msgcounts(dsh, &dsv_data); + if (ret == EX_OK) + ret = hook(NULL, &dsv_data, userdata); + } + + if (ret == EX_OK) + ret = ds_foreach(dsh, hook, userdata); + + if (ret != EX_OK) { ds_txn_abort(dsh); } else if (ds_txn_commit(dsh) != DST_OK) ret = EX_ERROR; Index: robx.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/robx.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- robx.c 21 Nov 2004 04:37:39 -0000 1.16 +++ robx.c 16 Jan 2005 05:04:46 -0000 1.17 @@ -58,36 +58,36 @@ struct robhook_data *rh = userdata; /* ignore system meta-data */ - if (*key->text == '.') + if (*key->text == '.') { + size_t len = strlen(".MSG_COUNT"); + if (key->leng == len && memcmp(key->text, ".MSG_COUNT", len) == 0) { + uint spam_cnt = data->spamcount; + uint good_cnt = data->goodcount; + rh->scalefactor = (double)spam_cnt/(double)good_cnt; + } return 0; + } robx_accum(rh, key, data); return 0; } -/** returns negative for failure */ -static double compute_robx(dsh_t *dsh) +/** returns negative for failure. + * used by bogoutil and bogotune */ +double compute_robinson_x(const char *path) { + int ret; double rx; + dsh_t *dsh; - dsv_t val; - bool ok; uint good_cnt, spam_cnt; struct robhook_data rh; - int ret; - - ok = ds_get_msgcounts(dsh, &val) == 0; - - if (!ok) { - fprintf(stderr, "Can't find message counts.\n"); - return -1; - } - spam_cnt = val.spamcount; - good_cnt = val.goodcount; + set_wordlist_dir(path, PR_NONE); + open_wordlists(word_lists, DS_READ); + dsh = get_default_wordlist(word_lists)->dsh; - rh.scalefactor = (double)spam_cnt/(double)good_cnt; rh.dsh = dsh; rh.sum = 0.0; rh.count = 0; @@ -100,23 +100,7 @@ MSG_COUNT, spam_cnt, good_cnt, rh.scalefactor, rh.sum, (int)rh.count, rx); - return ret ? -1 : rx; -} - -/** returns negative for failure. - * used by bogoutil and bogotune */ -double compute_robinson_x(const char *path) -{ - double rx; - dsh_t *ds; - - set_wordlist_dir(path, PR_NONE); - open_wordlists(word_lists, DS_READ); - ds = get_default_wordlist(word_lists)->dsh; - - rx = compute_robx(ds); - close_wordlists(word_lists, true); - return rx; + return ret ? -1 : rx; } |