40 #ifndef __EST_WFST_H__ 41 #define __EST_WFST_H__ 43 #include "EST_simplestats.h" 44 #include "EST_rw_status.h" 45 #include "EST_Option.h" 46 #include "EST_TList.h" 47 #include "EST_TVector.h" 48 #include "EST_THash.h" 50 #define wfst_error_msg(WMESS) (cerr << WMESS << endl,siod_error()) 52 #define WFST_ERROR_STATE -1 69 { p_weight=t.p_weight; p_state=t.p_state;
70 p_in_symbol = t.p_in_symbol; p_out_symbol=t.p_out_symbol; }
72 { p_weight=w; p_state=s; p_in_symbol=i; p_out_symbol=o;}
74 float weight()
const {
return p_weight; }
75 int state()
const {
return p_state; }
76 int in_symbol()
const {
return p_in_symbol; }
77 int out_symbol()
const {
return p_out_symbol; }
78 void set_weight(
float f) { p_weight = f; }
79 void set_state(
int s) { p_state = s; }
84 enum wfst_state_type {wfst_final, wfst_nonfinal, wfst_error, wfst_licence};
88 #define WFST_NONFINAL 1 90 #define WFST_LICENCE 3 99 enum wfst_state_type p_type;
112 int name()
const {
return p_name; }
113 int num_transitions()
const {
return transitions.length(); }
114 enum wfst_state_type type()
const {
return p_type; }
115 void set_type(wfst_state_type t) { p_type = t; }
116 void set_tag(
int v) { p_tag = v;}
117 int tag()
const {
return p_tag;}
122 enum wfst_mstate_type {wfst_ms_set, wfst_ms_list};
131 enum wfst_mstate_type p_type;
134 { p_name = -1; p_weight = 0.0; p_type = wfst_ms_set; }
136 { p_name = -1; p_weight = 0.0; p_type = ty; }
137 int name()
const {
return p_name; }
138 void set_name(
int i) { p_name = i; }
139 float weight()
const {
return p_weight; }
140 void set_weight(
float w) { p_weight = w; }
141 void set_type(
enum wfst_mstate_type s) { p_type = s; }
142 enum wfst_mstate_type type()
const {
return p_type; }
160 int operator_and(LISP l);
161 int operator_or(LISP l);
162 int operator_star(LISP l);
163 int operator_plus(LISP l);
164 int operator_optional(LISP l);
165 int operator_not(LISP l);
166 int terminal(LISP l);
170 void extend_alphabets(
const EST_WFST &b);
172 EST_read_status load_transitions_from_lisp(
int s, LISP trans);
173 void more_states(
int new_max);
175 int can_reach_final(
int state);
176 static int traverse_tag;
190 void init(
int init_num_states=10);
192 void init(LISP in, LISP out);
201 int num_states()
const {
return p_num_states; }
202 int start_state()
const {
return p_start_state; }
205 {
return p_in_symbols.
name(s); }
208 {
return p_in_symbols.
name(i); }
211 {
return p_out_symbols.
name(s); }
214 {
return p_out_symbols.
name(i); }
226 int final(
int i)
const 227 {
return ((i != WFST_ERROR_STATE) && (state(i)->type() == wfst_final));}
238 EST_write_status save(
const EST_String &filename,
240 EST_write_status save_binary(FILE *fd);
242 EST_read_status load(
const EST_String &filename);
244 EST_read_status load_binary(FILE *fd,
253 int transition(
int state,
int in,
int out)
const;
254 int transition(
int state,
int in,
int out,
float &prob)
const;
260 int transition(
int state,
const EST_String &inout)
const;
262 int transduce(
int state,
int in,
int &out)
const;
268 void transition_all(
int state,
int in,
int out,
279 void start_cumulate();
281 void stop_cumulate();
287 int add_state(
enum wfst_state_type state_type);
292 void build_wfst(
int start,
int end,LISP regex);
294 void build_and_transition(
int start,
int end, LISP conjunctions);
296 void build_or_transition(
int start,
int end, LISP disjunctions);
299 void build_from_regex(LISP inalpha, LISP outalpha, LISP regex);
301 void kkrule_compile(LISP inalpha, LISP outalpha, LISP fp,
302 LISP rule, LISP sets);
304 void build_from_rg(LISP inalpha, LISP outalpha,
305 LISP distinguished, LISP rewrites,
306 LISP sets, LISP terms,
309 void build_tree_lex(LISP inalpha, LISP outalpha,
316 void determinize(
const EST_WFST &a);
352 int deterministic()
const;
356 int in,
int out)
const;
360 void remove_error_states(
const EST_WFST &a);
379 void kkcompile(LISP ruleset,
EST_WFST &all_wfst);
381 void ltscompile(LISP lts_rules,
EST_WFST &all_wfst);
383 void rgcompile(LISP rg,
EST_WFST &all_wfst);
385 void tlcompile(LISP rg,
EST_WFST &all_wfst);
393 int recognize_for_perplexity(
const EST_WFST &wfst,
398 int recognize_for_perplexity(
const EST_WFST &wfst,
405 VAL_REGISTER_CLASS_DCLS(wfst,
EST_WFST)
LISP epsilon_label() const
LISP for on epsilon symbols.
EST_WFST(const EST_WFST &wfst)
?
int out_epsilon() const
Internal index for output epsilon.
const EST_String & name(const int n) const
The name given the index.
int in_symbol(const EST_String &s) const
Map input symbol to input alphabet index.
const EST_Discrete & out_symbols() const
Accessing the output alphabet.
int cumulate() const
Cumulation condition.
const EST_Discrete & in_symbols() const
Accessing the input alphabet.
int out_symbol(const EST_String &s) const
Map output symbol to output alphabet index.
const EST_WFST_State * state(int i) const
Return internal state information.
const EST_String & in_symbol(int i) const
Map input alphabet index to input symbol.
int in_epsilon() const
Internal index for input epsilon.
EST_WFST_State * state_non_const(int i)
Return internal state information (non-const)
const EST_String & out_symbol(int i) const
Map output alphabet index to output symbol.