49 "Prints out binary FSTs in simple text format.\n\n Usage: ";
51 usage +=
" [binary.fst [text.fst]]\n";
53 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
59 const std::string in_name =
60 (argc > 1 && strcmp(argv[1],
"-") != 0) ? argv[1] :
"";
61 const std::string out_name =
62 (argc > 2 && strcmp(argv[2],
"-") != 0) ? argv[2] :
"";
64 std::unique_ptr<FstClass>
fst(FstClass::Read(in_name));
67 std::string dest =
"standard output";
72 LOG(ERROR) << argv[0] <<
": Open failed, file = " << argv[2];
77 std::ostream &ostrm = fstrm.is_open() ? fstrm : std::cout;
80 std::unique_ptr<const SymbolTable> isyms;
81 if (!FST_FLAGS_isymbols.empty() && !FST_FLAGS_numeric) {
83 SymbolTable::ReadText(FST_FLAGS_isymbols,
84 FST_FLAGS_fst_field_separator));
88 std::unique_ptr<const SymbolTable> osyms;
89 if (!FST_FLAGS_osymbols.empty() && !FST_FLAGS_numeric) {
91 SymbolTable::ReadText(FST_FLAGS_osymbols,
92 FST_FLAGS_fst_field_separator));
96 std::unique_ptr<const SymbolTable> ssyms;
97 if (!FST_FLAGS_ssymbols.empty() && !FST_FLAGS_numeric) {
99 SymbolTable::ReadText(FST_FLAGS_ssymbols,
100 FST_FLAGS_fst_field_separator));
101 if (!ssyms)
return 1;
104 if (!isyms && !FST_FLAGS_numeric && fst->InputSymbols()) {
105 isyms.reset(fst->InputSymbols()->Copy());
108 if (!osyms && !FST_FLAGS_numeric && fst->OutputSymbols()) {
109 osyms.reset(fst->OutputSymbols()->Copy());
112 s::Print(*fst, ostrm, dest, isyms.get(), osyms.get(), ssyms.get(),
113 FST_FLAGS_acceptor, FST_FLAGS_show_weight_one,
114 FST_FLAGS_missing_symbol);
116 if (isyms && !FST_FLAGS_save_isymbols.empty()) {
117 if (!isyms->WriteText(FST_FLAGS_save_isymbols))
return 1;
120 if (osyms && !FST_FLAGS_save_osymbols.empty()) {
121 if (!osyms->WriteText(FST_FLAGS_save_osymbols))
return 1;
void ShowUsage(bool long_usage=true)
#define SET_FLAGS(usage, argc, argv, rmflags)
void Print(FstPrintArgs *args)
int fstprint_main(int argc, char **argv)