5 * ¤¢¤ëÆɤߤÎÍúÎò¤¬ ¸õÊäA ¸õÊäB ¸õÊäA ¸õÊäA ¸õÊäA
6 * ¤Ç¤¢¤Ã¤¿¤È¤¤¤¦¤è¤¦¤Ê¾ðÊó¤ò¤â¤È¤Ë¸õÊä¤Î¥¹¥³¥¢¤ò²ÃÅÀ¤¹¤ë¡£
8 * Copyright (C) 2006-2007 TABATA Yusuke
13 #include <anthy/segment.h>
14 #include <anthy/record.h>
17 #define HISTORY_DEPTH 8
18 #define MAX_HISTORY_ENTRY 200
20 /** ʸÀá¤Î¥³¥ß¥Ã¥È¤òÍúÎò¤ËÄɲ乤ë */
22 learn_cand_history(struct seg_ent *seg)
26 if (anthy_select_section("CAND_HISTORY", 1)) {
29 if (anthy_select_row(&seg->str, 1)) {
33 nr = anthy_get_nr_values();
35 if (nr > HISTORY_DEPTH) {
38 for (i = nr - 1; i > 0; i--) {
39 xstr *xs = anthy_get_nth_xstr(i - 1);
40 anthy_set_nth_xstr(i, xs);
43 anthy_set_nth_xstr(0, &seg->cands[seg->committed]->str);
44 anthy_mark_row_used();
48 learn_suffix_history(struct seg_ent *seg)
51 struct cand_ent *cand = seg->cands[seg->committed];
52 if (anthy_select_section("SUFFIX_HISTORY", 1)) {
55 for (i = 0; i < cand->nr_words; i++) {
56 struct cand_elm *elm = &cand->elm[i];
61 if (anthy_wtype_get_pos(elm->wt) != POS_SUC) {
64 if (anthy_select_row(&elm->str, 1)) {
67 if (anthy_get_nth_dic_ent_str(elm->se, &elm->str, elm->nth, &xs)) {
70 anthy_set_nth_xstr(0, &xs);
75 /** ³°¤«¤é¸Æ¤Ð¤ì¤ë´Ø¿ô
78 anthy_learn_cand_history(struct segment_list *sl)
81 for (i = 0; i < sl->nr_segments; i++) {
82 struct seg_ent *seg = anthy_get_nth_segment(sl, i);
84 if (seg->committed < 0) {
87 if (anthy_select_row(xs, 0)) {
88 if (seg->committed == 0) {
89 /* ¸õÊä¤Î¥¨¥ó¥È¥ê¤¬Ìµ¤¯¤Æ¡¢¥³¥ß¥Ã¥È¤µ¤ì¤¿¸õÊä¤âÀèƬ¤Î¤â¤Î¤Ç¤¢¤ì¤Ð¥Ñ¥¹ */
94 learn_cand_history(seg);
95 learn_suffix_history(seg);
99 if (!anthy_select_section("CAND_HISTORY", 1)) {
100 anthy_truncate_section(MAX_HISTORY_ENTRY);
102 if (!anthy_select_section("SUFFIX_HISTORY", 1)) {
103 anthy_truncate_section(MAX_HISTORY_ENTRY);
108 /* ÍúÎò¤ò¤ß¤Æ¸õÊä¤Î½Å¤ß¤ò·×»»¤¹¤ë */
110 get_history_weight(xstr *xs)
112 int i, nr = anthy_get_nr_values();
114 for (i = 0; i < nr; i++) {
115 xstr *h = anthy_get_nth_xstr(i);
119 if (!anthy_xstrcmp(xs, h)) {
122 /* ľÁ°¤Ë³ÎÄꤵ¤ì¤¿¤â¤Î¤Ë¤Ï¹â¤¤¥¹¥³¥¢*/
123 w += (HISTORY_DEPTH / 2);
131 reorder_by_candidate(struct seg_ent *se)
133 int i, primary_score;
135 if (anthy_select_section("CAND_HISTORY", 1)) {
138 if (anthy_select_row(&se->str, 0)) {
141 /* ºÇ¤âɾ²Á¤Î¹â¤¤¸õÊä */
142 primary_score = se->cands[0]->score;
144 for (i = 0; i < se->nr_cands; i++) {
145 struct cand_ent *ce = se->cands[i];
146 int weight = get_history_weight(&ce->str);
147 ce->score += primary_score / (HISTORY_DEPTH /2) * weight;
149 anthy_mark_row_used();
152 /* ÀÜÈø¼¤Î³Ø½¬¤òŬÍѤ¹¤ë */
154 reorder_by_suffix(struct seg_ent *se)
159 if (anthy_select_section("SUFFIX_HISTORY", 0)) {
163 for (i = 0; i < se->nr_cands; i++) {
164 struct cand_ent *ce = se->cands[i];
165 /* ¸õÊä¤ò¹½À®¤¹¤ë³Æñ¸ì */
166 for (j = 0; j < ce->nr_words; j++) {
167 struct cand_elm *elm = &ce->elm[j];
169 if (elm->nth == -1) {
172 if (anthy_wtype_get_pos(elm->wt) != POS_SUC) {
175 /* ÊÑ´¹¸µ¤Îʸ»úÎó¤ò¥¡¼¤Ë¸¡º÷ */
176 if (anthy_select_row(&elm->str, 0)) {
179 /* ÊÑ´¹¸å¤Îʸ»úÎó¤ò¼èÆÀ */
180 if (anthy_get_nth_dic_ent_str(elm->se, &elm->str, elm->nth, &xs)) {
183 /* ÍúÎòÃæ¤Îʸ»úÎó¤ÈÈæ³Ó¤¹¤ë */
184 if (anthy_xstrcmp(&xs, anthy_get_nth_xstr(0))) {
193 delta = (se->cands[top_cand]->score - ce->score) + 1;
203 anthy_reorder_candidates_by_history(struct seg_ent *se)
205 reorder_by_candidate(se);
206 reorder_by_suffix(se);