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