FST  openfst-1.8.2.post1
OpenFst Library
print.h
Go to the documentation of this file.
1 // Copyright 2005-2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 
18 #ifndef FST_SCRIPT_PRINT_H_
19 #define FST_SCRIPT_PRINT_H_
20 
21 #include <ostream>
22 #include <string>
23 
24 #include <fst/flags.h>
25 #include <fst/script/fst-class.h>
26 #include <fst/script/print-impl.h>
27 
28 DECLARE_string(fst_field_separator);
29 
30 namespace fst {
31 namespace script {
32 
33 // Note: it is safe to pass these strings as references because this struct is
34 // only used to pass them deeper in the call graph. Be sure you understand why
35 // this is so before using this struct for anything else!
36 struct FstPrintArgs {
37  const FstClass &fst;
41  const bool accept;
42  const bool show_weight_one;
43  std::ostream &ostrm;
44  const std::string &dest;
45  const std::string &sep;
46  const std::string &missing_symbol;
47 };
48 
49 template <class Arc>
50 void Print(FstPrintArgs *args) {
51  const Fst<Arc> &fst = *args->fst.GetFst<Arc>();
52  FstPrinter<Arc> fstprinter(fst, args->isyms, args->osyms, args->ssyms,
53  args->accept, args->show_weight_one, args->sep,
54  args->missing_symbol);
55  fstprinter.Print(args->ostrm, args->dest);
56 }
57 
58 void Print(const FstClass &fst, std::ostream &ostrm, const std::string &dest,
59  const SymbolTable *isyms = nullptr,
60  const SymbolTable *osyms = nullptr,
61  const SymbolTable *ssyms = nullptr, bool accept = true,
62  bool show_weight_one = true, const std::string &missing_sym = "");
63 
64 // TODO(kbg,2019-09-01): Deprecated.
65 void PrintFst(const FstClass &fst, std::ostream &ostrm, const std::string &dest,
66  const SymbolTable *isyms, const SymbolTable *osyms,
67  const SymbolTable *ssyms, bool accept, bool show_weight_one,
68  const std::string &missing_sym = "");
69 
70 // The same, but with more sensible defaults, and for arc-templated FSTs only.
71 // TODO(kbg,2019-09-01): Deprecated.
72 template <class Arc>
73 void PrintFst(const Fst<Arc> &fst, std::ostream &ostrm,
74  const std::string &dest = "", const SymbolTable *isyms = nullptr,
75  const SymbolTable *osyms = nullptr,
76  const SymbolTable *ssyms = nullptr) {
77  const std::string sep = FST_FLAGS_fst_field_separator.substr(0, 1);
78  FstPrinter<Arc> fstprinter(fst, isyms, osyms, ssyms, true, true, sep);
79  fstprinter.Print(ostrm, dest);
80 }
81 
82 } // namespace script
83 } // namespace fst
84 
85 #endif // FST_SCRIPT_PRINT_H_
const Fst< Arc > * GetFst() const
Definition: fst-class.h:394
const std::string & dest
Definition: print.h:44
const SymbolTable * osyms
Definition: print.h:39
const bool show_weight_one
Definition: print.h:42
const bool accept
Definition: print.h:41
void PrintFst(const FstClass &fst, std::ostream &ostrm, const std::string &dest, const SymbolTable *isyms, const SymbolTable *osyms, const SymbolTable *ssyms, bool accept, bool show_weight_one, const std::string &missing_sym="")
Definition: print.cc:38
void Print(std::ostream &ostrm, const std::string &dest)
Definition: print-impl.h:58
const FstClass & fst
Definition: print.h:37
const std::string & missing_symbol
Definition: print.h:46
const SymbolTable * isyms
Definition: print.h:38
std::ostream & ostrm
Definition: print.h:43
const std::string & sep
Definition: print.h:45
void Print(FstPrintArgs *args)
Definition: print.h:50
const SymbolTable * ssyms
Definition: print.h:40