FST  openfst-1.7.2
OpenFst Library
print.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_PRINT_H_
5 #define FST_SCRIPT_PRINT_H_
6 
7 #include <ostream>
8 
9 #include <fst/flags.h>
10 #include <fst/script/fst-class.h>
11 #include <fst/script/print-impl.h>
12 
13 DECLARE_string(fst_field_separator);
14 
15 namespace fst {
16 namespace script {
17 
18 // Note: it is safe to pass these strings as references because
19 // this struct is only used to pass them deeper in the call graph.
20 // Be sure you understand why this is so before using this struct
21 // for anything else!
23  const FstClass &fst;
27  const bool accept;
28  const bool show_weight_one;
29  std::ostream *ostrm;
30  const string &dest;
31  const string &sep; // NOLINT
32  const string &missing_symbol;
33 
34  FstPrinterArgs(const FstClass &fst, const SymbolTable *isyms,
35  const SymbolTable *osyms, const SymbolTable *ssyms,
36  bool accept, bool show_weight_one, std::ostream *ostrm,
37  const string &dest, const string &sep,
38  const string &missing_sym = "")
39  : fst(fst),
40  isyms(isyms),
41  osyms(osyms),
42  ssyms(ssyms),
43  accept(accept),
44  show_weight_one(show_weight_one),
45  ostrm(ostrm),
46  dest(dest),
47  sep(sep),
48  missing_symbol(missing_sym) {}
49 };
50 
51 template <class Arc>
52 void PrintFst(FstPrinterArgs *args) {
53  const Fst<Arc> &fst = *(args->fst.GetFst<Arc>());
54  FstPrinter<Arc> fstprinter(fst, args->isyms, args->osyms, args->ssyms,
55  args->accept, args->show_weight_one, args->sep,
56  args->missing_symbol);
57  fstprinter.Print(args->ostrm, args->dest);
58 }
59 
60 void PrintFst(const FstClass &fst, std::ostream &ostrm, const string &dest,
61  const SymbolTable *isyms, const SymbolTable *osyms,
62  const SymbolTable *ssyms, bool accept, bool show_weight_one,
63  const string &missing_sym = "");
64 
65 // The same, but with more sensible defaults.
66 template <class Arc>
67 void PrintFst(const Fst<Arc> &fst, std::ostream &ostrm, const string &dest = "",
68  const SymbolTable *isyms = nullptr,
69  const SymbolTable *osyms = nullptr,
70  const SymbolTable *ssyms = nullptr) {
71  const string sep = FLAGS_fst_field_separator.substr(0, 1);
72  FstPrinter<Arc> fstprinter(fst, isyms, osyms, ssyms, true, true, sep);
73  fstprinter.Print(&ostrm, dest);
74 }
75 
76 } // namespace script
77 } // namespace fst
78 
79 #endif // FST_SCRIPT_PRINT_H_
const FstClass & fst
Definition: print.h:23
const Fst< Arc > * GetFst() const
Definition: fst-class.h:357
const SymbolTable * osyms
Definition: print.h:25
const SymbolTable * isyms
Definition: print.h:24
FstPrinterArgs(const FstClass &fst, const SymbolTable *isyms, const SymbolTable *osyms, const SymbolTable *ssyms, bool accept, bool show_weight_one, std::ostream *ostrm, const string &dest, const string &sep, const string &missing_sym="")
Definition: print.h:34
const SymbolTable * ssyms
Definition: print.h:26
void PrintFst(FstPrinterArgs *args)
Definition: print.h:52
const string & missing_symbol
Definition: print.h:32
void Print(std::ostream *ostrm, const string &dest)
Definition: print-impl.h:46
std::ostream * ostrm
Definition: print.h:29
const string & sep
Definition: print.h:31
const bool show_weight_one
Definition: print.h:28
const string & dest
Definition: print.h:30