00001
00053
00054
00055
00056
00057
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) {
00106 for (arc = dfa->st[s].arc; arc; arc = arc->next) {
00107 cate = arc->label;
00108 ns = arc->to_state;
00109
00110 for (iw=0;iw<dfa->term.wnum[cate];iw++) {
00111 nw[num]->id = dfa->term.tw[cate][iw];
00112 nw[num]->next_state = ns;
00113 nw[num]->can_insert_sp = FALSE;
00114 nw[num]->lscore = r->config->lmp.penalty2;
00115 num++;
00116 if (num >= maxnw) return -1;
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
00165 for (arc = dfa->st[hypo->state].arc; arc; arc = arc->next) {
00166 cate = arc->label;
00167 ns = arc->to_state;
00168 if (dfa->is_sp[cate]) {
00169
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;
00180 }
00181 }
00182 } else {
00183
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;
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
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;
00279
00280
00281
00282
00283
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){
00289 nword->tre = bt->rw[t][i];
00290 return TRUE;
00291 }
00292 }
00293 }
00294
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){
00301 nword->tre = bt->rw[t][i];
00302 return TRUE;
00303 }
00304 }
00305 }
00306
00307 return FALSE;
00308 }
00309
00310