Julius 4.2
|
00001 00053 /* 00054 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00055 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00056 * Copyright (c) 2005-2011 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 #ifdef FIX_PENALTY 00115 nw[num]->lscore = 0.0; 00116 #else 00117 nw[num]->lscore = r->config->lmp.penalty2; 00118 #endif 00119 num++; 00120 if (num >= maxnw) return -1; /* buffer overflow */ 00121 } 00122 } 00123 } 00124 } 00125 } 00126 } 00127 00128 return num; 00129 } 00130 00158 int 00159 dfa_nextwords(NODE *hypo, NEXTWORD **nw, int maxnw, RecogProcess *r) 00160 { 00161 DFA_INFO *dfa; 00162 DFA_ARC *arc, *arc2; 00163 int iw,cate,ns,cate2,ns2; 00164 int num = 0; 00165 00166 dfa = r->lm->dfa; 00167 00168 /* hypo->state: current DFA state ID */ 00169 for (arc = dfa->st[hypo->state].arc; arc; arc = arc->next) {/* for all arc */ 00170 cate = arc->label; 00171 ns = arc->to_state; 00172 if (dfa->is_sp[cate]) { /* short pause */ 00173 /* expand one more next (not expand the short pause word itself) */ 00174 for (arc2 = dfa->st[ns].arc; arc2; arc2 = arc2->next) { 00175 cate2 = arc2->label; 00176 ns2 = arc2->to_state; 00177 for (iw=0;iw<dfa->term.wnum[cate2];iw++) { 00178 nw[num]->id = dfa->term.tw[cate2][iw]; 00179 nw[num]->next_state = ns2; 00180 nw[num]->can_insert_sp = TRUE; 00181 nw[num]->lscore = r->config->lmp.penalty2; 00182 num++; 00183 if (num >= maxnw) return -1; /* buffer overflow */ 00184 } 00185 } 00186 } else { /* not short pause */ 00187 /* all words within the category is expanded */ 00188 for (iw=0;iw<dfa->term.wnum[cate];iw++) { 00189 nw[num]->id = dfa->term.tw[cate][iw]; 00190 nw[num]->next_state = ns; 00191 nw[num]->can_insert_sp = FALSE; 00192 00193 nw[num]->lscore = r->config->lmp.penalty2; 00194 num++; 00195 if (num >= maxnw) return -1; /* buffer overflow */ 00196 } 00197 } 00198 } 00199 return num; 00200 } 00201 00202 00225 boolean 00226 dfa_acceptable(NODE *hypo, RecogProcess *r) 00227 { 00228 if (r->lm->dfa->st[hypo->state].status & ACCEPT_S) { 00229 return TRUE; 00230 } else { 00231 return FALSE; 00232 } 00233 } 00234 00235 /* patch by kashima */ 00270 boolean 00271 dfa_look_around(NEXTWORD *nword, NODE *hypo, RecogProcess *r) 00272 { 00273 int t,tm; 00274 int i; 00275 WORD_ID w; 00276 BACKTRELLIS *bt; 00277 int lookup_range; 00278 00279 bt = r->backtrellis; 00280 lookup_range = r->config->pass2.lookup_range; 00281 00282 tm = hypo->estimated_next_t; /* estimated connection time */ 00283 00284 /* look aound [tm-lookup_range..tm+lookup_range] frame */ 00285 /* near the center is better: 00286 1. the first half (backward) 2. the second half (forward) */ 00287 /* 1. backward */ 00288 for(t = tm; t >= tm - lookup_range; t--) { 00289 if (t < 0) break; 00290 for (i=0;i<bt->num[t];i++) { 00291 w = (bt->rw[t][i])->wid; 00292 if(w == nword->id){ /* found */ 00293 nword->tre = bt->rw[t][i]; 00294 return TRUE; 00295 } 00296 } 00297 } 00298 /* 2. forward */ 00299 for(t = tm + 1; t < tm + lookup_range; t++) { 00300 if (t > bt->framelen - 1) break; 00301 if (t >= hypo->bestt) break; 00302 for (i=0;i<bt->num[t];i++) { 00303 w = (bt->rw[t][i])->wid; 00304 if(w == nword->id){ /* found */ 00305 nword->tre = bt->rw[t][i]; 00306 return TRUE; 00307 } 00308 } 00309 } 00310 00311 return FALSE; /* not found */ 00312 } 00313 00314 /* end of file */