13 #ifndef _SFST_TRANSDUCER_H_
14 #define _SFST_TRANSDUCER_H_
19 #include "HfstExtractStrings.h"
20 #include "back-ends/sfst/interface.h"
21 #include "back-ends/sfst/fst.h"
32 namespace implementations
35 typedef SFST::Transducer Transducer;
38 using std::ostringstream;
40 void sfst_set_hopcroft(
bool);
49 void add_symbol(StringNumberMap &string_number_map,
51 SFST::Alphabet &alphabet);
54 SfstInputStream(
void);
55 SfstInputStream(
const std::string &filename);
61 void ignore(
unsigned int);
64 short stream_get_short();
65 void stream_unget(
char c);
67 bool set_implementation_specific_header_data
69 SFST::Transducer * read_transducer();
71 static bool is_fst(FILE * f);
72 static bool is_fst(std::istream &s);
75 class SfstOutputStream
82 SfstOutputStream(
void);
83 SfstOutputStream(
const std::string &filename);
85 void write(
const char &c);
86 void append_implementation_specific_header_data
87 (std::vector<char> &header, SFST::Transducer *t);
88 void write_transducer(SFST::Transducer * transducer);
94 size_t operator()(
const SFST::Node *node)
const {
99 int operator()(
const SFST::Node *n1,
const SFST::Node *n2)
const {
103 typedef SFST::hash_map<SFST::Node*, int, hashf, equalf> NL;
109 int &operator[]( SFST::Node *node ) {
110 NL::iterator it=number.find(node);
111 if (it == number.end())
112 return number.insert(NL::value_type(node, 0)).first->second;
121 static SFST::Transducer * create_empty_transducer(
void);
122 static SFST::Transducer * create_epsilon_transducer(
void);
124 static SFST::Transducer * define_transducer(
unsigned int number);
125 static SFST::Transducer * define_transducer
126 (
unsigned int inumber,
unsigned int onumber);
128 static SFST::Transducer * define_transducer(
const std::string &symbol);
129 static SFST::Transducer * define_transducer
130 (
const std::string &isymbol,
const std::string &osymbol);
131 static SFST::Transducer * define_transducer
133 static SFST::Transducer * define_transducer
135 static SFST::Transducer * define_transducer
136 (
const std::vector<StringPairSet> &spsv);
137 static SFST::Transducer * copy(SFST::Transducer * t);
138 static SFST::Transducer * determinize(SFST::Transducer * t);
139 static SFST::Transducer * minimize(SFST::Transducer * t);
140 static SFST::Transducer * remove_epsilons(SFST::Transducer * t);
141 static SFST::Transducer * repeat_star(SFST::Transducer * t);
142 static SFST::Transducer * repeat_plus(SFST::Transducer * t);
143 static SFST::Transducer * repeat_n(SFST::Transducer * t,
unsigned int n);
144 static SFST::Transducer * repeat_le_n(SFST::Transducer * t,
unsigned int n);
145 static SFST::Transducer * optionalize(SFST::Transducer * t);
146 static SFST::Transducer * invert(SFST::Transducer * t);
147 static SFST::Transducer * reverse(SFST::Transducer * transducer);
148 static SFST::Transducer * extract_input_language(SFST::Transducer * t);
149 static SFST::Transducer * extract_output_language(SFST::Transducer * t);
150 static std::vector<SFST::Transducer*> extract_path_transducers
151 (SFST::Transducer *t);
152 static void extract_paths
153 (SFST::Transducer * t, hfst::ExtractStringsCb& callback,
int cycles=-1,
154 FdTable<SFST::Character>* fd=NULL,
bool filter_fd=
false);
156 static void extract_random_paths
159 static SFST::Transducer * insert_freely
160 (SFST::Transducer *t ,
const StringPair &symbol_pair);
161 static SFST::Transducer * substitute
162 (SFST::Transducer * t,
String old_symbol,
String new_symbol);
163 static SFST::Transducer * substitute
164 (SFST::Transducer *t,
const StringPair &symbol_pair, SFST::Transducer *tr);
166 static SFST::Transducer * compose(SFST::Transducer * t1,
167 SFST::Transducer * t2);
168 static SFST::Transducer * concatenate(SFST::Transducer * t1,
169 SFST::Transducer * t2);
170 static SFST::Transducer * disjunct(SFST::Transducer * t1,
171 SFST::Transducer * t2);
172 static SFST::Transducer * intersect(SFST::Transducer * t1,
173 SFST::Transducer * t2);
174 static SFST::Transducer * subtract(SFST::Transducer * t1,
175 SFST::Transducer * t2);
176 static std::pair<SFST::Transducer*, SFST::Transducer*> harmonize
177 (SFST::Transducer *t1, SFST::Transducer *t2,
bool unknown_symbols_in_use=
true);
179 static bool are_equivalent(SFST::Transducer * t1, SFST::Transducer * t2);
180 static bool is_cyclic(SFST::Transducer * t);
181 static bool is_automaton(SFST::Transducer * t);
183 static FdTable<SFST::Character>* get_flag_diacritics(SFST::Transducer * t);
185 static void print_test(SFST::Transducer *t);
186 static void print_alphabet(SFST::Transducer *t);
188 static unsigned int get_biggest_symbol_number(SFST::Transducer * t);
190 static StringVector get_symbol_vector(SFST::Transducer * t);
192 static std::map<std::string, unsigned int> get_symbol_map(SFST::Transducer * t);
194 static SFST::Transducer * disjunct(SFST::Transducer * t,
const StringPairVector &spv);
198 float get_profile_seconds();
199 static unsigned int number_of_states(SFST::Transducer *t);
200 static unsigned int number_of_arcs(SFST::Transducer *t);
202 static StringSet get_alphabet(SFST::Transducer *t);
203 static void insert_to_alphabet(SFST::Transducer *t,
const std::string &symbol);
204 static void remove_from_alphabet
205 (SFST::Transducer *t,
const std::string &symbol);
206 static unsigned int get_symbol_number(SFST::Transducer *t,
207 const std::string &symbol);
210 static void initialize_alphabet(SFST::Transducer *t);
211 static SFST::Transducer * expand_arcs(SFST::Transducer * t, StringSet &unknown);
213 static void expand_node( SFST::Transducer *t, SFST::Node *origin, SFST::Label &l,
214 SFST::Node *target, hfst::StringSet &s );
216 ( SFST::Transducer *t, SFST::Node *node,
217 hfst::StringSet &new_symbols, std::set<SFST::Node*> &visited_nodes );
218 static void expand(SFST::Transducer *t, hfst::StringSet &new_symbols);
std::pair< String, String > StringPair
A symbol pair in a transition.
Definition: HfstSymbolDefs.h:71
std::string String
A UTF-8 symbol in a transition.
Definition: HfstSymbolDefs.h:60
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.