HFST - Helsinki Finite-State Transducer Technology - C++ API  version 3.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MyTransducerLibraryTransducer.h
Go to the documentation of this file.
1 // Copyright (c) 2016 University of Helsinki
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 3 of the License, or (at your option) any later version.
7 // See the file COPYING included with this distribution for more
8 // information.
9 
10 #ifndef _MY_TRANSDUCER_LIBRARY_TRANSDUCER_H_
11 #define _MY_TRANSDUCER_LIBRARY_TRANSDUCER_H_
12 
22 #include "HfstExceptionDefs.h"
23 #include "HfstFlagDiacritics.h"
24 #include "HfstSymbolDefs.h"
25 #include "HfstExtractStrings.h"
26 
27 /* Include all relevant header files of your transducer library here */
28 #ifndef _MY_TRANSDUCER_LIBRARY_LIB_H_
29 #define _MY_TRANSDUCER_LIBRARY_LIB_H_
30 #include "my_transducer_library/MyTransducerLibrary.h"
31 #endif
32 
33 #include <cstdio>
34 #include <string>
35 #include <sstream>
36 #include <iostream>
37 
38 
39 namespace hfst {
40 namespace implementations
41 {
42 
43  /* If your library is written in namespace my_namespace, it must be visible
44  as hfst::implementations::my_namespace */
45  using namespace my_namespace;
46 
57  {
58  private:
59  // you probably need
60  //std::string filename;
61 
62  // if the library uses C FILEs, you probably need this
63  //FILE * input_file;
64 
65  // if the library uses C++ streams, you probably need this
66  //ifstream i_stream;
67  //istream &input_stream;
68 
69  public:
73  MyTransducerLibraryInputStream(const std::string &filename);
76  void close(void);
78  bool is_eof(void);
80  bool is_bad(void);
82  bool is_good(void);
84  bool is_fst(void);
85 
87  char stream_get();
89  void stream_unget(char c);
91  void ignore(unsigned int n);
92 
95  bool set_implementation_specific_header_data
96  (StringPairVector &data, unsigned int index);
97 
99  MyFst * read_transducer();
100 
101  };
102 
113  {
114  private:
115  // you probably need this
116  //std::string filename;
117 
118  // if the library uses C FILEs, you probably need this
119  //FILE *ofile;
120 
121  // if the library uses C++ streams, you probably need this
122  //ofstream o_stream;
123  //ostream &output_stream;
124 
125  public:
129  MyTransducerLibraryOutputStream(const std::string &filename);
132  void close(void);
134  void write(const char &c);
135 
138  void append_implementation_specific_header_data
139  (std::vector<char> &header, MyFst *t);
140 
142  void write_transducer(MyFst * transducer);
143  };
144 
151  {
152  public:
154  static MyFst * create_empty_transducer(void);
156  static MyFst * create_epsilon_transducer(void);
159  static MyFst * define_transducer(const std::string &symbol);
162  static MyFst * define_transducer
163  (const std::string &isymbol, const std::string &osymbol);
166  static MyFst * define_transducer(const StringPairVector &spv);
170  static MyFst * define_transducer
171  (const StringPairSet &sps, bool cyclic=false);
174  static MyFst * define_transducer(const std::vector<StringPairSet> &spsv);
175 
177  static MyFst * copy(MyFst * t);
180  static MyFst * determinize(MyFst * t);
182  static MyFst * minimize(MyFst * t);
185  static MyFst * remove_epsilons(MyFst * t);
186 
189  static MyFst * repeat_star(MyFst * t);
192  static MyFst * repeat_plus(MyFst * t);
195  static MyFst * repeat_n(MyFst * t, unsigned int n);
198  static MyFst * repeat_le_n(MyFst * t, unsigned int n);
199 
202  static MyFst * optionalize(MyFst * t);
205  static MyFst * invert(MyFst * t);
208  static MyFst * reverse(MyFst * t);
209 
212  static MyFst * extract_input_language(MyFst * t);
215  static MyFst * extract_output_language(MyFst * t);
218  static std::vector<MyFst*> extract_paths(MyFst *t);
220  static void extract_paths
221  (MyFst * t, hfst::ExtractStringsCb& callback,
222  int cycles=-1, FdTable<unsigned int>* fd=NULL, bool filter_fd=false);
223 
228  static MyFst * insert_freely(MyFst *t , const StringPair &symbol_pair);
231  static MyFst * substitute
232  (MyFst * t, String old_symbol, String new_symbol);
236  static MyFst * substitute
237  (MyFst *t, const StringPair &symbol_pair, MyFst *tr);
238 
242  static MyFst * compose(MyFst * t1, MyFst * t2);
245  static MyFst * concatenate(MyFst * t1, MyFst * t2);
248  static MyFst * disjunct(MyFst * t1, MyFst * t2);
251  static MyFst * intersect(MyFst * t1, MyFst * t2);
254  static MyFst * subtract(MyFst * t1, MyFst * t2);
255 
272  static std::pair<MyFst*, MyFst*> harmonize
273  (MyFst *t1, MyFst *t2, bool unknown_symbols_in_use=true);
274 
276  static bool are_equivalent(MyFst * t1, MyFst * t2);
278  static bool is_cyclic(MyFst * t);
279 
282  static FdTable<unsigned int>* get_flag_diacritics(MyFst * t);
283 
285  static MyFst * remove_from_alphabet(MyFst *t, const std::string &symbol);
286 
288  static MyFst * disjunct(MyFst * t, const StringPairVector &spv);
289 
292  static StringPairSet get_symbol_pairs(MyFst *t);
293 
295  static unsigned int number_of_states(MyFst *t);
296 
297  // you probably need also these functions
298  protected:
304  static void initialize_alphabet(MyFst *t);
306  static StringSet get_alphabet(MyFst *t);
307 
308  };
309 
310 
311 } }
312 
313 
314 #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:150
std::pair< String, String > StringPair
A symbol pair in a transition.
Definition: HfstSymbolDefs.h:70
std::string String
A UTF-8 symbol in a transition.
Definition: HfstSymbolDefs.h:59
std::vector< std::pair< std::string, std::string > > StringPairVector
A vector of string pairs.
Definition: HfstDataTypes.h:105
A file for exceptions.
A skeleton class for writing a new type of binary transducers to a stream.
Definition: MyTransducerLibraryTransducer.h:112
Class declarations for flag diacritic handling.
A skeleton class for reading a new type of binary transducers from a stream.
Definition: MyTransducerLibraryTransducer.h:56
std::set< StringPair > StringPairSet
A set of symbol pairs used in substituting symbol pairs and in rule functions.
Definition: HfstSymbolDefs.h:82
Typedefs and functions for symbols, symbol pairs and sets of symbols.