48 #include "EST_cutils.h"
49 #include "EST_THash.h"
52 static LISP tl_find_l_w(LISP rules);
53 static int production_index(LISP state,
57 void tlcompile(LISP tl,
EST_WFST &all_wfst)
60 LISP l_w,letters,words;
62 LISP rules=siod_nth(3,tl);
64 l_w = tl_find_l_w(rules);
68 all_wfst.build_tree_lex(letters,words,rules);
72 static LISP tl_find_l_w(LISP rules)
75 LISP letters=NIL,words=NIL,r,s;
77 for (r=rules; r != NIL; r=cdr(r))
79 for (s = car(r); s != NIL; s=cdr(s))
81 if (streq(
"->",get_c_string(car(s))))
83 if (!siod_member_str(get_c_string(car(cdr(s))),words))
84 words = cons(car(cdr(s)),words);
87 else if (!siod_member_str(get_c_string(car(s)),letters))
89 letters = cons(car(s),letters);
94 return cons(letters,words);
98 void EST_WFST::build_tree_lex(LISP inalpha, LISP outalpha,
109 init(inalpha,outalpha);
115 p_start_state =
add_state(wfst_nonfinal);
118 for (w=wlist; w; w=cdr(w))
121 weight = get_c_float(car(siod_last(car(w))));
122 for (cs=p_start_state,l=car(w); l; l=cdr(l))
124 if (streq(
"->",get_c_string(car(l))))
128 p_out_symbols.
name(get_c_string(car(cdr(l)))));
132 ->add_transition(weight,
134 p_out_symbols.
name(get_c_string(car(cdr(l)))));
145 p_in_symbols.
name(get_c_string(car(l))),
149 ns = production_index(cdr(l),index,p_num_states);
150 if (ns == p_num_states)
153 ->add_transition(weight,
155 p_in_symbols.
name(get_c_string(car(l))),
161 trans->set_weight(trans->weight()+weight);
172 static int production_index(LISP state,
184 for (p=state; p != NIL; p = cdr(p))
185 istring +=
EST_String(get_c_string(car(p))) +
" ";
187 ns = index.
val(istring,found);