21 #ifndef FST_SCRIPT_PRINT_IMPL_H_ 22 #define FST_SCRIPT_PRINT_IMPL_H_ 40 using Label =
typename Arc::Label;
45 bool accept,
bool show_weight_one,
46 const std::string &field_separator,
47 const std::string &missing_symbol =
"")
53 show_weight_one_(show_weight_one),
54 sep_(field_separator),
55 missing_symbol_(missing_symbol) {}
58 void Print(std::ostream &ostrm,
const std::string &dest) {
60 const auto start = fst_.
Start();
63 PrintState(ostrm, start);
65 const auto s = siter.Value();
66 if (s != start) PrintState(ostrm, s);
73 std::string symbol = syms->
Find(
id);
75 if (missing_symbol_.empty()) {
76 FSTERROR() <<
"FstPrinter: Integer " <<
id 77 <<
" is not mapped to any textual symbol" 78 <<
", symbol table = " << syms->
Name()
79 <<
", destination = " << dest_;
82 symbol = missing_symbol_;
87 return std::to_string(
id);
91 std::string FormatStateId(
StateId s)
const {
return FormatId(s, ssyms_); }
93 std::string FormatILabel(
Label l)
const {
return FormatId(l, isyms_); }
95 std::string FormatOLabel(
Label l)
const {
return FormatId(l, osyms_); }
97 void PrintState(std::ostream &ostrm,
StateId s)
const {
100 const auto &arc = aiter.Value();
101 ostrm << FormatStateId(s) << sep_ << FormatStateId(arc.nextstate)
102 << sep_ << FormatILabel(arc.ilabel);
104 ostrm << sep_ << FormatOLabel(arc.olabel);
106 if (show_weight_one_ || arc.weight != Weight::One()) {
107 ostrm << sep_ << arc.weight;
112 const auto weight = fst_.
Final(s);
113 if (weight != Weight::Zero() || !output) {
114 ostrm << FormatStateId(s);
115 if (show_weight_one_ || weight != Weight::One()) {
116 ostrm << sep_ << weight;
128 bool show_weight_one_;
130 std::string missing_symbol_;
139 #endif // FST_SCRIPT_PRINT_IMPL_H_ const std::string & Name() const
typename Arc::StateId StateId
virtual Weight Final(StateId) const =0
void Print(std::ostream &ostrm, const std::string &dest)
virtual StateId Start() const =0
typename Arc::Label Label
typename Arc::Weight Weight
std::string Find(int64_t key) const
FstPrinter(const Fst< Arc > &fst, const SymbolTable *isyms, const SymbolTable *osyms, const SymbolTable *ssyms, bool accept, bool show_weight_one, const std::string &field_separator, const std::string &missing_symbol="")
constexpr uint64_t kAcceptor