2 * ʸÀá¤Î¹½Â¤metaword¤ò¥½¡¼¥È¤¹¤ë
4 * ʸÀá¤ËÂФ¹¤ëÊ£¿ô¤Î¹½Â¤¤Î¸õÊä¤ò¥½¡¼¥È¤¹¤ë
6 * Copyright (C) 2000-2007 TABATA Yusuke
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <anthy/segment.h>
28 #include <anthy/ordering.h>
29 #include <anthy/feature_set.h>
30 #include <anthy/splitter.h>
31 #include <anthy/diclib.h>
34 static void *cand_info_array;
37 calc_probability(struct feature_list *fl)
39 struct feature_freq *res, arg;
40 res = anthy_find_feature_freq(cand_info_array,
43 double pos = (double)res->f[15];
44 double neg = (double)res->f[14];
45 double prob = pos / (pos + neg);
54 mw_eval(struct seg_ent *prev_seg, struct seg_ent *seg,
58 struct feature_list fl;
61 anthy_feature_list_init(&fl);
63 anthy_feature_list_set_cur_class(&fl, mw->seg_class);
64 anthy_feature_list_set_dep_word(&fl, mw->dep_word_hash);
65 anthy_feature_list_set_dep_class(&fl, mw->dep_class);
66 anthy_feature_list_set_mw_features(&fl, mw->mw_features);
69 pc = prev_seg->best_seg_class;
73 anthy_feature_list_set_class_trans(&fl, pc, mw->seg_class);
74 anthy_feature_list_sort(&fl);
76 prob = 0.1 + calc_probability(&fl);
78 prob = (double)1 / (double)1000;
80 anthy_feature_list_free(&fl);
81 mw->struct_score = RATIO_BASE * RATIO_BASE;
82 mw->struct_score *= prob;
84 anthy_feature_list_print(&fl);
85 printf(" prob=%f, struct_score=%d\n", prob, mw->struct_score);
89 if (mw->mw_features & MW_FEATURE_SUFFIX) {
90 mw->struct_score /= 2;
92 if (mw->mw_features & MW_FEATURE_WEAK_CONN) {
93 mw->struct_score /= 10;
98 seg_eval(struct seg_ent *prev_seg,
102 for (i = 0; i < seg->nr_metaword; i++) {
103 mw_eval(prev_seg, seg, seg->mw_array[i]);
108 sl_eval(struct segment_list *seg_list)
111 struct seg_ent *prev_seg = NULL;
112 for (i = 0; i < seg_list->nr_segments; i++) {
114 seg = anthy_get_nth_segment(seg_list, i);
115 seg_eval(prev_seg, seg);
121 metaword_compare_func(const void *p1, const void *p2)
123 const struct meta_word * const *s1 = p1;
124 const struct meta_word * const *s2 = p2;
125 return (*s2)->struct_score - (*s1)->struct_score;
129 anthy_sort_metaword(struct segment_list *seg_list)
135 for (i = 0; i < seg_list->nr_segments; i++) {
136 struct seg_ent *seg = anthy_get_nth_segment(seg_list, i);
137 if (seg->mw_array) { /* ÉÔÀµ¤Ê¥á¥â¥ê¥¢¥¯¥»¥¹¤ò¹Ô¤¦¥Ð¥°¤Î½¤Àµ */
138 qsort(seg->mw_array, seg->nr_metaword, sizeof(struct meta_word *),
139 metaword_compare_func);
145 anthy_infosort_init(void)
147 cand_info_array = anthy_file_dic_get_section("cand_info");