libjulius/src/dfa_decode.c

Go to the documentation of this file.
00001 
00053 /*
00054  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00055  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00056  * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
00057  * All rights reserved
00058  */
00059 
00060 #include <julius/julius.h>
00061 
00088 int
00089 dfa_firstwords(NEXTWORD **nw, int peseqlen, int maxnw, RecogProcess *r)
00090 {
00091   DFA_INFO *dfa;
00092   DFA_ARC *arc;
00093   MULTIGRAM *m;
00094   int s, sb, se;
00095   int cate, iw, ns;
00096   int num = 0;
00097 
00098   dfa = r->lm->dfa;
00099 
00100   for (m = r->lm->grammars; m; m = m->next) {
00101     if (m->active) {
00102       sb = m->state_begin;
00103       se = sb + m->dfa->state_num;
00104       for(s=sb;s<se;s++) {
00105         if ((dfa->st[s].status & INITIAL_S) != 0) { /* from initial state */
00106           for (arc = dfa->st[s].arc; arc; arc = arc->next) {    /* for all arc */
00107             cate = arc->label;  /* category ID */
00108             ns = arc->to_state; /* next DFA state ID */
00109             /* all words within the category is expanded */
00110             for (iw=0;iw<dfa->term.wnum[cate];iw++) {
00111               nw[num]->id = dfa->term.tw[cate][iw]; /* word ID */
00112               nw[num]->next_state = ns; /* next state */
00113               nw[num]->can_insert_sp = FALSE; /* short pause should not inserted before this word */
00114               nw[num]->lscore = r->config->lmp.penalty2;
00115               num++;
00116               if (num >= maxnw) return -1; /* buffer overflow */
00117             }
00118           }
00119         }
00120       }
00121     }
00122   }
00123 
00124   return num;
00125 }
00126 
00154 int
00155 dfa_nextwords(NODE *hypo, NEXTWORD **nw, int maxnw, RecogProcess *r)
00156 {
00157   DFA_INFO *dfa;
00158   DFA_ARC *arc, *arc2;
00159   int iw,cate,ns,cate2,ns2;
00160   int num = 0;
00161 
00162   dfa = r->lm->dfa;
00163 
00164   /* hypo->state: current DFA state ID */
00165   for (arc = dfa->st[hypo->state].arc; arc; arc = arc->next) {/* for all arc */
00166     cate = arc->label;
00167     ns = arc->to_state;
00168     if (dfa->is_sp[cate]) {     /* short pause */
00169       /* expand one more next (not expand the short pause word itself) */
00170       for (arc2 = dfa->st[ns].arc; arc2; arc2 = arc2->next) {
00171         cate2 = arc2->label;
00172         ns2 = arc2->to_state;
00173         for (iw=0;iw<dfa->term.wnum[cate2];iw++) {
00174           nw[num]->id = dfa->term.tw[cate2][iw];
00175           nw[num]->next_state = ns2;
00176           nw[num]->can_insert_sp = TRUE;
00177           nw[num]->lscore = r->config->lmp.penalty2;
00178           num++;
00179           if (num >= maxnw) return -1; /* buffer overflow */
00180         }
00181       }
00182     } else {                    /* not short pause */
00183       /* all words within the category is expanded */
00184       for (iw=0;iw<dfa->term.wnum[cate];iw++) {
00185         nw[num]->id = dfa->term.tw[cate][iw];
00186         nw[num]->next_state = ns;
00187         nw[num]->can_insert_sp = FALSE;
00188 
00189         nw[num]->lscore = r->config->lmp.penalty2;
00190         num++;
00191         if (num >= maxnw) return -1; /* buffer overflow */
00192       }
00193     }
00194   }
00195   return num;
00196 }
00197 
00198 
00221 boolean
00222 dfa_acceptable(NODE *hypo, RecogProcess *r)
00223 {
00224   if (r->lm->dfa->st[hypo->state].status & ACCEPT_S) {
00225     return TRUE;
00226   } else {
00227     return FALSE;
00228   }
00229 }
00230 
00231 /* patch by kashima */
00266 boolean
00267 dfa_look_around(NEXTWORD *nword, NODE *hypo, RecogProcess *r)
00268 {
00269   int t,tm;
00270   int i;
00271   WORD_ID w;
00272   BACKTRELLIS *bt;
00273   int lookup_range;
00274 
00275   bt = r->backtrellis;
00276   lookup_range = r->config->pass2.lookup_range;
00277   
00278   tm = hypo->estimated_next_t;  /* estimated connection time */
00279 
00280   /* look aound [tm-lookup_range..tm+lookup_range] frame */
00281   /* near the center is better:
00282      1. the first half (backward)   2. the second half (forward) */
00283   /* 1. backward */
00284   for(t = tm; t >= tm - lookup_range; t--) {
00285     if (t < 0) break;
00286      for (i=0;i<bt->num[t];i++) {
00287        w = (bt->rw[t][i])->wid;
00288        if(w == nword->id){      /* found */
00289          nword->tre = bt->rw[t][i];
00290          return TRUE;
00291        }
00292      }
00293   }
00294   /* 2. forward */
00295   for(t = tm + 1; t < tm + lookup_range; t++) {
00296     if (t > bt->framelen - 1) break;
00297     if (t >= hypo->bestt) break;
00298     for (i=0;i<bt->num[t];i++) {
00299       w = (bt->rw[t][i])->wid;
00300       if(w == nword->id){       /* found */
00301         nword->tre = bt->rw[t][i];
00302         return TRUE;
00303       }
00304     }
00305   }
00306 
00307   return FALSE;                 /* not found */
00308 }
00309 
00310 /* end of file */

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