Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

dfa_decode.c

Go to the documentation of this file.
00001 
00053 /*
00054  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00055  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00056  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology, Nagoya Institute of Technology
00057  * All rights reserved
00058  */
00059 
00060 #include <julius.h>
00061 #ifdef USE_DFA
00062 
00085 int
00086 dfa_firstwords(NEXTWORD **nw, int peseqlen, int maxnw, DFA_INFO *dfa)
00087 {
00088   DFA_ARC *arc;
00089   MULTIGRAM *m;
00090   int s, sb, se;
00091   int cate, iw, ns;
00092   int num = 0;
00093 
00094   for (m = gramlist; m; m = m->next) {
00095     if (m->active) {
00096       sb = m->state_begin;
00097       se = sb + m->dfa->state_num;
00098       for(s=sb;s<se;s++) {
00099         if ((dfa->st[s].status & INITIAL_S) != 0) { /* from initial state */
00100           for (arc = dfa->st[s].arc; arc; arc = arc->next) {    /* for all arc */
00101             cate = arc->label;  /* category ID */
00102             ns = arc->to_state; /* next DFA state ID */
00103             /* all words within the category is expanded */
00104             for (iw=0;iw<dfa->term.wnum[cate];iw++) {
00105               nw[num]->id = dfa->term.tw[cate][iw]; /* word ID */
00106               nw[num]->next_state = ns; /* next state */
00107               nw[num]->can_insert_sp = FALSE; /* short pause should not inserted before this word */
00108               num++;
00109               if (num >= maxnw) return -1; /* buffer overflow */
00110             }
00111           }
00112         }
00113       }
00114     }
00115   }
00116 
00117   return num;
00118 }
00119 
00143 int
00144 dfa_nextwords(NODE *hypo, NEXTWORD **nw, int maxnw, DFA_INFO *dfa)
00145 {
00146   DFA_ARC *arc, *arc2;
00147   int iw,cate,ns,cate2,ns2;
00148   int num = 0;
00149 
00150   /* hypo->state: current DFA state ID */
00151   for (arc = dfa->st[hypo->state].arc; arc; arc = arc->next) {/* for all arc */
00152     cate = arc->label;
00153     ns = arc->to_state;
00154     if (dfa->is_sp[cate]) {     /* short pause */
00155       /* expand one more next (not expand the short pause word itself) */
00156       for (arc2 = dfa->st[ns].arc; arc2; arc2 = arc2->next) {
00157         cate2 = arc2->label;
00158         ns2 = arc2->to_state;
00159         for (iw=0;iw<dfa->term.wnum[cate2];iw++) {
00160           nw[num]->id = dfa->term.tw[cate2][iw];
00161           nw[num]->next_state = ns2;
00162           nw[num]->can_insert_sp = TRUE;
00163           num++;
00164           if (num >= maxnw) return -1; /* buffer overflow */
00165         }
00166       }
00167     } else {                    /* not short pause */
00168       /* all words within the category is expanded */
00169       for (iw=0;iw<dfa->term.wnum[cate];iw++) {
00170         nw[num]->id = dfa->term.tw[cate][iw];
00171         nw[num]->next_state = ns;
00172         nw[num]->can_insert_sp = FALSE;
00173         num++;
00174         if (num >= maxnw) return -1; /* buffer overflow */
00175       }
00176     }
00177   }
00178   return num;
00179 }
00180 
00181 
00200 boolean
00201 dfa_acceptable(NODE *hypo, DFA_INFO *dfa)
00202 {
00203   if (dfa->st[hypo->state].status & ACCEPT_S) {
00204     return TRUE;
00205   } else {
00206     return FALSE;
00207   }
00208 }
00209 
00210 /* patch by kashima */
00241 boolean
00242 dfa_look_around(NEXTWORD *nword, NODE *hypo, BACKTRELLIS *bt)
00243 {
00244   int t,tm;
00245   int i;
00246   WORD_ID w;
00247   
00248   tm = hypo->estimated_next_t;  /* estimated connection time */
00249 
00250   /* look aound [tm-lookup_range..tm+lookup_range] frame */
00251   /* near the center is better:
00252      1. the first half (backward)   2. the second half (forward) */
00253   /* 1. backward */
00254   for(t = tm; t >= tm - lookup_range; t--) {
00255     if (t < 0) break;
00256      for (i=0;i<bt->num[t];i++) {
00257        w = (bt->rw[t][i])->wid;
00258        if(w == nword->id){      /* found */
00259          nword->tre = bt->rw[t][i];
00260          return TRUE;
00261        }
00262      }
00263   }
00264   /* 2. forward */
00265   for(t = tm + 1; t < tm + lookup_range; t++) {
00266     if (t > bt->framelen - 1) break;
00267     if (t >= hypo->bestt) break;
00268     for (i=0;i<bt->num[t];i++) {
00269       w = (bt->rw[t][i])->wid;
00270       if(w == nword->id){       /* found */
00271         nword->tre = bt->rw[t][i];
00272         return TRUE;
00273       }
00274     }
00275   }
00276 
00277   return FALSE;                 /* not found */
00278 }
00279 
00280 #endif /* USE_DFA */

Generated on Tue Mar 28 16:01:38 2006 for Julius by  doxygen 1.4.2