FST  openfst-1.7.2
OpenFst Library
encode.h
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 
4 #ifndef FST_SCRIPT_ENCODE_H_
5 #define FST_SCRIPT_ENCODE_H_
6 
7 #include <memory>
8 #include <string>
9 #include <tuple>
10 #include <utility>
11 
12 #include <fst/encode.h>
14 #include <fst/script/fst-class.h>
15 
16 namespace fst {
17 namespace script {
18 
19 using EncodeArgs1 = std::tuple<MutableFstClass *, uint32, bool, const string &>;
20 
21 template <class Arc>
22 void Encode(EncodeArgs1 *args) {
23  MutableFst<Arc> *fst = std::get<0>(*args)->GetMutableFst<Arc>();
24  const string &coder_fname = std::get<3>(*args);
25  // If true, reuse encode from disk. If false, make a new encoder and just use
26  // the filename argument as the destination state.
27  std::unique_ptr<EncodeMapper<Arc>> encoder(
28  std::get<2>(*args) ? EncodeMapper<Arc>::Read(coder_fname, ENCODE)
29  : new EncodeMapper<Arc>(std::get<1>(*args), ENCODE));
30  Encode(fst, encoder.get());
31  if (!std::get<2>(*args)) encoder->Write(coder_fname);
32 }
33 
34 using EncodeArgs2 = std::pair<MutableFstClass *, EncodeMapperClass *>;
35 
36 template <class Arc>
37 void Encode(EncodeArgs2 *args) {
38  MutableFst<Arc> *fst = std::get<0>(*args)->GetMutableFst<Arc>();
39  EncodeMapper<Arc> *encoder = std::get<1>(*args)->GetEncodeMapper<Arc>();
40  Encode(fst, encoder);
41 }
42 
43 void Encode(MutableFstClass *fst, uint32 flags, bool reuse_encoder,
44  const string &coder_fname);
45 
46 void Encode(MutableFstClass *fst, EncodeMapperClass *encoder);
47 
48 } // namespace script
49 } // namespace fst
50 
51 #endif // FST_SCRIPT_ENCODE_H_
void Encode(EncodeArgs1 *args)
Definition: encode.h:22
std::tuple< MutableFstClass *, uint32, bool, const string & > EncodeArgs1
Definition: encode.h:19
std::pair< MutableFstClass *, EncodeMapperClass * > EncodeArgs2
Definition: encode.h:34
uint32_t uint32
Definition: types.h:31