File: wtype.c

package info (click to toggle)
anthy 1%3A0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 23,596 kB
  • sloc: ansic: 24,444; sh: 4,186; lisp: 1,265; makefile: 238
file content (195 lines) | stat: -rw-r--r-- 3,996 bytes parent folder | download | duplicates (3)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * 品詞型を管理する
 * 中身はwtype_tの内部のレイアウトに強く依存する。
 *
 * Copyright (C) 2000-2007 TABATA Yusuke
 */
/*
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */
#include <stdio.h>
#include <string.h>

#include <anthy/wtype.h>
#include "dic_main.h"

wtype_t anthy_wt_none, anthy_wt_all;

wtype_t anthy_wtype_noun, anthy_wtype_num_noun;
wtype_t anthy_wtype_a_tail_of_v_renyou;

struct wttable {
  const char *name;
  int pos;
  int cos;
  int scos;
  int cc;
  int ct;/*カ変など*/
  int flags;
};

/* 辞書中の品詞の名前を品詞に変換するテーブル */
static struct wttable wt_name_tab[]= {
#include "wtab.h"
};

static wtype_t
anthy_get_wtype (int pos, int cos, int scos, int cc, int ct, int wf)
{
  union {
    unsigned int u;
    wtype_t wt;
  } w;

  w.u = 0;

  w.wt.pos = pos;
  w.wt.cos = cos;
  w.wt.scos = scos;
  w.wt.cc = cc;
  w.wt.ct = ct;
  w.wt.wf = wf;

  return w.wt;
}

static struct wttable *
find_wttab(struct wttable *array, const char *name)
{
  struct wttable *w;
  for (w = array; w->name; w++) {
    if (!strcmp(w->name, name)) {
      return w;
    }
  }
  return NULL;
}

void
anthy_init_wtypes(void)
{
  anthy_wt_all = anthy_get_wtype (POS_NONE, COS_NONE, SCOS_NONE,
				  CC_NONE, CT_NONE, WF_NONE);

  anthy_wt_none = anthy_get_wtype (POS_INVAL, COS_NONE, SCOS_NONE,
				   CC_NONE, CT_NONE, WF_NONE);

  /* {"名詞35",POS_NOUN,COS_NONE,SCOS_T35,CC_NONE,CT_NONE,WF_INDEP} */
  anthy_type_to_wtype ("#T", &anthy_wtype_noun);

  /* {"数詞",POS_NUMBER,COS_NN,SCOS_NONE,CC_NONE,CT_NONE,WF_INDEP} */
  anthy_type_to_wtype ("#NN", &anthy_wtype_num_noun); /* exported for ext_ent.c */

  /* {"形容詞化接尾語",POS_D2KY,COS_NONE,SCOS_A1,CC_NONE,CT_HEAD,WF_INDEP} */
  /* {"#D2KY",POS_D2KY,COS_SUFFIX,SCOS_A1,CC_A_KU,CT_HEAD,WF_INDEP} # "形容詞化接尾語(しづらい,がたい)" */
  anthy_type_to_wtype ("#D2KY", &anthy_wtype_a_tail_of_v_renyou); /* exported for metaword.c */
}

/*
 * 返り値には品詞の名前
 * tには品詞が返される
 */
const char *
anthy_type_to_wtype(const char *s, wtype_t *t)
{
  struct wttable *w;
  if (s[0] != '#') {
    *t = anthy_wt_none;
    return NULL;
  }
  w = find_wttab(wt_name_tab, s);
  if (!w) {
    *t = anthy_wt_all;
    return NULL;
  }
  *t = anthy_get_wtype(w->pos, w->cos, w->scos, w->cc, w->ct, w->flags);
  return w->name;
}

/* 二つの品詞が完全に一致しているかどうか */
int
anthy_wtype_equal(wtype_t lhs, wtype_t rhs)
{
  union {
    unsigned int u;
    wtype_t wt;
  } l, r;

  l.wt = lhs;
  r.wt = rhs;

  return (l.u == r.u);
}


int
anthy_wtype_get_cc(wtype_t t)
{
  return t.cc;
}

int
anthy_wtype_get_ct(wtype_t t)
{
  return t.ct;
}

int
anthy_wtype_get_pos(wtype_t t)
{
  return t.pos;
}

int
anthy_wtype_get_cos(wtype_t t)
{
  return t.cos;
}

int
anthy_wtype_get_scos(wtype_t t)
{
  return t.scos;
}

int
anthy_wtype_get_wf(wtype_t t)
{
  return t.wf;
}

int
anthy_wtype_get_indep(wtype_t t)
{
  return t.wf & WF_INDEP;
}

int
anthy_wtype_get_sv(wtype_t w)
{
  return w.wf & WF_SV;
}

void
anthy_print_wtype(wtype_t w)
{
  printf("(POS=%d,COS=%d,SCOS=%d,CC=%d,CT=%d,flags=%d)\n",
	 anthy_wtype_get_pos(w),
	 anthy_wtype_get_cos(w),
	 anthy_wtype_get_scos(w),
	 anthy_wtype_get_cc(w),
	 anthy_wtype_get_ct(w),
	 anthy_wtype_get_wf(w));
}