0
|
1 /*
|
|
2 * $Id: mknode0.c,v 1.4 2002/05/12 22:51:16 hiroo Exp $
|
|
3 */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
|
|
10 * 1987, 1988, 1989, 1990, 1991, 1992
|
|
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
|
|
13 * Copyright FreeWnn Project 1999, 2000, 2002
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
16 *
|
|
17 * This program is free software; you can redistribute it and/or modify
|
|
18 * it under the terms of the GNU General Public License as published by
|
|
19 * the Free Software Foundation; either version 2 of the License, or
|
|
20 * (at your option) any later version.
|
|
21 *
|
|
22 * This program is distributed in the hope that it will be useful,
|
|
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25 * GNU General Public License for more details.
|
|
26 *
|
|
27 * You should have received a copy of the GNU General Public License
|
|
28 * along with this program; if not, write to the Free Software
|
|
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
30 */
|
|
31 #ifdef HAVE_CONFIG_H
|
|
32 # include <config.h>
|
|
33 #endif
|
|
34
|
|
35 #include "commonhd.h"
|
|
36 #include "de_header.h"
|
|
37 #include "kaiseki.h"
|
|
38
|
|
39 static struct BZD *clrnd_sub ();
|
|
40 static void lnk_bzd (), lnk_ichbn ();
|
|
41 static int mknd_sub (), hyoka2 ();
|
|
42 void freebzd ();
|
|
43
|
|
44 static struct BZD *free_bzd_top = NULL;
|
|
45 static struct free_list *free_list_bzd = NULL;
|
|
46 static struct ICHBNP *free_ichbn_top = NULL;
|
|
47 static struct free_list *free_list_ichbn = NULL;
|
|
48
|
|
49 /************************************************/
|
|
50 /* initialize link struct BZD */
|
|
51 /************************************************/
|
|
52 int
|
|
53 init_bzd ()
|
|
54 {
|
|
55 free_area (free_list_bzd);
|
|
56 if (get_area (FIRST_BZD_KOSUU, sizeof (struct BZD), &free_list_bzd) < 0)
|
|
57 return (-1);
|
|
58 lnk_bzd (free_list_bzd);
|
|
59 return (0);
|
|
60 }
|
|
61
|
|
62 /* free_bzd が 0 でない時に呼んだらあかんよ */
|
|
63 static void
|
|
64 lnk_bzd (list)
|
|
65 struct free_list *list;
|
|
66 {
|
|
67 register int n;
|
|
68 register struct BZD *wk_ptr;
|
|
69
|
|
70 free_bzd_top = wk_ptr = (struct BZD *) ((char *) list + sizeof (struct free_list));
|
|
71
|
|
72 for (n = list->num - 1; n > 0; wk_ptr++, n--)
|
|
73 wk_ptr->lnk_son = wk_ptr + 1;
|
|
74 wk_ptr->lnk_son = 0;
|
|
75 }
|
|
76
|
|
77
|
|
78 /***********************************************/
|
|
79 /* initialize link struct ICHBNP */
|
|
80 /***********************************************/
|
|
81 int
|
|
82 init_ichbnp ()
|
|
83 {
|
|
84 free_area (free_list_ichbn);
|
|
85 if (get_area (FIRST_ICHBN_KOSUU, sizeof (struct ICHBNP), &free_list_ichbn) < 0)
|
|
86 return (-1);
|
|
87 lnk_ichbn (free_list_ichbn);
|
|
88 return (0);
|
|
89 }
|
|
90
|
|
91 /* free_ichbn が 0 でない時に呼んだらあかんよ */
|
|
92 static void
|
|
93 lnk_ichbn (list)
|
|
94 struct free_list *list;
|
|
95 {
|
|
96 register int n;
|
|
97 register struct ICHBNP *wk_ptr;
|
|
98
|
|
99 free_ichbn_top = wk_ptr = (struct ICHBNP *) ((char *) list + sizeof (struct free_list));
|
|
100
|
|
101 for (n = list->num - 1; n > 0; wk_ptr++, n--)
|
|
102 wk_ptr->next_p = wk_ptr + 1;
|
|
103 wk_ptr->next_p = 0;
|
|
104 }
|
|
105
|
|
106 /*********************************************************/
|
|
107 /* struct BZD & ICHBNP free area sakusei routine */
|
|
108 /*********************************************************/
|
|
109 void
|
|
110 clr_node (bzd)
|
|
111 register struct BZD *bzd; /*clear node top pointer */
|
|
112 {
|
|
113 register struct BZD *return_p; /*clrnd_sub return pointer */
|
|
114
|
|
115 return_p = clrnd_sub (bzd->lnk_son);
|
|
116 if (return_p != 0)
|
|
117 {
|
|
118 freebzd (return_p);
|
|
119 }
|
|
120 freebzd (bzd);
|
|
121 }
|
|
122
|
|
123 static struct BZD *
|
|
124 clrnd_sub (bzd)
|
|
125 register struct BZD *bzd; /* node pointer */
|
|
126 {
|
|
127 struct BZD *return_p; /* clrnd_sub return pointer */
|
|
128
|
|
129 if (bzd != 0)
|
|
130 {
|
|
131 return_p = clrnd_sub (bzd->lnk_son);
|
|
132 if (return_p != 0)
|
|
133 {
|
|
134 freebzd (return_p);
|
|
135 }
|
|
136 return_p = clrnd_sub (bzd->lnk_br);
|
|
137 if (return_p != 0)
|
|
138 freebzd (return_p);
|
|
139 return (bzd);
|
|
140 }
|
|
141 else
|
|
142 return (0);
|
|
143 }
|
|
144
|
|
145 void
|
|
146 freebzd (bzd) /* struct BZD o free_area e link */
|
|
147 register struct BZD *bzd; /* クリアするノードのポインタ */
|
|
148 {
|
|
149 bzd->lnk_son = free_bzd_top;
|
|
150 free_bzd_top = bzd;
|
|
151 clr_sbn_node (bzd->sbn);
|
|
152 }
|
|
153
|
|
154 void
|
|
155 freeibsp (ichbnp_p) /* struct ICHBNP o free_area e link */
|
|
156 struct ICHBNP *ichbnp_p; /* BZD ni link shiteiru ICHBNP eno pointer */
|
|
157 {
|
|
158 register struct ICHBNP *wk_ptr;
|
|
159
|
|
160 if (ichbnp_p == 0)
|
|
161 return;
|
|
162 for (wk_ptr = ichbnp_p; wk_ptr->next_p != 0; wk_ptr = wk_ptr->next_p)
|
|
163 ;
|
|
164 wk_ptr->next_p = free_ichbn_top;
|
|
165 free_ichbn_top = ichbnp_p;
|
|
166 }
|
|
167
|
|
168 /******************************************/
|
|
169 /* BZD area no kakutoku routine */
|
|
170 /******************************************/
|
|
171 struct BZD *
|
|
172 getbzdsp ()
|
|
173 {
|
|
174 register struct BZD *rtnptr;
|
|
175
|
|
176 if (free_bzd_top == 0)
|
|
177 {
|
|
178 if (get_area (BZD_KOSUU, sizeof (struct BZD), &free_list_bzd) < 0)
|
|
179 return ((struct BZD *) -1);
|
|
180 lnk_bzd (free_list_bzd);
|
|
181 }
|
|
182
|
|
183 rtnptr = free_bzd_top;
|
|
184 free_bzd_top = free_bzd_top->lnk_son;
|
|
185 rtnptr->lnk_br = 0;
|
|
186 rtnptr->lnk_son = 0;
|
|
187 rtnptr->son_v = 0;
|
|
188 return (rtnptr);
|
|
189 }
|
|
190
|
|
191 /******************************************/
|
|
192 /* ICHBNP area no kakutoku routine */
|
|
193 /******************************************/
|
|
194 struct ICHBNP *
|
|
195 getibsp ()
|
|
196 {
|
|
197 register struct ICHBNP *rtnptr;
|
|
198
|
|
199 if (free_ichbn_top == 0)
|
|
200 {
|
|
201 if (get_area (ICHBN_KOSUU, sizeof (struct ICHBNP), &free_list_ichbn) < 0)
|
|
202 return ((struct ICHBNP *) -1);
|
|
203 lnk_ichbn (free_list_ichbn);
|
|
204 }
|
|
205
|
|
206 rtnptr = free_ichbn_top;
|
|
207 free_ichbn_top = free_ichbn_top->next_p;
|
|
208 rtnptr->next_p = 0;
|
|
209 return (rtnptr);
|
|
210 }
|
|
211
|
|
212
|
|
213 /*******************************************/
|
|
214 /* ICHBNP table からのオフセットの取りだし */
|
|
215 /*******************************************/
|
|
216 struct fzkkouho *
|
|
217 getfzkoh_body (ichbnp_p, no)
|
|
218 register struct ICHBNP *ichbnp_p;
|
|
219 int no; /* table index 0 org */
|
|
220 {
|
|
221 register int cnt, no1;
|
|
222
|
|
223 no1 = no / FZKIBNO;
|
|
224 for (cnt = 0; cnt < no1; cnt++)
|
|
225 ichbnp_p = ichbnp_p->next_p;
|
|
226 return (&(ichbnp_p->fzkib[no % FZKIBNO]));
|
|
227 }
|
|
228
|
|
229 struct fzkkouho *
|
|
230 getfzkoh1_body (ichbnp_p, no)
|
|
231 register struct ICHBNP *ichbnp_p;
|
|
232 register int no; /* table index 0 org */
|
|
233 {
|
|
234 register int cnt, no1;
|
|
235
|
|
236 no1 = no / FZKIBNO;
|
|
237 for (cnt = 0; cnt < no1; cnt++)
|
|
238 ichbnp_p = ichbnp_p->next_p;
|
|
239 return (&(ichbnp_p->fzkib1[no % FZKIBNO]));
|
|
240 }
|
|
241
|
|
242
|
|
243 /*********************************************/
|
|
244 /* make_node routine */
|
|
245 /*********************************************/
|
|
246 int
|
|
247 #ifdef NO_FZK
|
|
248 mknode (ptr, yomi_eno, beginvect, endvect, mx_syo_bnst)
|
|
249 #else
|
|
250 mknode (ptr, yomi_eno, beginvect, fzkchar, endvect, mx_syo_bnst)
|
|
251 #endif /* NO_FZK */
|
|
252 struct BZD *ptr; /* struct BZD node top pointer */
|
|
253 int yomi_eno; /* kaiseki bunsyou end index (end char no tugi) */
|
|
254 int beginvect; /* 前端ベクタ(-1:文節先頭、-2:なんでも)品詞No. */
|
|
255 #ifndef NO_FZK
|
|
256 w_char *fzkchar;
|
|
257 #endif /* NO_FZK */
|
|
258 int endvect; /* shuutan vector */
|
|
259 int mx_syo_bnst; /* 解析を止める小文節の数 */
|
|
260 {
|
|
261 register int flg = 1; /* call or nocall value */
|
|
262
|
|
263 flg = mknd_sub (ptr, yomi_eno, beginvect,
|
|
264 #ifndef NO_FZK
|
|
265 fzkchar,
|
|
266 #endif /* NO_FZK */
|
|
267 endvect, flg, mx_syo_bnst);
|
|
268 switch (flg)
|
|
269 {
|
|
270 case 1:
|
|
271 ptr->kbcnt++; /* new_node ga tsukurareta toki */
|
|
272 return (1);
|
|
273 case 0:
|
|
274 return (0); /* new_node ga tsukurarenakatta toki */
|
|
275 default:
|
|
276 return (-1); /* free_area ga nakatta toki */
|
|
277 }
|
|
278 }
|
|
279
|
|
280 static int
|
|
281 #ifdef NO_FZK
|
|
282 mknd_sub (ptr, yomi_eno, beginvect, endvect, flg, mx_syo_bnst)
|
|
283 #else
|
|
284 mknd_sub (ptr, yomi_eno, beginvect, fzkchar, endvect, flg, mx_syo_bnst)
|
|
285 #endif /* NO_FZK */
|
|
286 struct BZD *ptr; /* struct BZD node pointer */
|
|
287 int yomi_eno; /* kaiseki bunsyou end index (end char no tugi) */
|
|
288 int beginvect; /* 前端ベクタ(-1:文節先頭、-2:なんでも)品詞No. */
|
|
289 #ifndef NO_FZK
|
|
290 w_char *fzkchar;
|
|
291 #endif /* NO_FZK */
|
|
292 int endvect; /* shuutan vector */
|
|
293 int flg; /* call or nocall value */
|
|
294 int mx_syo_bnst; /* 解析を止める小文節の数 */
|
|
295 {
|
|
296 register int keep_v; /* max 評価値 */
|
|
297 register struct BZD *wk_ptr; /* work pointer */
|
|
298
|
|
299 if (ptr->lnk_son != 0)
|
|
300 {
|
|
301 for (wk_ptr = ptr->lnk_son, keep_v = 0; wk_ptr != 0; wk_ptr = wk_ptr->lnk_br)
|
|
302 {
|
|
303 switch (mknd_sub (wk_ptr, yomi_eno, beginvect,
|
|
304 #ifndef NO_FZK
|
|
305 fzkchar,
|
|
306 #endif /* NO_FZK */
|
|
307 endvect, flg, mx_syo_bnst))
|
|
308 {
|
|
309 case 1:
|
|
310 if (flg == 1)
|
|
311 { /* 解析文節数 */
|
|
312 wk_ptr->kbcnt++;
|
|
313 /* brothers max hyoka value */
|
|
314 if (wk_ptr->son_v > keep_v)
|
|
315 keep_v = wk_ptr->son_v;
|
|
316 wk_ptr->son_v /= wk_ptr->kbcnt;
|
|
317 }
|
|
318 break;
|
|
319 case 0:
|
|
320 if (flg == 1)
|
|
321 {
|
|
322 keep_v = wk_ptr->son_v;
|
|
323 flg = 0;
|
|
324 }
|
|
325 else
|
|
326 { /* brothers max hyoka value */
|
|
327 if (wk_ptr->son_v > keep_v)
|
|
328 keep_v = wk_ptr->son_v;
|
|
329 }
|
|
330 wk_ptr->son_v += wk_ptr->v_jc;
|
|
331 break;
|
|
332 default:
|
|
333 return (-1);
|
|
334 }
|
|
335 }
|
|
336 if (keep_v != 0)
|
|
337 ptr->son_v = hyoka2 (keep_v, ptr->v_jc);
|
|
338 return (flg);
|
|
339 }
|
|
340 else
|
|
341 {
|
|
342 if (ptr->j_c + 1 < yomi_eno)
|
|
343 {
|
|
344 if (flg == 1)
|
|
345 { /* make new node */
|
|
346 if (dbn_kai (ptr->j_c + 1, yomi_eno, beginvect,
|
|
347 #ifndef NO_FZK
|
|
348 fzkchar,
|
|
349 #endif /* NO_FZK */
|
|
350 endvect, WNN_VECT_NO, mx_syo_bnst, &(ptr->lnk_son)) < 0)
|
|
351 return (-1); /* ERROR */
|
|
352 for (wk_ptr = ptr->lnk_son, keep_v = 0; wk_ptr != 0; wk_ptr = wk_ptr->lnk_br)
|
|
353 {
|
|
354 if (wk_ptr->v_jc > keep_v)
|
|
355 keep_v = wk_ptr->v_jc;
|
|
356 /* brothers max hyoka value */
|
|
357 }
|
|
358 ptr->son_v = hyoka2 (keep_v, ptr->v_jc);
|
|
359 }
|
|
360 return (1); /* make flg */
|
|
361 }
|
|
362 else
|
|
363 return (0); /* no make flg */
|
|
364 }
|
|
365 }
|
|
366
|
|
367 /********************************************/
|
|
368 /* bunsetsu hyoka kansuu */
|
|
369 /********************************************/
|
|
370 static int
|
|
371 hyoka2 (max_v, par_v)
|
|
372 int max_v; /* brothers max hyoka value */
|
|
373 int par_v; /* parent hyoka value */
|
|
374 {
|
|
375 return ((max_v + par_v));
|
|
376 }
|