comparison Wnn/jserver/jikouho_d.c @ 0:bbc77ca4def5

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