21 #ifndef FST_SCRIPT_PRINT_IMPL_H_ 22 #define FST_SCRIPT_PRINT_IMPL_H_ 34 #include <string_view> 45 using Label =
typename Arc::Label;
50 bool accept,
bool show_weight_one,
51 std::string_view field_separator,
52 std::string_view missing_symbol =
"")
58 show_weight_one_(show_weight_one),
59 sep_(field_separator),
60 missing_symbol_(missing_symbol) {}
63 void Print(std::ostream &ostrm, std::string_view dest) {
64 dest_ = std::string(dest);
65 const auto start = fst_.
Start();
68 PrintState(ostrm, start);
70 const auto s = siter.Value();
71 if (s != start) PrintState(ostrm, s);
78 std::string symbol = syms->
Find(
id);
80 if (missing_symbol_.empty()) {
81 FSTERROR() <<
"FstPrinter: Integer " <<
id 82 <<
" is not mapped to any textual symbol" 83 <<
", symbol table = " << syms->
Name()
84 <<
", destination = " << dest_;
87 symbol = missing_symbol_;
92 return std::to_string(
id);
96 std::string FormatStateId(
StateId s)
const {
return FormatId(s, ssyms_); }
98 std::string FormatILabel(
Label l)
const {
return FormatId(l, isyms_); }
100 std::string FormatOLabel(
Label l)
const {
return FormatId(l, osyms_); }
102 void PrintState(std::ostream &ostrm,
StateId s)
const {
105 const auto &arc = aiter.Value();
106 ostrm << FormatStateId(s) << sep_ << FormatStateId(arc.nextstate)
107 << sep_ << FormatILabel(arc.ilabel);
109 ostrm << sep_ << FormatOLabel(arc.olabel);
111 if (show_weight_one_ || arc.weight != Weight::One()) {
112 ostrm << sep_ << arc.weight;
117 const auto weight = fst_.
Final(s);
118 if (weight != Weight::Zero() || !output) {
119 ostrm << FormatStateId(s);
120 if (show_weight_one_ || weight != Weight::One()) {
121 ostrm << sep_ << weight;
133 bool show_weight_one_;
135 std::string missing_symbol_;
144 #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, std::string_view dest)
virtual StateId Start() const =0
FstPrinter(const Fst< Arc > &fst, const SymbolTable *isyms, const SymbolTable *osyms, const SymbolTable *ssyms, bool accept, bool show_weight_one, std::string_view field_separator, std::string_view missing_symbol="")
typename Arc::Label Label
typename Arc::Weight Weight
std::string Find(int64_t key) const
constexpr uint64_t kAcceptor