FST  openfst-1.8.3
OpenFst Library
print.h
Go to the documentation of this file.
1 // Copyright 2005-2024 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/fst.h>
26 #include <fst/symbol-table.h>
27 #include <fst/script/fst-class.h>
28 #include <fst/script/print-impl.h>
29 #include <string_view>
30 
31 DECLARE_string(fst_field_separator);
32 
33 namespace fst {
34 namespace script {
35 
36 // Note: it is safe to pass these strings as references because this struct is
37 // only used to pass them deeper in the call graph. Be sure you understand why
38 // this is so before using this struct for anything else!
39 struct FstPrintArgs {
40  const FstClass &fst;
44  const bool accept;
45  const bool show_weight_one;
46  std::ostream &ostrm;
47  const std::string &dest;
48  const std::string &sep;
49  const std::string &missing_symbol;
50 };
51 
52 template <class Arc>
53 void Print(FstPrintArgs *args) {
54  const Fst<Arc> &fst = *args->fst.GetFst<Arc>();
55  FstPrinter<Arc> fstprinter(fst, args->isyms, args->osyms, args->ssyms,
56  args->accept, args->show_weight_one, args->sep,
57  args->missing_symbol);
58  fstprinter.Print(args->ostrm, args->dest);
59 }
60 
61 void Print(const FstClass &fst, std::ostream &ostrm, const std::string &dest,
62  const SymbolTable *isyms = nullptr,
63  const SymbolTable *osyms = nullptr,
64  const SymbolTable *ssyms = nullptr, bool accept = true,
65  bool show_weight_one = true, const std::string &missing_sym = "");
66 
67 // TODO(kbg,2019-09-01): Deprecated.
68 void PrintFst(const FstClass &fst, std::ostream &ostrm, const std::string &dest,
69  const SymbolTable *isyms, const SymbolTable *osyms,
70  const SymbolTable *ssyms, bool accept, bool show_weight_one,
71  const std::string &missing_sym = "");
72 
73 // The same, but with more sensible defaults, and for arc-templated FSTs only.
74 // TODO(kbg,2019-09-01): Deprecated.
75 template <class Arc>
76 void PrintFst(const Fst<Arc> &fst, std::ostream &ostrm,
77  std::string_view dest = "", const SymbolTable *isyms = nullptr,
78  const SymbolTable *osyms = nullptr,
79  const SymbolTable *ssyms = nullptr) {
80  const std::string sep = FST_FLAGS_fst_field_separator.substr(0, 1);
81  FstPrinter<Arc> fstprinter(fst, isyms, osyms, ssyms, true, true, sep);
82  fstprinter.Print(ostrm, dest);
83 }
84 
85 } // namespace script
86 } // namespace fst
87 
88 #endif // FST_SCRIPT_PRINT_H_
const Fst< Arc > * GetFst() const
Definition: fst-class.h:401
const std::string & dest
Definition: print.h:47
const SymbolTable * osyms
Definition: print.h:42
const bool show_weight_one
Definition: print.h:45
const bool accept
Definition: print.h:44
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:41
const FstClass & fst
Definition: print.h:40
const std::string & missing_symbol
Definition: print.h:49
void Print(std::ostream &ostrm, std::string_view dest)
Definition: print-impl.h:63
const SymbolTable * isyms
Definition: print.h:41
std::ostream & ostrm
Definition: print.h:46
const std::string & sep
Definition: print.h:48
void Print(FstPrintArgs *args)
Definition: print.h:53
const SymbolTable * ssyms
Definition: print.h:43