53 ostream &operator << (ostream &s,
const wfst_tstate &state)
56 return s <<
"<<wfst_tstate>>";
59 Declare_TList(wfst_tstate)
61 #if defined(INSTANTIATE_TEMPLATES)
62 #include "../base_class/EST_TList.cc"
64 Instantiate_TList(wfst_tstate)
70 static void add_transduce_mstate(
const EST_WFST &wfst,
71 const wfst_tstate &cs,
73 wfst_tstate_list &ns);
82 for (p=in.head(); p != 0; p=p->next())
85 r = transduce(wfst,in_i,out_i);
87 for (p=out_i.head(); p != 0; p=p->next())
98 wfst_tstate_list *current_ms =
new wfst_tstate_list;
99 wfst_tstate start_state;
102 start_state.state = wfst.start_state();
103 start_state.score = 0;
104 current_ms->append(start_state);
107 add_transduce_mstate(wfst,start_state,ss_eps_trans,*current_ms);
109 for (i=in.head(); i != 0; i=i->next())
111 wfst_tstate_list *ns =
new wfst_tstate_list;
113 for (cs=current_ms->head(); cs != 0; cs=cs->next())
116 wfst.
transduce((*current_ms)(cs).state,in(i),translist);
117 add_transduce_mstate(wfst,(*current_ms)(cs),translist,*ns);
123 if (current_ms->length() == 0)
127 if (current_ms->length() > 1)
128 cerr <<
"WFST: found " << current_ms->length() <<
" transductions" <<
132 for (cs = current_ms->head(); cs != 0; cs=cs->next())
134 if ((wfst.
final((*current_ms)(cs).state)) &&
135 ((*current_ms)(cs).outs.length() > out.length()))
138 out = (*current_ms)(cs).outs;
145 static void add_transduce_mstate(
const EST_WFST &wfst,
146 const wfst_tstate &cs,
148 wfst_tstate_list &ns)
158 for (t=translist.head(); t != 0; t=t->next())
164 wfst_tstate &ts = ns.last();
166 ts.state = translist(t)->state();
168 ts.score = translist(t)->weight()+cs.score;
171 ts.outs.append(translist(t)->out_symbol());
176 add_transduce_mstate(wfst,ts,etranslist,ns);
188 for (p=in.head(); p != 0; p=p->next())
190 if (in(p).contains(
"/"))
204 r = recognize(wfst,in_i,out_i,quiet);
212 int state = wfst.start_state();
216 for (p=in.head(),q=out.head();
217 ((p != 0) && (q != 0));
218 p=p->next(),q=q->next())
222 printf(
"state %d %s/%s -> %d\n",state,
227 if (state == WFST_ERROR_STATE)
233 cerr <<
"wfst recognize: in/out tapes of different lengths"
238 if (wfst.
final(state))
244 int recognize_for_perplexity(
const EST_WFST &wfst,
256 for (p=in.head(); p != 0; p=p->next())
258 if (in(p).contains(
"/"))
272 r = recognize_for_perplexity(wfst,in_i,out_i,quiet,count,sumlogp);
277 int recognize_for_perplexity(
const EST_WFST &wfst,
284 int state = wfst.start_state();
291 for (p=in.head(),q=out.head();
292 ((p != 0) && (q != 0));
293 p=p->next(),q=q->next())
295 nstate = wfst.
transition(state,in(p),out(q),prob);
298 sumlogp += log(prob);
302 printf(
"state %d %s/%s -> %d\n",state,
307 if (state == WFST_ERROR_STATE)
313 cerr <<
"wfst recognize: in/out tapes of different lengths"
318 if (wfst.
final(state))