HFST - Helsinki Finite-State Transducer Technology API  version 3.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MyTransducerLibraryTransducer.h
Go to the documentation of this file.
1 // This program is free software: you can redistribute it and/or modify
2 // it under the terms of the GNU General Public License as published by
3 // the Free Software Foundation, version 3 of the License.
4 //
5 // This program is distributed in the hope that it will be useful,
6 // but WITHOUT ANY WARRANTY; without even the implied warranty of
7 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 // GNU General Public License for more details.
9 //
10 // You should have received a copy of the GNU General Public License
11 // along with this program. If not, see <http://www.gnu.org/licenses/>.
12 
13 #ifndef _MY_TRANSDUCER_LIBRARY_TRANSDUCER_H_
14 #define _MY_TRANSDUCER_LIBRARY_TRANSDUCER_H_
15 
25 #include "HfstExceptionDefs.h"
26 #include "HfstFlagDiacritics.h"
27 #include "HfstSymbolDefs.h"
28 #include "HfstExtractStrings.h"
29 
30 /* Include all relevant header files of your transducer library here */
31 #ifndef _MY_TRANSDUCER_LIBRARY_LIB_H_
32 #define _MY_TRANSDUCER_LIBRARY_LIB_H_
33 #include "my_transducer_library/MyTransducerLibrary.h"
34 #endif
35 
36 #include <cstdio>
37 #include <string>
38 #include <sstream>
39 #include <iostream>
40 
41 
42 namespace hfst {
43 namespace implementations
44 {
45 
46  /* If your library is written in namespace my_namespace, it must be visible
47  as hfst::implementations::my_namespace */
48  using namespace my_namespace;
49 
60  {
61  private:
62  // you probably need
63  //std::string filename;
64 
65  // if the library uses C FILEs, you probably need this
66  //FILE * input_file;
67 
68  // if the library uses C++ streams, you probably need this
69  //ifstream i_stream;
70  //istream &input_stream;
71 
72  public:
76  MyTransducerLibraryInputStream(const std::string &filename);
79  void close(void);
81  bool is_eof(void);
83  bool is_bad(void);
85  bool is_good(void);
87  bool is_fst(void);
88 
90  char stream_get();
92  void stream_unget(char c);
94  void ignore(unsigned int n);
95 
98  bool set_implementation_specific_header_data
99  (StringPairVector &data, unsigned int index);
100 
102  MyFst * read_transducer();
103 
104  };
105 
116  {
117  private:
118  // you probably need this
119  //std::string filename;
120 
121  // if the library uses C FILEs, you probably need this
122  //FILE *ofile;
123 
124  // if the library uses C++ streams, you probably need this
125  //ofstream o_stream;
126  //ostream &output_stream;
127 
128  public:
132  MyTransducerLibraryOutputStream(const std::string &filename);
135  void close(void);
137  void write(const char &c);
138 
141  void append_implementation_specific_header_data
142  (std::vector<char> &header, MyFst *t);
143 
145  void write_transducer(MyFst * transducer);
146  };
147 
154  {
155  public:
157  static MyFst * create_empty_transducer(void);
159  static MyFst * create_epsilon_transducer(void);
162  static MyFst * define_transducer(const std::string &symbol);
165  static MyFst * define_transducer
166  (const std::string &isymbol, const std::string &osymbol);
169  static MyFst * define_transducer(const StringPairVector &spv);
173  static MyFst * define_transducer
174  (const StringPairSet &sps, bool cyclic=false);
177  static MyFst * define_transducer(const std::vector<StringPairSet> &spsv);
178 
180  static MyFst * copy(MyFst * t);
183  static MyFst * determinize(MyFst * t);
185  static MyFst * minimize(MyFst * t);
188  static MyFst * remove_epsilons(MyFst * t);
189 
192  static MyFst * repeat_star(MyFst * t);
195  static MyFst * repeat_plus(MyFst * t);
198  static MyFst * repeat_n(MyFst * t, unsigned int n);
201  static MyFst * repeat_le_n(MyFst * t, unsigned int n);
202 
205  static MyFst * optionalize(MyFst * t);
208  static MyFst * invert(MyFst * t);
211  static MyFst * reverse(MyFst * t);
212 
215  static MyFst * extract_input_language(MyFst * t);
218  static MyFst * extract_output_language(MyFst * t);
221  static std::vector<MyFst*> extract_paths(MyFst *t);
223  static void extract_paths
224  (MyFst * t, hfst::ExtractStringsCb& callback,
225  int cycles=-1, FdTable<unsigned int>* fd=NULL, bool filter_fd=false);
226 
231  static MyFst * insert_freely(MyFst *t , const StringPair &symbol_pair);
234  static MyFst * substitute
235  (MyFst * t, String old_symbol, String new_symbol);
239  static MyFst * substitute
240  (MyFst *t, const StringPair &symbol_pair, MyFst *tr);
241 
245  static MyFst * compose(MyFst * t1, MyFst * t2);
248  static MyFst * concatenate(MyFst * t1, MyFst * t2);
251  static MyFst * disjunct(MyFst * t1, MyFst * t2);
254  static MyFst * intersect(MyFst * t1, MyFst * t2);
257  static MyFst * subtract(MyFst * t1, MyFst * t2);
258 
275  static std::pair<MyFst*, MyFst*> harmonize
276  (MyFst *t1, MyFst *t2, bool unknown_symbols_in_use=true);
277 
279  static bool are_equivalent(MyFst * t1, MyFst * t2);
281  static bool is_cyclic(MyFst * t);
282 
285  static FdTable<unsigned int>* get_flag_diacritics(MyFst * t);
286 
288  static MyFst * remove_from_alphabet(MyFst *t, const std::string &symbol);
289 
291  static MyFst * disjunct(MyFst * t, const StringPairVector &spv);
292 
295  static StringPairSet get_symbol_pairs(MyFst *t);
296 
298  static unsigned int number_of_states(MyFst *t);
299 
300  // you probably need also these functions
301  protected:
307  static void initialize_alphabet(MyFst *t);
309  static StringSet get_alphabet(MyFst *t);
310 
311  };
312 
313 
314 } }
315 
316 
317 #endif // #ifndef _MY_TRANSDUCER_LIBRARY_TRANSDUCER_H_
A skeleton library class that contains operations for a new transducer type that is added under the H...
Definition: MyTransducerLibraryTransducer.h:153
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
A file for exceptions.
A skeleton class for writing a new type of binary transducers to a stream.
Definition: MyTransducerLibraryTransducer.h:115
Class declarations for flag diacritic handling.
A skeleton class for reading a new type of binary transducers from a stream.
Definition: MyTransducerLibraryTransducer.h:59
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.