Julius 4.2
libsent/src/dfa/mkcpair.c
説明を見る。
00001 
00044 /*
00045  * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
00046  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00047  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00048  * All rights reserved
00049  */
00050 
00051 #include <sent/stddefs.h>
00052 #include <sent/dfa.h>
00053 
00060 boolean
00061 extract_cpair(DFA_INFO *dinfo)
00062 {
00063   int i;
00064   DFA_ARC *arc_l, *arc_r, *arc_r2;
00065   int left, right;
00066   int size;
00067 
00068   /* initialize */
00069   /* initial size = average fun-out num per state */
00070   size = dinfo->arc_num / dinfo->state_num;
00071   if (size < DFA_CP_MINSTEP) size = DFA_CP_MINSTEP;
00072   malloc_dfa_cp(dinfo, dinfo->term_num, size);
00073 
00074   /* extract cpair info */
00075   for (i=0;i<dinfo->state_num;i++) {
00076     if ((dinfo->st[i].status & INITIAL_S) != 0) { /* arc from initial state */
00077       for (arc_r = dinfo->st[i].arc; arc_r; arc_r = arc_r->next) {
00078         if (dinfo->is_sp[arc_r->label]) {
00079           jlog("Error: mkcpair: skippable sp should not appear at end of sentence\n");
00080           return FALSE;
00081         }
00082         set_dfa_cp_end(dinfo, arc_r->label, TRUE);
00083       }
00084     }
00085     for(arc_l = dinfo->st[i].arc; arc_l; arc_l = arc_l->next) {
00086       left = arc_l->label;
00087       if ((dinfo->st[arc_l->to_state].status & ACCEPT_S) != 0) {/* arc to accept state */
00088         if (dinfo->is_sp[left]) {
00089           jlog("Error: mkcpair: skippable sp should not appear at beginning of sentence\n");
00090           return FALSE;
00091         }
00092         set_dfa_cp_begin(dinfo, left, TRUE);
00093       }
00094       /* others */
00095       for (arc_r = dinfo->st[arc_l->to_state].arc; arc_r; arc_r = arc_r->next) {
00096         right = arc_r->label;
00097         set_dfa_cp(dinfo, right, left, TRUE);
00098         if (dinfo->is_sp[right]) {
00099           for (arc_r2 = dinfo->st[arc_r->to_state].arc; arc_r2; arc_r2 = arc_r2->next) {
00100             if (dinfo->is_sp[arc_r2->label]) { /* sp model continues twice */
00101               jlog("Error: mkcpair: skippable sp should not repeat\n");
00102               return FALSE;
00103             }
00104             set_dfa_cp(dinfo, arc_r2->label, left, TRUE);
00105           }
00106         }
00107       }
00108 
00109     }
00110   }
00111 
00112   return TRUE;
00113 }
00114 
00122 boolean
00123 cpair_append(DFA_INFO *dst, DFA_INFO *src, int coffset)
00124 {
00125   /* dst info must be already appended */
00126   /* [coffset..dst->term_num-1] is the new categories */
00127   if (dst->term_num - coffset != src->term_num) {
00128     jlog("Error: mkcpair: append term num not match!: %d, %d, %d\n",
00129                dst->term_num, src->term_num, coffset);
00130     return FALSE;
00131   }
00132 
00133   /* allocate appended area */
00134   if (dfa_cp_append(dst, src, coffset) == FALSE) return FALSE;
00135 
00136   return TRUE;
00137 }