libsent/src/dfa/mkcpair.c

Go to the documentation of this file.
00001 
00044 /*
00045  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00046  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00047  * Copyright (c) 2005-2007 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 
00067   /* initialize */
00068   malloc_dfa_cp(dinfo, dinfo->term_num);
00069 
00070   /* extract cpair info */
00071   for (i=0;i<dinfo->state_num;i++) {
00072     if ((dinfo->st[i].status & INITIAL_S) != 0) { /* arc from initial state */
00073       for (arc_r = dinfo->st[i].arc; arc_r; arc_r = arc_r->next) {
00074         if (dinfo->is_sp[arc_r->label]) {
00075           jlog("Error: mkcpair: skippable sp should not appear at end of sentence\n");
00076           return FALSE;
00077         }
00078         set_dfa_cp_end(dinfo, arc_r->label, TRUE);
00079       }
00080     }
00081     for(arc_l = dinfo->st[i].arc; arc_l; arc_l = arc_l->next) {
00082       left = arc_l->label;
00083       if ((dinfo->st[arc_l->to_state].status & ACCEPT_S) != 0) {/* arc to accept state */
00084         if (dinfo->is_sp[left]) {
00085           jlog("Error: mkcpair: skippable sp should not appear at beginning of sentence\n");
00086           return FALSE;
00087         }
00088         set_dfa_cp_begin(dinfo, left, TRUE);
00089       }
00090       /* others */
00091       for (arc_r = dinfo->st[arc_l->to_state].arc; arc_r; arc_r = arc_r->next) {
00092         right = arc_r->label;
00093         set_dfa_cp(dinfo, right, left, TRUE);
00094         if (dinfo->is_sp[right]) {
00095           for (arc_r2 = dinfo->st[arc_r->to_state].arc; arc_r2; arc_r2 = arc_r2->next) {
00096             if (dinfo->is_sp[arc_r2->label]) { /* sp model continues twice */
00097               jlog("Error: mkcpair: skippable sp should not repeat\n");
00098               return FALSE;
00099             }
00100             set_dfa_cp(dinfo, arc_r2->label, left, TRUE);
00101           }
00102         }
00103       }
00104 
00105     }
00106   }
00107 
00108   return TRUE;
00109 }
00110 
00118 boolean
00119 cpair_append(DFA_INFO *dst, DFA_INFO *src, int coffset)
00120 {
00121   int i,j;
00122 
00123   /* dst info must be already appended */
00124   /* [coffset..dst->term_num-1] is the new categories */
00125   if (dst->term_num - coffset != src->term_num) {
00126     jlog("Error: mkcpair: append term num not match!: %d, %d, %d\n",
00127                dst->term_num, src->term_num, coffset);
00128     return FALSE;
00129   }
00130 
00131   /* allocate appended area */
00132   realloc_dfa_cp(dst, coffset, dst->term_num);
00133   
00134   /* append cp */
00135   for(i=coffset;i<dst->term_num;i++) {
00136     for(j=coffset;j<dst->term_num;j++) {
00137       set_dfa_cp(dst, i, j, dfa_cp(src, i-coffset, j-coffset));
00138     }
00139     set_dfa_cp_begin(dst, i, dfa_cp_begin(src, i-coffset));
00140     set_dfa_cp_end(dst, i, dfa_cp_end(src, i-coffset));
00141   }
00142 
00143   return TRUE;
00144 }

Generated on Tue Dec 18 15:59:54 2007 for Julius by  doxygen 1.5.4