 |
Edinburgh Speech Tools
2.4-release
|
|
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));}
240 EST_write_status save_binary(FILE *fd);
244 EST_read_status load_binary(FILE *fd,
287 int add_state(
enum wfst_state_type state_type);
292 void build_wfst(
int start,
int end,LISP regex);
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,
356 int in,
int out)
const;
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.
void remove_error_states(const EST_WFST &a)
Remove error states from the WFST.
const EST_Discrete & out_symbols() const
Accessing the output alphabet.
int cumulate() const
Cumulation condition.
void compose(const EST_WFST &a, const EST_WFST &b)
const EST_String & name(const int n) const
The name given the index.
EST_WFST & operator=(const EST_WFST &a)
?
void intersection(EST_TList< EST_WFST > &wl)
const EST_Discrete & in_symbols() const
Accessing the input alphabet.
void stop_cumulate()
Stop cumulation and calculate probabilities on transitions.
void uunion(EST_TList< EST_WFST > &wl)
void minimize(const EST_WFST &a)
Build minimized form of a.
void build_and_transition(int start, int end, LISP conjunctions)
Basic conjunction constructor.
int deterministic() const
True if WFST is deterministic.
void difference(const EST_WFST &a, const EST_WFST &b)
EST_WFST(const EST_WFST &wfst)
?
void init(int init_num_states=10)
Clear with (estimation of number of states required)
EST_write_status save(const EST_String &filename, const EST_String type="ascii")
?
EST_WFST_State * state_non_const(int i)
Return internal state information (non-const)
int transduce(int state, int in, int &out) const
Transduce in to out from state.
const EST_String & in_symbol(int i) const
Map input alphabet index to input symbol.
void determinize(const EST_WFST &a)
Build determinized form of a.
enum wfst_state_type ms_type(EST_WFST_MultiState *ms) const
Given a multi-state return type (final, ok, error)
const EST_String & out_symbol(int i) const
Map output alphabet index to output symbol.
EST_WFST_Transition * find_transition(int state, int in, int out) const
Find (first) transition given in and out symbols.
int transition(int state, int in, int out) const
Find (first) new state given in and out symbols.
void build_wfst(int start, int end, LISP regex)
Basic regex constructor.
void build_or_transition(int start, int end, LISP disjunctions)
Basic disjunction constructor.
int add_state(enum wfst_state_type state_type)
Add a new state, returns new name.
int in_symbol(const EST_String &s) const
Map input symbol to input alphabet index.
void concat(const EST_WFST &a, const EST_WFST &b)
void complement(const EST_WFST &a)
Build complement of a.
EST_WFST_MultiState * apply_multistate(const EST_WFST &wfst, EST_WFST_MultiState *ms, int in, int out) const
Transduce a multi-state given n and out.
void clear()
clear removing existing states if any
int out_epsilon() const
Internal index for output epsilon.
void copy(const EST_WFST &wfst)
Copy from existing wfst.
const EST_WFST_State * state(int i) const
Return internal state information.
EST_read_status load(const EST_String &filename)
?
void start_cumulate()
Clear and start cumulation.
void transition_all(int state, int in, int out, EST_WFST_MultiState *ms) const
Find all possible transitions for given state/input/output.
int out_symbol(const EST_String &s) const
Map output symbol to output alphabet index.
int in_epsilon() const
Internal index for input epsilon.
void add_epsilon_reachable(EST_WFST_MultiState *ms) const
Extend multi-state with epsilon reachable states.