static void on_msg_recv(const char *msg) { if (msg == NULL) { /* server closed */ client_main_run = false; return; } msglist_add(msg); }
static void distribute(int mode, tunelist_t *ns_or_sp) { int good = mode == REG_GOOD; int bad = 1 - good; bool divvy = ds_flag == DS_RAM && user_robx < EPS && !msg_count_file; mlitem_t *item; mlhead_t *msgs = ns_or_sp->msgs; int score_count = 0; int train_count = 0; static int train_good = 0; static int train_bad = 0; double ratio = scale(msgs->count, LIST_COUNT + TEST_COUNT, /* small count */ LIST_COUNT + LIST_COUNT, /* large count */ LIST_COUNT / TEST_COUNT, /* small ratio */ LIST_COUNT / LIST_COUNT); /* large ratio */ for (item = msgs->head; item != NULL; item = item->next) { wordhash_t *wh = item->wh; /* training set */ if (divvy && train_count / ratio < score_count + 1) { wordhash_set_counts(wh, good, bad); wordhash_add(train, wh, &wordprop_init); train_count += 1; wordhash_free(wh); train_good += good; train_bad += bad; } /* scoring set */ else { uint bin = divvy ? MOD(score_count,3) : 0; msglist_add(ns_or_sp->u.sets[bin], wh); score_count += 1; } item->wh = NULL; } if (divvy) { wordhash_insert(train, w_msg_count, sizeof(wordprop_t), &wordprop_init); set_msg_counts(train_good, train_bad); } if (verbose > 1) printf("%s: train_count = %d, score_count = %d\n", good ? "ns" : "sp", train_count, score_count); return; }
static uint read_mailbox(const char *arg, mlhead_t *msgs) { if (verbose) { printf("Reading %s\n", arg); fflush(stdout); } init_count(); mbox_mode = true; bogoreader_init(1, &arg); while ((*reader_more)()) { wordhash_t *whp = NULL; wordhash_t *whc = wordhash_new(); collect_words(whc); if (ds_path != NULL && (msgs_good + msgs_bad) == 0) set_train_msg_counts(whc); if (whc->count == 0 && !quiet) { printf("msg #%u, count is %u\n", message_count, whc->count); bt_trap(); } if (bogolex_file != NULL) { wordhash_sort(whc); lookup_words(whc); write_msgcount_file(whc); } else if (whc->count != 0) { if (!msg_count_file) whp = convert_wordhash_to_propslist(whc, train); else whp = convert_propslist_to_countlist(whc); msglist_add(msgs, whp); } update_count(); if (whc != whp) wordhash_free(whc); } print_final_count(); ns_and_sp->count += message_count; bogoreader_fini(); return message_count; }