NIIBE Yutaka
gniib****@m17n*****
2005年 10月 15日 (土) 16:16:04 JST
9 つめ。 田畑さん、吉田さん: えーと、お昼に話してたのはこれなんですけど。 ここまでやっておくと、wtype_t の実装(今はビットに encode している) を ハンドルがあってアクセサがテーブルを引くというのに変更できます。 言いたかったのは、ビットに encode しているという実装を「使う側」も 知っているというインタフェースってどうですかってことです。 2005-10-15 NIIBE Yutaka <gniib****@fsij*****> * src-splitter/depgraph.c (anthy_get_nth_dep_rule): Use anthy_get_wtype. * src-diclib/wtype.c (anthy_init_wtype_by_name) (anthy_type_to_wtype): Likewise. * src-diclib/file_dic.c (add_dic_ent): Use anthy_get_wtype_with_ct. * src-splitter/compose.c (enum_candidates): Likewise. * src-diclib/wtype.c (anthy_get_wtype_with_ct, anthy_get_wtype): New functions. * include/wtype.h (anthy_get_wtype, anthy_get_wtype_with_ct): New function declarations. * src-diclib/wtype.c (anthy_type_to_wtype): Don't set POS_INVAL partially, but substitute anthy_wt_none. * src-diclib/file_dic.c (parse_wtype_str): Don't set POS_INVAL partially, but substitute anthy_wt_none. diff --git a/include/wtype.h b/include/wtype.h --- a/include/wtype.h +++ b/include/wtype.h @@ -213,6 +213,9 @@ int anthy_wtype_get_sv(wtype_t w); int anthy_wtype_get_meisi(wtype_t w); int anthy_wtype_get_ajv(wtype_t w); +wtype_t anthy_get_wtype(int pos, int cos, int scos, int cc, int ct, int wf); +wtype_t anthy_get_wtype_with_ct(wtype_t base, int ct); + void anthy_wtype_set_pos(wtype_t *w, int pos); void anthy_wtype_set_cc(wtype_t *w, int cc); void anthy_wtype_set_ct(wtype_t *w, int ct); diff --git a/src-diclib/file_dic.c b/src-diclib/file_dic.c --- a/src-diclib/file_dic.c +++ b/src-diclib/file_dic.c @@ -182,7 +182,7 @@ parse_wtype_str(struct wt_stat *ws) wt_name = anthy_type_to_wtype(buf, &ws->wt); if (!wt_name) { - anthy_wtype_set_pos(&ws->wt, POS_INVAL); + ws->wt = anthy_wt_none; } ws->offset += len; return wt_name; @@ -260,7 +260,7 @@ add_dic_ent(struct seq_ent *seq, struct anthy_mem_dic_push_back_dic_ent(seq, xs, w, ws->wt_name, freq, id); if (anthy_wtype_get_meisi(w)) { /* 連用形が名詞化するやつは名詞化したものも追加 */ - anthy_wtype_set_ct(&w, CT_MEISIKA); + w = anthy_get_wtype_with_ct(w, CT_MEISIKA); anthy_mem_dic_push_back_dic_ent(seq, xs, w, ws->wt_name, freq, id); } anthy_free_xstr(xs); diff --git a/src-diclib/wtype.c b/src-diclib/wtype.c --- a/src-diclib/wtype.c +++ b/src-diclib/wtype.c @@ -79,21 +79,16 @@ const char * anthy_type_to_wtype(const char *s, wtype_t *t) { struct wttable *w; - t->pos = POS_INVAL; if (s[0] != '#') { + *t = anthy_wt_none; return NULL; } - *t = anthy_wt_all; w = get_table_by_name(s); if (!w) { + *t = anthy_wt_all; return NULL; } - t->cc = w->cc; - t->ct = w->ct; - t->pos = w->pos; - t->cos = w->cos; - t->scos = w->scos; - t->wf = w->flags; + *t = anthy_get_wtype(w->pos, w->cos, w->scos, w->cc, w->ct, w->flags); return w->name; } @@ -104,12 +99,7 @@ anthy_init_wtype_by_name(const char *nam p = get_pos_by_name(name); *w = anthy_wt_all; if (p) { - anthy_wtype_set_pos(w, p->pos); - anthy_wtype_set_ct(w, p->ct); - anthy_wtype_set_cc(w, p->cc); - anthy_wtype_set_cos(w, p->cos); - anthy_wtype_set_scos(w, p->scos); - w->wf = p->flags; + *w = anthy_get_wtype(p->pos, p->cos, p->scos, p->cc, p->ct, p->flags); return 0; } printf("Failed to find wtype(%s).\n", name); @@ -272,3 +262,29 @@ anthy_print_wtype(wtype_t w) anthy_wtype_get_ct(w), anthy_wtype_get_wf(w)); } + +wtype_t +anthy_get_wtype_with_ct(wtype_t base, int ct) +{ + wtype_t w; + + w = base; + w.ct = ct; + + return w; +} + +wtype_t +anthy_get_wtype(int pos, int cos, int scos, int cc, int ct, int wf) +{ + wtype_t w; + + w.pos = pos; + w.cos = cos; + w.scos = scos; + w.cc = cc; + w.ct = ct; + w.wf = wf; + + return w; +} diff --git a/src-splitter/compose.c b/src-splitter/compose.c --- a/src-splitter/compose.c +++ b/src-splitter/compose.c @@ -157,7 +157,7 @@ enum_candidates(struct seg_ent *seg, for (i = 0; i < p; i++) { wtype_t wt; anthy_get_nth_dic_ent_wtype(ce->elm[n].se, &ce->str, i, &wt); - anthy_wtype_set_ct(&ce->elm[n].wt, CT_NONE); + ce->elm[n].wt = anthy_get_wtype_with_ct(ce->elm[n].wt, CT_NONE); if (anthy_wtype_include(ce->elm[n].wt, wt)) { xstr word, yomi; yomi.len = ce->elm[n].str.len; diff --git a/src-splitter/depgraph.c b/src-splitter/depgraph.c --- a/src-splitter/depgraph.c +++ b/src-splitter/depgraph.c @@ -345,12 +345,7 @@ anthy_get_nth_dep_rule(int index, struct { /* ディスク上の情報からデータを取り出す */ struct ondisk_wordseq_rule *r = &fdep.rules[index]; - anthy_wtype_set_pos(&rule->wt, r->wt[0]); - anthy_wtype_set_cos(&rule->wt, r->wt[1]); - anthy_wtype_set_scos(&rule->wt, r->wt[2]); - anthy_wtype_set_cc(&rule->wt, r->wt[3]); - anthy_wtype_set_ct(&rule->wt, r->wt[4]); - rule->wt.wf = r->wt[5]; + rule->wt = anthy_get_wtype(r->wt[0], r->wt[1], r->wt[2], r->wt[3], r->wt[4], r->wt[5]); rule->ratio = ntohl(r->ratio); rule->node_id = ntohl(r->node_id); }