20 #ifndef FST_EXTENSIONS_FAR_PRINT_STRINGS_H_ 21 #define FST_EXTENSIONS_FAR_PRINT_STRINGS_H_ 40 TokenType token_type,
const std::string &begin_key,
41 const std::string &end_key,
bool print_key,
bool print_weight,
42 const std::string &symbols_source,
bool initial_symbols,
43 int32_t generate_sources,
const std::string &source_prefix,
44 const std::string &source_suffix) {
45 std::unique_ptr<const SymbolTable> syms;
46 if (!symbols_source.empty()) {
51 LOG(ERROR) <<
"PrintStrings: Error reading symbol table " 56 if (!begin_key.empty()) reader.
Find(begin_key);
59 for (
int i = 1; !reader.
Done(); reader.
Next(), ++i) {
60 const auto &key = reader.
GetKey();
61 if (!end_key.empty() && end_key < key)
break;
69 if (i == 1 && initial_symbols && !syms &&
fst->InputSymbols()) {
70 syms.reset(
fst->InputSymbols()->Copy());
73 VLOG(2) <<
"Handling key: " << key;
75 syms ? syms.get() :
fst->InputSymbols(),
80 std::cout << key << FST_FLAGS_far_field_separator[0];
83 std::cout << FST_FLAGS_far_field_separator[0]
86 std::cout << std::endl;
88 std::stringstream sstrm;
89 if (generate_sources) {
91 sstrm << std::right << std::setw(generate_sources) << i;
94 if (nrep > 0) sstrm <<
"." << nrep;
97 source = source_prefix + sstrm.str() + source_suffix;
98 std::ofstream ostrm(source);
100 LOG(ERROR) <<
"PrintStrings: Can't open file: " << source;
111 #endif // FST_EXTENSIONS_FAR_PRINT_STRINGS_H_ virtual const std::string & GetKey() const =0
virtual bool Done() const =0
DECLARE_string(far_field_separator)
virtual const Fst< Arc > * GetFst() const =0
static SymbolTable * ReadText(std::istream &strm, std::string_view name, const SymbolTableTextOptions &opts=SymbolTableTextOptions())
void ShortestDistance(const Fst< Arc > &fst, std::vector< typename Arc::Weight > *distance, const ShortestDistanceOptions< Arc, Queue, ArcFilter > &opts)
virtual bool Find(std::string_view key)=0
void PrintStrings(FarReader< Arc > &reader, FarEntryType entry_type, TokenType token_type, const std::string &begin_key, const std::string &end_key, bool print_key, bool print_weight, const std::string &symbols_source, bool initial_symbols, int32_t generate_sources, const std::string &source_prefix, const std::string &source_suffix)