HFST - Helsinki Finite-State Transducer Technology API  version 3.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HfstOlTransducer.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 _HFST_OL_TRANSDUCER_H_
14 #define _HFST_OL_TRANSDUCER_H_
15 
16 #include <iostream>
17 #include <fstream>
18 #include "../HfstExceptionDefs.h"
19 #include "../HfstFlagDiacritics.h"
20 #include "../HfstExtractStrings.h"
21 #include "optimized-lookup/transducer.h"
22 
27 namespace hfst { namespace implementations
28 {
29  using std::ostream;
30  using std::ofstream;
31  using std::istream;
32  using std::ifstream;
33  using std::string;
34  ;
35 
36  class HfstOlInputStream
37  {
38  private:
39  std::string filename;
40  ifstream i_stream;
41  istream &input_stream;
42  bool weighted;
43  void skip_identifier_version_3_0(void);
44  void skip_hfst_header(void);
45  public:
46  HfstOlInputStream(bool weighted);
47  HfstOlInputStream(const std::string &filename, bool weighted);
48  void open(void);
49  void close(void);
50  bool is_open(void) const;
51  bool is_eof(void) const;
52  bool is_bad(void) const;
53  bool is_good(void) const;
54  bool is_fst(void) const;
55 
56  char stream_get();
57  short stream_get_short();
58  void stream_unget(char c);
59  void ignore(unsigned int n);
60 
61  bool operator() (void) const;
62  hfst_ol::Transducer * read_transducer(bool has_header);
63 
64  // 1=unweighted, 2=weighted
65  static int is_fst(FILE * f);
66  static int is_fst(istream &s);
67  };
68 
69  class HfstOlOutputStream
70  {
71  private:
72  std::string filename;
73  ofstream o_stream;
74  ostream &output_stream;
75  bool weighted;
76  public:
77  HfstOlOutputStream(bool weighted);
78  HfstOlOutputStream(const std::string &filename, bool weighted);
79  void open(void);
80  void close(void);
81  void write(const char &c);
82  void write_transducer(hfst_ol::Transducer * transducer);
83  };
84 
85  class HfstOlTransducer
86  {
87  public:
88  static hfst_ol::Transducer * create_empty_transducer(bool weighted);
89 
90  static bool is_cyclic(hfst_ol::Transducer* t);
91 
92  static void extract_paths
93  (hfst_ol::Transducer * t, hfst::ExtractStringsCb& callback,
94  int cycles=-1, const FdTable<hfst_ol::SymbolNumber>* fd=NULL,
95  bool filter_fd=false);
96  static const FdTable<hfst_ol::SymbolNumber>*
97  get_flag_diacritics(hfst_ol::Transducer* t);
98  static StringSet get_alphabet(hfst_ol::Transducer * t);
99 
100 
101  };
102 
103 } }
104 
105 #endif
A compiled transducer format, suitable for fast lookup operations.
Definition: 3831_transducer.h:804