00001
00053
00054
00055
00056
00057
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) {
00100 for (arc = dfa->st[s].arc; arc; arc = arc->next) {
00101 cate = arc->label;
00102 ns = arc->to_state;
00103
00104 for (iw=0;iw<dfa->term.wnum[cate];iw++) {
00105 nw[num]->id = dfa->term.tw[cate][iw];
00106 nw[num]->next_state = ns;
00107 nw[num]->can_insert_sp = FALSE;
00108 num++;
00109 if (num >= maxnw) return -1;
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
00151 for (arc = dfa->st[hypo->state].arc; arc; arc = arc->next) {
00152 cate = arc->label;
00153 ns = arc->to_state;
00154 if (dfa->is_sp[cate]) {
00155
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;
00165 }
00166 }
00167 } else {
00168
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;
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
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;
00249
00250
00251
00252
00253
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){
00259 nword->tre = bt->rw[t][i];
00260 return TRUE;
00261 }
00262 }
00263 }
00264
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){
00271 nword->tre = bt->rw[t][i];
00272 return TRUE;
00273 }
00274 }
00275 }
00276
00277 return FALSE;
00278 }
00279
00280 #endif