0
|
1 /*
|
|
2 * $Id: jikouho_d.c,v 1.6 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
|
|
32 /************************************************
|
|
33 * 大文節次候補取りだし *
|
|
34 ************************************************/
|
|
35 #ifdef HAVE_CONFIG_H
|
|
36 # include <config.h>
|
|
37 #endif
|
|
38
|
|
39 #include <stdio.h>
|
|
40 #include <ctype.h>
|
|
41 #if STDC_HEADERS
|
|
42 # include <stdlib.h>
|
|
43 #else
|
|
44 # if HAVE_MALLOC_H
|
|
45 # include <malloc.h>
|
|
46 # endif
|
|
47 #endif /* STDC_HEADERS */
|
|
48
|
|
49 #include "commonhd.h"
|
|
50 #include "de_header.h"
|
|
51 #include "jdata.h"
|
|
52 #include "fzk.h"
|
|
53 #include "kaiseki.h"
|
|
54
|
|
55 #ifdef CONVERT_from_TOP
|
|
56 static void sbn_set (), sons_set ();
|
|
57 #endif /* CONVERT_from_TOP */
|
|
58
|
|
59 static void dsd_hyouka (), cnt_sbn (), cnt_dbn ();
|
|
60 static int cmp_dsd_dbn (), jkt_dbn (), jkt_sbjunjo (), set_jkt_dai (), zen_sbn (), cnt_par (), cnt_son ();
|
|
61 static struct JKT_SBN *jkt_que_reorder ();
|
|
62
|
|
63 static int yomi_sno_tmp;
|
|
64
|
|
65 /*
|
|
66 * jkt_get_dai : 次候補 all 取りだし (大文節)
|
|
67 */
|
|
68 int
|
|
69 #ifdef NO_FZK
|
|
70 jkt_get_dai (yomi_sno, yomi_eno, beginvect, endvect, endvect1, nmax, dsd_dbn)
|
|
71 #else
|
|
72 jkt_get_dai (yomi_sno, yomi_eno, beginvect, fzkchar, endvect, endvect1, nmax, dsd_dbn)
|
|
73 #endif /* NO_FZK */
|
|
74 int yomi_sno;
|
|
75 int yomi_eno;
|
|
76 int beginvect; /* 前端ベクタ(-1:文節先頭、-2:なんでも)品詞No. */
|
|
77 #ifndef NO_FZK
|
|
78 w_char *fzkchar;
|
|
79 #endif /* NO_FZK */
|
|
80 int endvect; /* 終端ベクタ */
|
|
81 int endvect1; /* 終端ベクタ */
|
|
82 int nmax; /* 1大文節中の最大小文節数 */
|
|
83 struct DSD_DBN **dsd_dbn;
|
|
84 {
|
|
85 register int i;
|
|
86 register int cnt;
|
|
87 struct JKT_DBN *rjkt_dbn = 0;
|
|
88 register struct DSD_DBN *dbn;
|
|
89 int divid;
|
|
90
|
|
91 if (c_env->fzk_fid == -1)
|
|
92 {
|
|
93 wnn_errorno = WNN_FZK_FILE_NO_LOAD;
|
|
94 return (-1);
|
|
95 }
|
|
96 ft = (struct FT *) files[c_env->fzk_fid].area;
|
|
97 if ((cnt = jkt_dbn (yomi_sno, yomi_eno, beginvect,
|
|
98 #ifndef NO_FZK
|
|
99 fzkchar,
|
|
100 #endif /* NO_FZK */
|
|
101 endvect, endvect1, nmax, &rjkt_dbn)) < 0)
|
|
102 {
|
|
103 init_work_areas ();
|
|
104 return (-1);
|
|
105 }
|
|
106 if ((cnt = dbn_set (dsd_dbn, rjkt_dbn)) < 0)
|
|
107 {
|
|
108 init_work_areas ();
|
|
109 return (-1);
|
|
110 }
|
|
111 for (dbn = *dsd_dbn, i = cnt; i > 0; i--, dbn++)
|
|
112 {
|
|
113 dsd_hyouka (dbn);
|
|
114 if ((divid = get_jkt_status (dbn->sbn->kangovect, beginvect,
|
|
115 #ifndef NO_FZK
|
|
116 fzkchar,
|
|
117 #endif /* NO_FZK */
|
|
118 &(dbn->sbn->status))) != 0)
|
|
119 dbn->v_jc = DIVID_HYOUKA (dbn->v_jc, divid);
|
|
120 }
|
|
121 /* SORT */
|
|
122 qsort ((char *) *dsd_dbn, cnt, sizeof (struct DSD_DBN), cmp_dsd_dbn);
|
|
123 return (cnt);
|
|
124 }
|
|
125
|
|
126 static int
|
|
127 cmp_dsd_dbn (dbn1, dbn2)
|
|
128 struct DSD_DBN *dbn1;
|
|
129 struct DSD_DBN *dbn2;
|
|
130 {
|
|
131 return (dbn2->v_jc - dbn1->v_jc);
|
|
132 }
|
|
133
|
|
134 static void
|
|
135 dsd_hyouka (dbn)
|
|
136 struct DSD_DBN *dbn;
|
|
137 {
|
|
138 struct DSD_SBN *sbn;
|
|
139 int len; /* 大文節長 */
|
|
140 int son_v = 0;
|
|
141 register int j_c;
|
|
142 register struct DSD_SBN *s_p;
|
|
143 int i;
|
|
144
|
|
145 sbn = dbn->sbn;
|
|
146 j_c = sbn->bun_jc;
|
|
147 len = j_c - dbn->bun_m + 1;
|
|
148
|
|
149 for (i = 0, s_p = sbn; i < dbn->sbncnt; s_p++, i++)
|
|
150 {
|
|
151 son_v += s_p->v_jc;
|
|
152 }
|
|
153
|
|
154 dbn->v_jc = hyoka_dbn (son_v, dbn->sbncnt, len);
|
|
155 }
|
|
156
|
|
157 /*******************/
|
|
158
|
|
159 static int
|
|
160 #ifdef NO_FZK
|
2
|
161 jkt_dbn (int yomi_sno, int yomi_eno, int beginvect, int endvect,
|
|
162 int endvect1, int nmax, struct JKT_DBN **rjkt_dbn)
|
0
|
163 #else
|
2
|
164 jkt_dbn (int yomi_sno, int yomi_eno, int beginvect, w_char *fzkchar, int endvect,
|
|
165 int endvect1, int nmax, struct JKT_DBN **rjkt_dbn)
|
0
|
166 #endif /* NO_FZK */
|
2
|
167
|
|
168 #if 0
|
0
|
169 int yomi_sno;
|
|
170 int yomi_eno;
|
|
171 int beginvect; /* 前端ベクタ(-1:文節先頭、-2:なんでも)品詞No. */
|
|
172 #ifndef NO_FZK
|
|
173 w_char *fzkchar;
|
|
174 #endif /* NO_FZK */
|
|
175 int endvect; /* 終端ベクタ */
|
|
176 int endvect1; /* 終端ベクタ */
|
|
177 register int nmax; /* 1大文節中の最大小文節数 */
|
|
178 struct JKT_DBN **rjkt_dbn; /* 次候補解析結果 */
|
2
|
179 #endif
|
|
180
|
0
|
181 {
|
|
182 register struct JKT_SBN **sb_que_head; /* 小文節解析結果 */
|
|
183 int tmp; /* 次候補ベクター数 */
|
|
184 struct JKT_SBN *db_tmp;
|
|
185 register struct JKT_SBN *sb_one;
|
|
186 struct JKT_SBN *sbn_tmp;
|
|
187 register struct JKT_SBN **sb_que_newcomer;
|
|
188 struct JKT_DBN *jktdbn = 0;
|
|
189 int dbncnt = 0;
|
|
190 #ifndef NO_KANA
|
|
191 int gijiflag = 0; /* 疑似文節を作ったか:最初の小文節のみ */
|
|
192 #endif /* NO_KANA */
|
|
193
|
|
194 yomi_sno_tmp = yomi_sno;
|
|
195
|
|
196 sb_que_head = &db_tmp;
|
|
197 *sb_que_head = NULL;
|
|
198
|
2
|
199 if ((tmp = zen_sbn (yomi_sno, yomi_eno, endvect, endvect1, sb_que_head, 1, NULL
|
0
|
200 #ifndef NO_KANA
|
|
201 , &gijiflag
|
|
202 #endif /* NO_KANA */
|
|
203 )) <= 0)
|
|
204 return (tmp);
|
|
205
|
|
206 while (*sb_que_head != NULL)
|
|
207 {
|
|
208 sb_one = *sb_que_head;
|
|
209 *sb_que_head = sb_one->lnk_br;
|
|
210 if (nmax > sb_one->kbcnt && yomi_eno > sb_one->j_c + 1)
|
|
211 {
|
|
212 sb_que_newcomer = &sbn_tmp;
|
|
213 *sb_que_newcomer = NULL;
|
|
214 tmp = zen_sbn (sb_one->j_c + 1, yomi_eno, sb_one->kangovect, WNN_VECT_NO, sb_que_newcomer, sb_one->kbcnt + 1, sb_one
|
|
215 #ifndef NO_KANA
|
2
|
216 , NULL
|
0
|
217 #endif /* NO_KANA */
|
|
218 );
|
|
219 if (tmp < 0)
|
|
220 {
|
|
221 return (-1); /* ERROR */
|
|
222 }
|
|
223 else if (tmp > 0)
|
|
224 {
|
|
225 sb_one->reference += tmp;
|
|
226 if (*sb_que_head != 0)
|
|
227 *sb_que_head = jkt_que_reorder (*sb_que_head, *sb_que_newcomer);
|
|
228 else
|
|
229 *sb_que_head = *sb_que_newcomer;
|
|
230 }
|
|
231 else
|
|
232 {
|
|
233 freejktsbn (sb_one);
|
|
234 }
|
|
235 }
|
|
236 else if (yomi_eno == sb_one->j_c + 1)
|
|
237 {
|
|
238 if (set_jkt_dai (rjkt_dbn, &jktdbn, sb_one) < 0)
|
|
239 return (-1);
|
|
240 dbncnt++;
|
|
241 }
|
|
242 }
|
|
243 #ifndef NO_KANA
|
|
244 /* ひらがな候補 */
|
|
245 if (gijiflag == 0)
|
|
246 {
|
|
247 if ((sb_one = get_hira_kouho (&db_tmp, yomi_sno, yomi_eno)) < (struct JKT_SBN *) 0)
|
|
248 return (-1);
|
|
249
|
|
250 if (sb_one > (struct JKT_SBN *) 0)
|
|
251 {
|
|
252 sb_one->parent = 0;
|
|
253 sb_one->bend_m = yomi_sno;
|
|
254 sb_one->kbcnt = 1;
|
|
255 if (set_jkt_dai (rjkt_dbn, &jktdbn, sb_one) < 0)
|
|
256 return (-1);
|
|
257 dbncnt++;
|
|
258 }
|
|
259 }
|
|
260 #endif /* NO_KANA */
|
|
261
|
|
262 return (dbncnt);
|
|
263 }
|
|
264
|
|
265 /* 前(beginvect,fzkchar)と接続できるか調べ、
|
|
266 接続できるとき 1
|
|
267 大文節の先頭の時 0
|
|
268 接続できないとき -1
|
|
269 を返す
|
|
270 get_status 参照
|
|
271 */
|
|
272
|
|
273 int
|
|
274 #ifdef NO_FZK
|
|
275 get_jkt_status (kangovect, beginvect, status)
|
|
276 #else
|
|
277 get_jkt_status (kangovect, beginvect, fzkchar, status)
|
|
278 #endif /* NO_FZK */
|
|
279 int kangovect;
|
|
280 int beginvect;
|
|
281 #ifndef NO_FZK
|
|
282 w_char *fzkchar;
|
|
283 #endif /* NO_FZK */
|
|
284 short *status;
|
|
285 {
|
|
286 extern int _status;
|
|
287 _status = 0;
|
|
288 return (get_status (kangovect, beginvect,
|
|
289 #ifndef NO_FZK
|
|
290 fzkchar,
|
|
291 #endif /* NO_FZK */
|
|
292 status));
|
|
293 }
|
|
294
|
|
295 /*
|
|
296 int
|
|
297 get_dsd_status(kangovect, beginvect, fzkchar, status)
|
|
298 int kangovect;
|
|
299 int beginvect;
|
|
300 w_char *fzkchar;
|
|
301 int *status;
|
|
302 {
|
|
303 if (zentan_able(kangovect, beginvect, fzkchar) == YES) {
|
|
304 if (beginvect == WNN_ALL_HINSI) {
|
|
305 if (kan_ckvt(sentou_no, kangovect) == WNN_CONNECT_BK) {
|
|
306 *status = WNN_SENTOU;
|
|
307 } else {
|
|
308 *status = WNN_NOT_CONNECT;
|
|
309 return (-1);
|
|
310 }
|
|
311 } else if (beginvect == WNN_BUN_SENTOU) {
|
|
312 *status = WNN_SENTOU;
|
|
313 } else {
|
|
314 if ((fzkchar == NULL || *fzkchar == NULL) && beginvect == sentou_no)
|
|
315 *status = WNN_SENTOU;
|
|
316 else
|
|
317 *status = WNN_CONNECT;
|
|
318 return (1);
|
|
319 }
|
|
320 } else if (kan_ckvt(sentou_no, kangovect) == WNN_CONNECT_BK) {
|
|
321 sb_one->status = WNN_SENTOU;
|
|
322 } else {
|
|
323 *status = WNN_NOT_CONNECT;
|
|
324 return (-1);
|
|
325 }
|
|
326 return(0);
|
|
327 }
|
|
328 */
|
|
329
|
|
330 /* 小文節の並び替え 長さとベクタでソートする */
|
|
331 /* que の先頭を返す */
|
|
332 static struct JKT_SBN *
|
|
333 jkt_que_reorder (que, new)
|
|
334 register struct JKT_SBN *que, *new;
|
|
335 {
|
|
336 struct JKT_SBN *que_sv;
|
|
337 register struct JKT_SBN *tmp;
|
|
338 register struct JKT_SBN *next;
|
|
339
|
2
|
340 if (new == NULL)
|
0
|
341 return (que);
|
|
342 if (jkt_sbjunjo (que, new) < 0)
|
|
343 {
|
|
344 que_sv = new;
|
|
345 }
|
|
346 else
|
|
347 que_sv = que;
|
|
348
|
|
349 while (new != NULL)
|
|
350 {
|
|
351 next = new->lnk_br;
|
|
352 if (jkt_sbjunjo (que, new) < 0)
|
|
353 {
|
|
354 /* NEW が前 */
|
|
355 tmp = que;
|
|
356 que = new;
|
|
357 que->lnk_br = tmp;
|
|
358 new = next;
|
|
359 continue;
|
|
360 }
|
|
361 /* QUE が前 */
|
|
362 while ((jkt_sbjunjo (que, new) > 0) && que->lnk_br != NULL)
|
|
363 que = (que->lnk_br);
|
|
364 tmp = que->lnk_br;
|
|
365 /* QUE の後にNEW */
|
|
366 que->lnk_br = new;
|
|
367 new->lnk_br = tmp;
|
|
368 new = next;
|
|
369 }
|
|
370 return (que_sv);
|
|
371 }
|
|
372
|
|
373 /* que と new の順序
|
|
374 1: que が前
|
|
375 0: que の後に new
|
|
376 -1:new が前
|
|
377 XXXXX -2:同一順位 */
|
|
378 static int
|
|
379 jkt_sbjunjo (que, new)
|
|
380 struct JKT_SBN *que, *new;
|
|
381 {
|
2
|
382 if (new == NULL)
|
0
|
383 return (1);
|
|
384 if (que->j_c > new->j_c)
|
|
385 return (-1);
|
|
386 if (que->j_c < new->j_c)
|
|
387 {
|
2
|
388 if (que->lnk_br == NULL)
|
0
|
389 return (0);
|
|
390 if (que->lnk_br->j_c > new->j_c)
|
|
391 return (0);
|
|
392 if (que->lnk_br->j_c < new->j_c)
|
|
393 return (1);
|
|
394 if (que->lnk_br->kangovect > new->kangovect)
|
|
395 return (0);
|
|
396 return (1);
|
|
397 }
|
|
398 if (que->kangovect == new->kangovect)
|
|
399 return (0); /* return (-2); */
|
|
400 if (que->kangovect > new->kangovect)
|
|
401 return (-1);
|
2
|
402 if (que->lnk_br == NULL)
|
0
|
403 return (0);
|
|
404 if (que->lnk_br->j_c > new->j_c)
|
|
405 return (0);
|
|
406 if (que->lnk_br->kangovect > new->kangovect)
|
|
407 return (0);
|
|
408 return (1);
|
|
409 }
|
|
410
|
|
411
|
|
412 /* 文節の先頭になれれば、大文節の候補をセットする */
|
|
413 static int
|
|
414 set_jkt_dai (rjkt_dbn, jktdbn, sbn)
|
|
415 struct JKT_DBN **rjkt_dbn;
|
|
416 register struct JKT_DBN **jktdbn;
|
|
417 register struct JKT_SBN *sbn;
|
|
418 {
|
|
419 struct JKT_DBN *getjktdbn ();
|
|
420
|
|
421 if (*jktdbn != 0)
|
|
422 {
|
2
|
423 if (((*jktdbn)->lnk_br = getjktdbn ()) == NULL)
|
0
|
424 return (-1);
|
|
425 (*jktdbn) = (*jktdbn)->lnk_br;
|
|
426 }
|
|
427 else
|
|
428 {
|
2
|
429 if ((*rjkt_dbn = *jktdbn = getjktdbn ()) == NULL)
|
0
|
430 return (-1);
|
|
431 }
|
|
432 (*jktdbn)->j_c = sbn->j_c;
|
|
433 (*jktdbn)->sbn_cnt = sbn->kbcnt;
|
|
434 (*jktdbn)->lnk_br = 0;
|
|
435 (*jktdbn)->sbn = sbn;
|
|
436 (*jktdbn)->bend_m = yomi_sno_tmp;
|
|
437 return (0);
|
|
438 }
|
|
439
|
|
440 static int
|
2
|
441 zen_sbn (int yomi_sno, int yomi_eno, int endvect, int endvect1, struct JKT_SBN **tjktsbn,
|
|
442 int bnst_num, struct JKT_SBN *parent
|
0
|
443 #ifndef NO_KANA
|
2
|
444 , int *gijiflagp
|
0
|
445 #endif /* NO_KANA */
|
|
446 )
|
2
|
447
|
|
448 #if 0
|
0
|
449 int yomi_sno;
|
|
450 int yomi_eno;
|
|
451 int endvect; /* 終端ベクタ */
|
|
452 int endvect1; /* 終端ベクタ */
|
|
453 struct JKT_SBN **tjktsbn; /* 小文節解析結果 */
|
|
454 int bnst_num; /* これまでに解析した小文節数 */
|
|
455 struct JKT_SBN *parent; /* 親の幹語ノード */
|
|
456 #ifndef NO_KANA
|
|
457 int *gijiflagp;
|
|
458 #endif /* NO_KANA */
|
2
|
459 #endif
|
|
460
|
0
|
461 {
|
|
462 register int fzkcnt, ii, jktcnt;
|
|
463 register int i, /* 幹語の終わりのインデックス */
|
|
464 j; /* 文節始めのインデックス */
|
|
465 struct JKT_SBN *jktsbn_top = 0;
|
|
466 struct ICHBNP *ichbnpbp;
|
|
467 struct JKT_SBN *gijisbn_top;
|
|
468 int get_giji_flg = -1; /* 擬似文節を作れたか */
|
|
469 int cnt;
|
|
470 #ifndef NO_KANA
|
|
471 struct JKT_SBN *jktsbn;
|
|
472 int index_tmp;
|
|
473 struct fzkkouho *fzkptr;
|
|
474 int *vector1;
|
|
475 #endif
|
|
476
|
|
477 #ifndef NO_KATA
|
|
478 struct JKT_SBN *get_kata_kouho ();
|
|
479 #endif
|
|
480 struct JKT_SBN *get_hira_kouho ();
|
|
481 struct SYO_BNSETSU *giji_sbn;
|
|
482 struct SYO_BNSETSU *getsbnsp ();
|
|
483
|
|
484 if (yomi_sno == yomi_eno)
|
|
485 return (NOTHING);
|
|
486
|
|
487 if (fzk_ckvt (endvect) == NO && fzk_ckvt (endvect1) == NO)
|
|
488 return (NOTHING);
|
|
489 fzkcnt = fzk_kai (&bun[yomi_sno], &bun[yomi_eno], endvect, endvect1, &ichbnpbp);
|
|
490 if (fzkcnt <= 0)
|
|
491 return (fzkcnt); /* ERROR */
|
|
492 for (ii = 0; ii < fzkcnt; ii++)
|
|
493 getfzkoh (ichbnpbp, ii)->offset += yomi_sno;
|
|
494
|
|
495
|
|
496 for (ii = 0; ii < fzkcnt; ii++)
|
|
497 {
|
|
498 i = getfzkoh (ichbnpbp, ii)->offset;
|
|
499 if (jmtp[i] == (struct jdata **) UN_KNOWN) /* もう引いた? */
|
|
500 jmt_set (i); /* 辞書引き */
|
|
501 }
|
|
502
|
|
503 j = j_max (ichbnpbp, fzkcnt);
|
|
504 j = (j >= yomi_eno) ? yomi_eno - 1 : j;
|
|
505
|
|
506 jktcnt = 0;
|
|
507
|
|
508 #if !defined(NO_KANA) && !defined(KOREAN)
|
|
509 /* カタカナ疑似文節を取り出します */
|
2
|
510 if (gijiflagp != NULL && j < yomi_eno - 1)
|
0
|
511 {
|
|
512 for (ii = 0; ii < fzkcnt; ii++)
|
|
513 { /* 付属語 */
|
|
514 fzkptr = getfzkoh (ichbnpbp, ii);
|
|
515 if (bnst_num == 1)
|
|
516 vector1 = getfzkoh1 (ichbnpbp, ii)->vector;
|
|
517 else
|
|
518 vector1 = fzkptr->vector;
|
|
519 index_tmp = fzkptr->offset;
|
|
520 if ((jktsbn = get_kata_kouho (&jktsbn_top, yomi_sno, yomi_eno, fzkptr->offset, fzkptr->vector, vector1, ii)) < (struct JKT_SBN *) 0)
|
|
521
|
|
522 return (-1);
|
|
523 if (jktsbn > (struct JKT_SBN *) 0)
|
|
524 {
|
|
525 jktsbn->parent = parent;
|
|
526 jktsbn->bend_m = yomi_sno;
|
|
527 jktsbn->kbcnt = bnst_num;
|
|
528 jktcnt++;
|
|
529 }
|
|
530 } /* 付属語 */
|
|
531 }
|
|
532 #endif /* !defined(NO_KANA) && !defined(KOREAN) */
|
|
533 if ((giji_sbn = getsbnsp ()) == NO)
|
|
534 return (-1);
|
|
535 gijisbn_top = 0;
|
|
536 giji_sbn->bend_m = yomi_sno;
|
|
537 if (getgiji (yomi_sno, yomi_eno, giji_sbn, ichbnpbp, fzkcnt, bnst_num) >= 0)
|
|
538 {
|
|
539 if (giji_sbn->hinsi_fk != katakanago_no && giji_sbn->hinsi_fk != giji_no && giji_sbn->hinsi_fk != fuzokugo_no)
|
|
540 {
|
|
541 if (get_zen_giji (giji_sbn, &gijisbn_top) < 0)
|
|
542 return (-1);
|
|
543 gijisbn_top->parent = parent;
|
|
544 gijisbn_top->kbcnt = bnst_num;
|
|
545 get_giji_flg = giji_sbn->j_c;
|
|
546 #ifndef NO_KANA
|
2
|
547 if (gijiflagp != NULL && giji_sbn->j_c == yomi_eno - 1)
|
0
|
548 *gijiflagp = 1;
|
|
549 #endif /* NO_KANA */
|
|
550 jktcnt++;
|
|
551 }
|
|
552 }
|
|
553 freesbn (giji_sbn);
|
|
554
|
|
555 if (gijisbn_top != 0)
|
|
556 {
|
|
557 if (get_giji_flg > j)
|
|
558 {
|
|
559 gijisbn_top->lnk_br = jktsbn_top;
|
|
560 jktsbn_top = gijisbn_top;
|
|
561 get_giji_flg = -1;
|
|
562 }
|
|
563 }
|
|
564
|
|
565 for (; j >= yomi_sno; j--)
|
|
566 {
|
|
567 /* 文節の長さ */
|
|
568 if (get_giji_flg == j)
|
|
569 {
|
|
570 gijisbn_top->lnk_br = jktsbn_top;
|
|
571 jktsbn_top = gijisbn_top;
|
|
572 get_giji_flg = -1;
|
|
573 }
|
|
574 if ((cnt = jkt_sbn_one (yomi_sno, j + 1, &jktsbn_top, bnst_num, parent, ichbnpbp, fzkcnt)) < 0)
|
|
575 return (-1);
|
|
576 jktcnt += cnt;
|
|
577
|
|
578 }
|
|
579 *tjktsbn = jktsbn_top; /* 短いものから並べる */
|
|
580 freeibsp (ichbnpbp);
|
|
581 return (jktcnt);
|
|
582 }
|
|
583
|
|
584 struct DSD_DBN *
|
|
585 get_dsd_dbn (cnt)
|
|
586 register int cnt;
|
|
587 {
|
|
588 static struct DSD_DBN *m_dbn = 0;
|
|
589 static int md_cnt = 0;
|
|
590
|
|
591 if (md_cnt < cnt)
|
|
592 {
|
|
593 /* どんどんふくれる Jserver */
|
|
594 if (m_dbn)
|
|
595 free (m_dbn);
|
|
596 m_dbn = (struct DSD_DBN *) malloc (cnt * sizeof (struct DSD_DBN));
|
|
597 if (m_dbn == NULL)
|
|
598 {
|
|
599 /* 大きくなって天まで届け! */
|
|
600 wnn_errorno = WNN_JKTAREA_FULL;
|
|
601 error1 ("malloc err in dbn_set (at daibnsetsu jikouho).\n");
|
|
602 md_cnt = 0;
|
3
|
603 return NULL;
|
0
|
604 }
|
|
605 else
|
|
606 md_cnt = cnt;
|
|
607 }
|
|
608 return (m_dbn);
|
|
609 }
|
|
610
|
|
611 struct DSD_SBN *
|
|
612 get_dsd_sbn (cnt)
|
|
613 register int cnt;
|
|
614 {
|
|
615 static struct DSD_SBN *m_sbn = 0;
|
|
616 static int ms_cnt = 0;
|
|
617
|
|
618 if (ms_cnt < cnt)
|
|
619 {
|
|
620 if (m_sbn)
|
|
621 free (m_sbn);
|
|
622 m_sbn = (struct DSD_SBN *) malloc (cnt * sizeof (struct DSD_SBN));
|
|
623 if (m_sbn == NULL)
|
|
624 {
|
|
625 wnn_errorno = WNN_JKTAREA_FULL;
|
|
626 error1 ("malloc err in dbn_set (at daibnsetsu jikouho).\n");
|
|
627 ms_cnt = 0;
|
3
|
628 return NULL;
|
0
|
629 }
|
|
630 else
|
|
631 ms_cnt = cnt;
|
|
632 }
|
|
633 return (m_sbn);
|
|
634 }
|
|
635
|
|
636 int
|
|
637 dbn_set (dsd_dbn, dbn)
|
|
638 struct DSD_DBN **dsd_dbn;
|
|
639 register struct JKT_DBN *dbn;
|
|
640 {
|
|
641 register struct JKT_SBN *sbn;
|
|
642 register struct JKT_SONE *sone;
|
|
643 int i;
|
|
644 #ifndef CONVERT_from_TOP
|
|
645 int j, son, par;
|
|
646 #endif
|
|
647 struct JKT_DBN *next_dbn;
|
|
648
|
|
649 int cnt;
|
|
650 int dbn_cnt;
|
|
651 int sbn_cnt;
|
|
652 struct DSD_DBN *d_dbn;
|
|
653 struct DSD_SBN *d_sbn;
|
|
654 register struct DSD_SBN *p_sbn;
|
|
655 struct DSD_SBN *sv_sbn;
|
|
656
|
|
657 cnt_dbn (dbn, &cnt, &sbn_cnt);
|
|
658
|
3
|
659 if ( (d_dbn = *dsd_dbn = get_dsd_dbn (cnt)) == NULL)
|
0
|
660 return (-1);
|
3
|
661 if ( (sv_sbn = d_sbn = get_dsd_sbn (sbn_cnt)) == NULL)
|
0
|
662 return (-1);
|
|
663
|
|
664 while (dbn)
|
|
665 {
|
|
666 sbn = dbn->sbn;
|
|
667 cnt_sbn (sbn, &dbn_cnt, &sbn_cnt);
|
|
668 p_sbn = d_sbn = sv_sbn;
|
|
669 sv_sbn += sbn_cnt;
|
|
670 for (i = 0; i < dbn_cnt; i++)
|
|
671 {
|
|
672 d_dbn->bun_m = dbn->bend_m;
|
|
673 d_dbn->bun_jc = dbn->j_c;
|
|
674 d_dbn->sbncnt = dbn->sbn_cnt;
|
|
675 d_dbn->sbn = p_sbn;
|
|
676 p_sbn += dbn->sbn_cnt;
|
|
677 d_dbn++;
|
|
678 }
|
|
679 #ifdef CONVERT_from_TOP
|
|
680 sbn_set (dbn, &d_sbn, sone, dbn->sbn);
|
|
681
|
|
682 next_dbn = dbn->lnk_br;
|
|
683 freejktdbn (dbn);
|
|
684 dbn = next_dbn;
|
|
685 #else /* CONVERT_from_TOP */
|
|
686 for (sbn = dbn->sbn; sbn != 0; sbn = sbn->parent, d_sbn++)
|
|
687 {
|
|
688 son = cnt_son (dbn->sbn, sbn);
|
|
689 par = cnt_par (sbn);
|
|
690 p_sbn = d_sbn;
|
|
691 for (j = 0; j < son; j++)
|
|
692 {
|
|
693 for (sone = sbn->sbn; sone != 0; sone = sone->lnk_br)
|
|
694 {
|
|
695 for (i = 0; i < par; i++)
|
|
696 {
|
|
697 p_sbn->bun_m = sbn->bend_m;
|
|
698 p_sbn->bun_jc = sbn->j_c;
|
|
699 p_sbn->i_jc = sone->i_jc;
|
|
700 p_sbn->jentptr = sone->jentptr;
|
|
701 p_sbn->t_jc = sone->t_jc;
|
|
702 p_sbn->hinsi = sone->hinsi_fk;
|
|
703 p_sbn->kangovect = sbn->kangovect;
|
|
704 p_sbn->v_jc = sone->v_jc;
|
|
705 p_sbn->status_bkwd = sone->status_bkwd;
|
|
706 if (sbn->status == WNN_NOT_CONNECT && sone->jentptr == 0)
|
|
707 p_sbn->status = WNN_GIJI;
|
|
708 else
|
|
709 p_sbn->status = sbn->status;
|
|
710 p_sbn += dbn->sbn_cnt;
|
|
711 }
|
|
712 }
|
|
713 }
|
|
714 }
|
|
715 next_dbn = dbn->lnk_br;
|
|
716 freejktdbn (dbn);
|
|
717 dbn = next_dbn;
|
|
718 #endif /* CONVERT_from_TOP */
|
|
719 }
|
|
720 return (cnt);
|
|
721 }
|
|
722
|
|
723 #ifdef CONVERT_from_TOP
|
|
724 static void
|
|
725 sbn_set (dbn, pr_d_sbn, sone, sbn)
|
|
726 register struct JKT_DBN *dbn;
|
|
727 register struct DSD_SBN **pr_d_sbn;
|
|
728 register struct JKT_SONE *sone;
|
|
729 register struct JKT_SBN *sbn;
|
|
730 {
|
|
731 int son, par;
|
|
732 register struct DSD_SBN *p_sbn;
|
|
733 if (sbn != 0)
|
|
734 {
|
|
735 sbn_set (dbn, pr_d_sbn, sone, sbn->parent);
|
|
736
|
|
737 son = cnt_son (dbn->sbn, sbn);
|
|
738 par = cnt_par (sbn);
|
|
739 p_sbn = *pr_d_sbn;
|
|
740 sons_set (dbn, sone, sbn, p_sbn, son, par);
|
|
741
|
|
742 (*pr_d_sbn)++;
|
|
743 }
|
|
744 }
|
|
745
|
|
746 static void
|
|
747 sons_set (dbn, sone, sbn, p_sbn, son, par)
|
|
748 register struct JKT_DBN *dbn;
|
|
749 register struct JKT_SONE *sone;
|
|
750 register struct JKT_SBN *sbn;
|
|
751 register struct DSD_SBN *p_sbn;
|
|
752 register int son, par;
|
|
753 {
|
|
754 register int i, j;
|
|
755
|
|
756 for (j = 0; j < son; j++)
|
|
757 {
|
|
758 for (sone = sbn->sbn; sone != 0; sone = sone->lnk_br)
|
|
759 {
|
|
760 for (i = 0; i < par; i++)
|
|
761 {
|
|
762 p_sbn->bun_m = sbn->bend_m;
|
|
763 p_sbn->bun_jc = sbn->j_c;
|
|
764 p_sbn->i_jc = sone->i_jc;
|
|
765 p_sbn->jentptr = sone->jentptr;
|
|
766 p_sbn->t_jc = sone->t_jc;
|
|
767 p_sbn->hinsi = sone->hinsi_fk;
|
|
768 p_sbn->kangovect = sbn->kangovect;
|
|
769 p_sbn->v_jc = sone->v_jc;
|
|
770 p_sbn->status_bkwd = sone->status_bkwd;
|
|
771 if (sbn->status == WNN_NOT_CONNECT && sone->jentptr == 0)
|
|
772 p_sbn->status = WNN_GIJI;
|
|
773 else
|
|
774 p_sbn->status = sbn->status;
|
|
775 p_sbn += dbn->sbn_cnt;
|
|
776 }
|
|
777 }
|
|
778 }
|
|
779 }
|
|
780 #endif /* CONVERT_from_TOP */
|
|
781
|
|
782 /* 小文節の次候補の数 */
|
|
783 int
|
|
784 cnt_sone (sone)
|
|
785 register struct JKT_SONE *sone;
|
|
786 {
|
|
787 register int i = 0;
|
|
788 while (sone)
|
|
789 {
|
|
790 i++;
|
|
791 sone = sone->lnk_br;
|
|
792 }
|
|
793 return (i);
|
|
794 }
|
|
795
|
|
796 /* その文節以後の総文節数 */
|
|
797 static int
|
|
798 cnt_par (sbn)
|
|
799 register struct JKT_SBN *sbn;
|
|
800 {
|
|
801 register int cnt;
|
|
802 cnt = 1;
|
|
803 while (sbn->parent)
|
|
804 {
|
|
805 sbn = sbn->parent;
|
|
806 cnt *= cnt_sone (sbn->sbn);
|
|
807 }
|
|
808 return (cnt);
|
|
809 }
|
|
810
|
|
811 /* その文節以前の総文節数 */
|
|
812 static int
|
|
813 cnt_son (son, sbn)
|
|
814 register struct JKT_SBN *son;
|
|
815 register struct JKT_SBN *sbn;
|
|
816 {
|
|
817 register int cnt;
|
|
818 cnt = 1;
|
|
819 while (son != sbn)
|
|
820 {
|
|
821 cnt *= cnt_sone (son->sbn);
|
|
822 son = son->parent;
|
|
823 }
|
|
824 return (cnt);
|
|
825 }
|
|
826
|
|
827 /* 1 大文節中の小文節の数 */
|
|
828 static void
|
|
829 cnt_sbn (sbn, d_cnt, s_cnt)
|
|
830 register struct JKT_SBN *sbn;
|
|
831 register int *d_cnt;
|
|
832 register int *s_cnt;
|
|
833 {
|
|
834 *s_cnt = 0;
|
|
835 *d_cnt = 1;
|
|
836 while (sbn)
|
|
837 {
|
|
838 *d_cnt *= cnt_sone (sbn->sbn);
|
|
839 (*s_cnt)++;
|
|
840 sbn = sbn->parent;
|
|
841 }
|
|
842 *s_cnt *= *d_cnt;
|
|
843 }
|
|
844
|
|
845 /* 1 大文節の数 */
|
|
846 static void
|
|
847 cnt_dbn (dbn, dbn_cnt, sbn_cnt)
|
|
848 register struct JKT_DBN *dbn;
|
|
849 register int *dbn_cnt;
|
|
850 register int *sbn_cnt;
|
|
851 {
|
|
852 int dbn_cnt_tmp;
|
|
853 int sbn_cnt_tmp;
|
|
854
|
|
855 *dbn_cnt = 0;
|
|
856 *sbn_cnt = 0;
|
|
857 while (dbn)
|
|
858 {
|
|
859 cnt_sbn (dbn->sbn, &dbn_cnt_tmp, &sbn_cnt_tmp);
|
|
860 *dbn_cnt += dbn_cnt_tmp;
|
|
861 *sbn_cnt += sbn_cnt_tmp;
|
|
862 dbn = dbn->lnk_br;
|
|
863 }
|
|
864 }
|