12 #ifndef _LOG_WEIGHT_TRANSDUCER_H_
13 #define _LOG_WEIGHT_TRANSDUCER_H_
20 #include "back-ends/openfstwin/src/include/fst/fstlib.h"
22 #include "../../../config.h"
23 #include "back-ends/openfst/src/include/fst/fstlib.h"
26 #include "HfstExtractStrings.h"
38 namespace implementations
42 typedef LogArc::StateId StateId;
43 typedef VectorFst<LogArc> LogFst;
45 typedef std::vector<LogArc> LogArcVector;
46 struct LogArcLessThan {
47 bool operator() (
const LogArc &arc1,
const LogArc &arc2)
const; };
50 using std::ostringstream;
51 using std::stringstream;
53 void openfst_log_set_hopcroft(
bool value);
55 class LogWeightInputStream
60 istream &input_stream;
61 void skip_identifier_version_3_0(
void);
62 void skip_hfst_header(
void);
64 LogWeightInputStream(
void);
65 LogWeightInputStream(
const std::string &filename);
67 bool is_eof(
void)
const;
68 bool is_bad(
void)
const;
69 bool is_good(
void)
const;
70 bool is_fst(
void)
const;
71 bool operator() (
void)
const;
72 void ignore(
unsigned int);
73 LogFst * read_transducer();
76 short stream_get_short();
77 void stream_unget(
char c);
79 static bool is_fst(FILE * f);
80 static bool is_fst(istream &s);
83 class LogWeightOutputStream
88 ostream &output_stream;
91 LogWeightOutputStream(
void);
92 LogWeightOutputStream(
const std::string &filename);
94 void write(
const char &c);
95 void write_transducer(LogFst * transducer);
98 class LogWeightTransitionIterator;
100 typedef StateId LogWeightState;
102 class LogWeightStateIterator
105 StateIterator<LogFst> * iterator;
107 LogWeightStateIterator(LogFst * t);
108 ~LogWeightStateIterator(
void);
111 LogWeightState value(
void);
115 class LogWeightTransition
121 LogWeightTransition(
const LogArc &arc, LogFst *t);
122 ~LogWeightTransition(
void);
123 std::string get_input_symbol(
void)
const;
124 std::string get_output_symbol(
void)
const;
125 LogWeightState get_target_state(
void)
const;
126 LogWeight get_weight(
void)
const;
130 class LogWeightTransitionIterator
133 ArcIterator<LogFst> * arc_iterator;
136 LogWeightTransitionIterator(LogFst * t, StateId state);
137 ~LogWeightTransitionIterator(
void);
140 LogWeightTransition value(
void);
144 class LogWeightTransducer
147 static LogFst * create_empty_transducer(
void);
148 static LogFst * create_epsilon_transducer(
void);
151 static LogFst * define_transducer(
const std::string &symbol);
152 static LogFst * define_transducer
153 (
const std::string &isymbol,
const std::string &osymbol);
154 static LogFst * define_transducer
156 static LogFst * define_transducer
158 static LogFst * define_transducer(
const std::vector<StringPairSet> &spsv);
161 static LogFst * define_transducer(
unsigned int number);
162 static LogFst * define_transducer
163 (
unsigned int inumber,
unsigned int onumber);
164 static LogFst * define_transducer(
const hfst::NumberPairVector &npv);
165 static LogFst * define_transducer
166 (
const hfst::NumberPairSet &nps,
bool cyclic=
false);
167 static LogFst * define_transducer
168 (
const std::vector<NumberPairSet> &npsv);
170 static LogFst * copy(LogFst * t);
171 static LogFst * determinize(LogFst * t);
172 static LogFst * minimize(LogFst * t);
173 static LogFst * remove_epsilons(LogFst * t);
174 static LogFst * n_best(LogFst * t,
unsigned int n);
175 static LogFst * repeat_star(LogFst * t);
176 static LogFst * repeat_plus(LogFst * t);
177 static LogFst * repeat_n(LogFst * t,
unsigned int n);
178 static LogFst * repeat_le_n(LogFst * t,
unsigned int n);
179 static LogFst * optionalize(LogFst * t);
180 static LogFst * invert(LogFst * t);
181 static LogFst * reverse(LogFst * transducer);
182 static LogFst * extract_input_language(LogFst * t);
183 static LogFst * extract_output_language(LogFst * t);
184 static void extract_paths
185 (LogFst * t, hfst::ExtractStringsCb& callback,
186 int cycles=-1, FdTable<int64>* fd=NULL,
bool filter_fd=
false
188 static void extract_random_paths
190 static LogFst * compose(LogFst * t1,
192 static LogFst * concatenate(LogFst * t1,
194 static LogFst * disjunct(LogFst * t1,
198 static LogFst * disjunct(LogFst * t,
const NumberPairVector &npv);
200 static LogFst * intersect(LogFst * t1,
202 static LogFst * subtract(LogFst * t1,
204 static LogFst * set_weight(LogFst * t,
float f);
205 static LogFst * set_final_weights(LogFst * t,
float weight);
206 static LogFst * transform_weights(LogFst * t,
float (*func)(
float f));
207 static LogFst * push_weights(LogFst * t,
bool to_initial_state);
209 static std::pair<LogFst*, LogFst*> harmonize
210 (LogFst *t1, LogFst *t2,
bool unknown_symbols_in_use=
true);
212 static void write_in_att_format(LogFst * t, FILE *ofile);
213 static void write_in_att_format_number(LogFst * t, FILE *ofile);
215 static void test_minimize(
void);
217 static void write_in_att_format(LogFst * t, std::ostream &os);
218 static void write_in_att_format_number(LogFst * t, std::ostream &os);
220 static LogFst * read_in_att_format(FILE *ifile);
222 static bool are_equivalent(LogFst *one, LogFst *another);
223 static bool is_cyclic(LogFst * t);
224 static bool is_automaton(LogFst * t);
226 static FdTable<int64>* get_flag_diacritics(LogFst * t);
229 static LogFst * insert_freely(LogFst * t,
const StringPair &symbol_pair);
230 static LogFst * substitute
231 (LogFst * t, std::string old_symbol, std::string new_symbol);
232 static LogFst * substitute(LogFst * t,
235 static LogFst * substitute(LogFst * t,
238 static LogFst * substitute(LogFst * t,
243 static LogFst * insert_freely(LogFst * t,
const NumberPair &number_pair);
244 static LogFst * substitute(LogFst * t,
unsigned int,
unsigned int);
245 static LogFst * substitute(LogFst * t,
246 NumberPair old_number_pair,
247 NumberPair new_number_pair);
248 static LogFst * substitute(LogFst * t,
249 const NumberPair old_number_pair,
252 static void insert_to_alphabet
253 (LogFst *t,
const std::string &symbol);
254 static void remove_from_alphabet
255 (LogFst *t,
const std::string &symbol);
256 static StringSet get_alphabet(LogFst *t);
257 static unsigned int get_symbol_number(LogFst *t,
258 const std::string &symbol);
260 static NumberNumberMap create_mapping(LogFst * t1, LogFst * t2);
261 static void recode_symbol_numbers(LogFst * t, hfst::NumberNumberMap &km);
263 static LogFst * expand_arcs
264 (LogFst * t, hfst::StringSet &unknown,
bool unknown_symbols_in_use);
266 float get_profile_seconds();
268 static unsigned int number_of_states(
const LogFst * t);
271 static fst::SymbolTable create_symbol_table(std::string name);
272 static void initialize_symbol_tables(LogFst *t);
273 static void remove_symbol_table(LogFst *t);
277 typedef std::map<int, StateId> StateMap;
279 static StateId add_and_map_state
280 (LogFst *t,
int state_number, StateMap &state_map);
282 static int has_arc(LogFst &t,
283 LogArc::StateId sourcestate,
284 LogArc::Label ilabel,
285 LogArc::Label olabel);
286 static void disjunct_as_tries(LogFst &t1,
290 static void add_sub_trie(LogFst &t1,
296 static StateId add_state(LogFst *t);
297 static void set_final_weight(LogFst *t, StateId s,
float w);
298 static void add_transition
299 (LogFst *t, StateId source,
300 std::string &isymbol, std::string &osymbol,
float w, StateId target);
301 static float get_final_weight(LogFst *t, StateId s);
302 static float is_final(LogFst *t, StateId s);
303 static StateId get_initial_state(LogFst *t);
304 static void represent_empty_transducer_as_having_one_state(LogFst *t);
std::pair< String, String > StringPair
A symbol pair in a transition.
Definition: HfstSymbolDefs.h:71
std::vector< std::pair< std::string, std::string > > StringPairVector
A vector of string pairs.
Definition: HfstDataTypes.h:106
Class declarations for flag diacritic handling.
std::set< HfstTwoLevelPath > HfstTwoLevelPaths
A set of two-level weighted paths.
Definition: HfstDataTypes.h:110
std::set< StringPair > StringPairSet
A set of symbol pairs used in substituting symbol pairs and in rule functions.
Definition: HfstSymbolDefs.h:83
Typedefs and functions for symbols, symbol pairs and sets of symbols.