51 static LISP find_rewrites(LISP rules, LISP terms, LISP nonterms);
52 static LISP rg_find_nt_ts(LISP rules,LISP sets);
53 static LISP prod_join(LISP n, LISP p);
54 static int production_index(LISP state,
61 LISP nt_ts,nonterms,terms,rewrites;
65 nt_ts = rg_find_nt_ts(rules,sets);
66 nonterms =
car(nt_ts);
69 rewrites = find_rewrites(rules,terms,nonterms);
81 static LISP find_rewrites(LISP rules, LISP terms, LISP nonterms)
90 for (nt=nonterms; nt !=
NIL; nt=
cdr(nt))
93 for (r=rules; r !=
NIL; r=
cdr(r))
102 static LISP rg_find_nt_ts(LISP rules,LISP sets)
105 LISP terms=
NIL,nonterms=
NIL,r,s,
set,t;
107 for (r=rules; r !=
NIL; r=
cdr(r))
111 for (r=rules; r !=
NIL; r=
cdr(r))
119 for (t=
cdr(
set); t != 0; t=
cdr(t))
124 return cons(nonterms,terms);
129 LISP distinguished, LISP rewrites,
130 LISP sets, LISP terms,
136 LISP current, start_state, remainder,
set, new_prod;
137 int ns, current_state;
138 const char *current_sym;
145 init(inalpha,outalpha);
146 int i_epsilon = in_epsilon();
147 int o_epsilon = out_epsilon();
154 production_index(start_state,index,p_start_state);
156 agenda =
cons(start_state,agenda);
158 while (agenda !=
NIL)
160 current =
car(agenda);
161 agenda =
cdr(agenda);
164 remainder =
cdr(
cdr(current));
166 cout << summary() <<
" Agenda " <<
siod_llength(agenda) << endl;
171 ns = production_index(remainder,index,p_num_states);
173 for (LISP s=
cdr(
set); s !=
NIL; s=
cdr(s))
174 p_states[current_state]
175 ->add_transition(0.0,
179 if (remainder ==
NIL)
181 else if (ns == p_num_states)
189 ns = production_index(remainder,index,p_num_states);
191 p_states[current_state]
192 ->add_transition(0.0,
194 p_in_symbols.name(current_sym),
195 p_out_symbols.name(current_sym));
196 if (remainder ==
NIL)
198 else if (ns == p_num_states)
210 new_prod = prod_join(
car(p),remainder);
211 ns = production_index(new_prod,index,p_num_states);
212 p_states[current_state]
213 ->add_transition(0.0,
214 ns,i_epsilon,o_epsilon);
215 if (ns == p_num_states)
230 static int production_index(LISP state,
241 for (p=state; p !=
NIL; p =
cdr(p))
246 for (p=state; p !=
NIL; p =
cdr(p))
249 ns = index.
val(istring,found);
260 static LISP prod_join(LISP n, LISP p)
a call representing a weighted finite-state transducer
long int get_c_int(LISP x)
int siod_llength(LISP list)
A specialised hash table for when the key is an EST_String.
LISP siod_assoc_str(const char *key, LISP alist)
int index(EST_TList< T > &l, T &val, bool(*eq)(const EST_UItem *, const EST_UItem *)=NULL)
LISP siod_nth(int nth, LISP list)
const char * get_c_string(LISP x)
LISP cons(LISP x, LISP y)
V & val(const K &key, int &found) const
void rgcompile(LISP rg, EST_WFST &all_wfst)
void build_from_rg(LISP inalpha, LISP outalpha, LISP distinguished, LISP rewrites, LISP sets, LISP terms, int max_depth)
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
LISP siod_member_str(const char *key, LISP list)