6 #ifndef FST_EXTENSIONS_FAR_PRINT_STRINGS_H_ 7 #define FST_EXTENSIONS_FAR_PRINT_STRINGS_H_ 26 const string &begin_key,
const string &end_key,
27 bool print_key,
bool print_weight,
28 const string &symbols_fname,
bool initial_symbols,
29 int32 generate_filenames,
const string &filename_prefix,
30 const string &filename_suffix) {
34 }
else if (far_token_type ==
FTT_BYTE) {
36 }
else if (far_token_type ==
FTT_UTF8) {
39 FSTERROR() <<
"FarPrintStrings: Unknown token type";
42 std::unique_ptr<const SymbolTable> syms;
43 if (!symbols_fname.empty()) {
48 LOG(ERROR) <<
"FarPrintStrings: Error reading symbol table " 54 if (!far_reader)
return;
55 if (!begin_key.empty()) far_reader->Find(begin_key);
58 for (
int i = 1; !far_reader->Done(); far_reader->Next(), ++i) {
59 const auto &key = far_reader->GetKey();
60 if (!end_key.empty() && end_key < key)
break;
67 const auto *
fst = far_reader->GetFst();
68 if (i == 1 && initial_symbols && !syms &&
fst->InputSymbols())
69 syms.reset(
fst->InputSymbols()->Copy());
71 VLOG(2) <<
"Handling key: " << key;
73 syms ? syms.get() :
fst->InputSymbols());
74 string_printer(*
fst, &str);
76 if (print_key) std::cout << key << FLAGS_far_field_separator[0];
80 std::cout << std::endl;
82 std::stringstream sstrm;
83 if (generate_filenames) {
85 sstrm << std::right << std::setw(generate_filenames) << i;
88 if (nrep > 0) sstrm <<
"." << nrep;
91 filename = filename_prefix + sstrm.str() + filename_suffix;
92 std::ofstream ostrm(filename);
94 LOG(ERROR) <<
"FarPrintStrings: Can't open file: " << filename;
105 #endif // FST_EXTENSIONS_FAR_PRINT_STRINGS_H_ void FarPrintStrings(const std::vector< string > &ifilenames, FarEntryType entry_type, FarTokenType far_token_type, const string &begin_key, const string &end_key, bool print_key, bool print_weight, const string &symbols_fname, bool initial_symbols, int32 generate_filenames, const string &filename_prefix, const string &filename_suffix)
DECLARE_string(far_field_separator)
void ShortestDistance(const Fst< Arc > &fst, std::vector< typename Arc::Weight > *distance, const ShortestDistanceOptions< Arc, Queue, ArcFilter > &opts)
static SymbolTable * ReadText(std::istream &strm, const string &name, const SymbolTableTextOptions &opts=SymbolTableTextOptions())