41 #include "EST_cutils.h" 50 if (disjunctions == NIL)
51 cerr <<
"WFST construct: disjunct is nil\n";
53 for (l=disjunctions; l != NIL; l=cdr(l))
68 if (conjunctions == NIL)
69 cerr <<
"WFST build: conjunct is nil\n";
72 for (l=conjunctions; cdr(l) != NIL; l=cdr(l))
82 int EST_WFST::terminal(LISP l)
92 int EST_WFST::operator_or(LISP l)
94 if (l && !consp(l) && (streq(
"or",get_c_string(l))))
100 int EST_WFST::operator_plus(LISP l)
102 if (l && !consp(l) && (streq(
"+",get_c_string(l))))
108 int EST_WFST::operator_not(LISP l)
110 if (l && !consp(l) && (streq(
"not",get_c_string(l))))
116 int EST_WFST::operator_star(LISP l)
118 if (l && !consp(l) && (streq(
"*",get_c_string(l))))
124 int EST_WFST::operator_optional(LISP l)
126 if (l && !consp(l) && (streq(
"?",get_c_string(l))))
132 int EST_WFST::operator_and(LISP l)
134 if (l && !consp(l) && (streq(
"and",get_c_string(l))))
150 out = p_out_symbols.
name(s_name.
after(
"/"));
154 in = p_in_symbols.
name(get_c_string(regex));
155 out = p_out_symbols.
name(get_c_string(regex));
157 if ((in == -1) || (out == -1))
158 cerr <<
"WFST_build: symbol " << get_c_string(regex) <<
159 " not in alphabet\n";
160 p_states[start]->add_transition(0,end,in,out);
162 else if (operator_or(car(regex)))
164 else if (operator_plus(car(regex)))
169 else if (operator_star(car(regex)))
174 else if (operator_not(car(regex)))
179 else if (operator_optional(car(regex)))
184 else if (operator_and(car(regex)))
190 void EST_WFST::build_from_regex(LISP inalpha, LISP outalpha, LISP regex)
195 cout <<
"building from regex: " << endl;
198 init(inalpha,outalpha);
203 p_start_state =
add_state(wfst_nonfinal);
LISP epsilon_label() const
LISP for on epsilon symbols.
int add_state(enum wfst_state_type state_type)
Add a new state, returns new name.
void clear()
clear removing existing states if any
void build_or_transition(int start, int end, LISP disjunctions)
Basic disjunction constructor.
const EST_String & name(const int n) const
The name given the index.
void build_wfst(int start, int end, LISP regex)
Basic regex constructor.
int contains(const char *s, int pos=-1) const
Does it contain this substring?
EST_String after(int pos, int len=1) const
Part after pos+len.
void init(int init_num_states=10)
Clear with (estimation of number of states required)
EST_String before(int pos, int len=0) const
Part before position.
void build_and_transition(int start, int end, LISP conjunctions)
Basic conjunction constructor.