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 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/*
* Ф
*/
#include <segment.h>
#include <record.h>
#include "sorter.h"
#define HISTORY_DEPTH 8
#define MAX_HISTORY_ENTRY 200
/** ʸΥߥåȤɲä */
static void
learn_history(struct seg_ent *seg)
{
int nr, i;
if (anthy_select_column(&seg->str, 1)) {
return ;
}
/* եȤ */
nr = anthy_get_nr_values();
nr ++;
if (nr > HISTORY_DEPTH) {
nr = HISTORY_DEPTH;
}
for (i = nr - 1; i > 0; i--) {
xstr *xs = anthy_get_nth_xstr(i - 1);
anthy_set_nth_xstr(i, xs);
}
/* 0ܤ */
anthy_set_nth_xstr(0, &seg->cands[seg->committed]->str);
}
/** ƤФؿ
* ɲä */
void
anthy_learn_cand_history(struct segment_list *sl)
{
int i, nr = 0;
if (anthy_select_section("CAND_HISTORY", 1)) {
return ;
}
for (i = 0; i < sl->nr_segments; i++) {
struct seg_ent *seg = anthy_get_nth_segment(sl, i);
xstr *xs = &seg->str;
if (seg->committed < 0) {
continue;
}
if (anthy_select_column(xs, 0)) {
if (seg->committed == 0) {
/* Υȥ̵꤬ơߥåȤ줿ƬΤΤǤХѥ */
continue;
}
}
/**/
learn_history(seg);
nr ++;
}
if (nr) {
anthy_truncate_section(MAX_HISTORY_ENTRY);
}
}
/* ߤƸνŤߤ */
static int
get_history_weight(xstr *xs)
{
int i, nr = anthy_get_nr_values();
int w = 0;
for (i = 0; i < nr; i++) {
xstr *h = anthy_get_nth_xstr(i);
if (!anthy_xstrcmp(xs, h)) {
w++;
if (i == 0) {
/* ľ˳ꤵ줿ΤˤϹ⤤*/
w += (HISTORY_DEPTH / 2);
}
}
}
return w;
}
void
anthy_reorder_candidates_by_history(struct seg_ent *se)
{
int i, primary_score;
/**/
if (anthy_select_section("CAND_HISTORY", 1)) {
return ;
}
if (anthy_select_column(&se->str, 0)) {
return ;
}
/* Ǥɾι⤤ */
primary_score = se->cands[0]->score;
/**/
for (i = 0; i < se->nr_cands; i++) {
struct cand_ent *ce = se->cands[i];
int weight = get_history_weight(&ce->str);
ce->score += primary_score / (HISTORY_DEPTH /2) * weight;
}
anthy_mark_column_used();
}
|