3 * ÁÇÀ¤ÎÈÖ¹æ¤È°ÕÌ£¤ò±£Ê䷤ƴÉÍý¤¹¤ë
5 * Copyright (C) 2006-2007 TABATA Yusuke
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <arpa/inet.h>
27 #include <anthy/segclass.h>
28 #include <anthy/feature_set.h>
29 /* for MW_FEATURE* constants */
30 #include <anthy/splitter.h>
35 * 30-319(30+SEG_SIZE^2) ¥¯¥é¥¹Á«°Ü°À
37 * 580- (1024¸Ä) ÉÕ°¸ì¤Î¼ïÎà
40 #define CUR_CLASS_BASE 0
41 #define DEP_TYPE_FEATURE_BASE 20
42 #define CLASS_TRANS_BASE 30
43 #define FEATURE_SV 542
44 #define FEATURE_WEAK 543
45 #define FEATURE_SUFFIX 544
46 #define FEATURE_NUM 546
47 #define FEATURE_CORE1 547
48 #define FEATURE_HIGH_FREQ 548
49 #define FEATURE_WEAK_SEQ 549
51 #define DEP_FEATURE_BASE 580
54 anthy_feature_list_init(struct feature_list *fl)
57 fl->size = NR_EM_FEATURES;
61 anthy_feature_list_free(struct feature_list *fl)
67 anthy_feature_list_add(struct feature_list *fl, int f)
69 if (fl->nr < NR_EM_FEATURES) {
70 fl->u.index[fl->nr] = f;
76 anthy_feature_list_nr(const struct feature_list *fl)
82 anthy_feature_list_nth(const struct feature_list *fl, int nth)
84 return fl->u.index[nth];
88 cmp_short(const void *p1, const void *p2)
90 return *((short *)p1) - *((short *)p2);
94 anthy_feature_list_sort(struct feature_list *fl)
96 qsort(fl->u.index, fl->nr, sizeof(fl->u.index[0]),
102 anthy_feature_list_set_cur_class(struct feature_list *fl, int cl)
104 anthy_feature_list_add(fl, CUR_CLASS_BASE + cl);
108 anthy_feature_list_set_class_trans(struct feature_list *fl, int pc, int cc)
110 anthy_feature_list_add(fl, CLASS_TRANS_BASE + pc * SEG_SIZE + cc);
114 anthy_feature_list_set_dep_word(struct feature_list *fl, int h)
116 anthy_feature_list_add(fl, h + DEP_FEATURE_BASE);
120 anthy_feature_list_set_dep_class(struct feature_list *fl, int c)
122 anthy_feature_list_add(fl, c + DEP_TYPE_FEATURE_BASE);
126 anthy_feature_list_set_noun_cos(struct feature_list *fl, wtype_t wt)
129 if (anthy_wtype_get_pos(wt) != POS_NOUN) {
132 c = anthy_wtype_get_cos(wt);
133 if (c == COS_SUFFIX) {
134 anthy_feature_list_add(fl, COS_BASE + c);
139 anthy_feature_list_set_mw_features(struct feature_list *fl, int mask)
141 if (mask & MW_FEATURE_WEAK_CONN) {
142 anthy_feature_list_add(fl, FEATURE_WEAK);
144 if (mask & MW_FEATURE_SUFFIX) {
145 anthy_feature_list_add(fl, FEATURE_SUFFIX);
147 if (mask & MW_FEATURE_SV) {
148 anthy_feature_list_add(fl, FEATURE_SV);
150 if (mask & MW_FEATURE_NUM) {
151 anthy_feature_list_add(fl, FEATURE_NUM);
153 if (mask & MW_FEATURE_CORE1) {
154 anthy_feature_list_add(fl, FEATURE_CORE1);
156 if (mask & MW_FEATURE_HIGH_FREQ) {
157 anthy_feature_list_add(fl, FEATURE_HIGH_FREQ);
159 if (mask & MW_FEATURE_WEAK_SEQ) {
160 anthy_feature_list_add(fl, FEATURE_WEAK_SEQ);
165 anthy_feature_list_print(struct feature_list *fl)
169 for (i = 0; i < fl->nr; i++) {
173 printf("%d", fl->u.index[i]);
179 compare_line(const void *kp, const void *cp)
182 const struct feature_freq *c = cp;
184 for (i = 0; i < NR_EM_FEATURES; i++) {
185 if (f[i] != (int)ntohl(c->f[i])) {
186 return f[i] - ntohl(c->f[i]);
192 struct feature_freq *
193 anthy_find_array_freq(const void *image, int *f, int nr,
194 struct feature_freq *arg)
196 struct feature_freq *res;
198 const int *array = (int *)image;
199 int n[NR_EM_FEATURES];
204 for (i = 0; i < NR_EM_FEATURES; i++) {
212 nr_lines = ntohl(array[1]);
213 res = bsearch(n, &array[16], nr_lines,
214 sizeof(struct feature_freq),
219 for (i = 0; i < NR_EM_FEATURES + 2; i++) {
220 arg->f[i] = ntohl(res->f[i]);
225 struct feature_freq *
226 anthy_find_feature_freq(const void *image,
227 const struct feature_list *fl,
228 struct feature_freq *arg)
231 int f[NR_EM_FEATURES + 2];
233 /* ÇÛÎó¤Ë¥³¥Ô¡¼¤¹¤ë */
234 nr = anthy_feature_list_nr(fl);
235 for (i = 0; i < NR_EM_FEATURES + 2; i++) {
237 f[i] = anthy_feature_list_nth(fl, i);
242 return anthy_find_array_freq(image, f, NR_EM_FEATURES, arg);
246 anthy_init_features(void)