18 #ifndef FST_EXTENSIONS_FAR_INFO_H_ 19 #define FST_EXTENSIONS_FAR_INFO_H_ 37 #include <string_view> 45 siter.Next(), ++(*nstate)) {
47 for (; !aiter.Done(); aiter.Next(), ++(*narc)) {
49 if (fst.
Final(siter.Value()) != Arc::Weight::Zero()) ++(*nfinal);
73 void GetInfo(
const std::vector<std::string> &sources,
74 std::string_view begin_key, std::string_view end_key,
79 LOG(ERROR) <<
"GetFarInfo: failed to create far reader.";
82 if (!begin_key.empty()) reader->Find(begin_key);
84 for (; !reader->Done(); reader->Next()) {
85 const auto &
key = reader->GetKey();
86 if (!end_key.empty() && end_key <
key)
break;
88 const auto *
fst = reader->GetFst();
109 void Info(
const std::vector<std::string> &sources, std::string_view begin_key,
110 std::string_view end_key,
const bool list_fsts) {
112 GetInfo<Arc>(sources, begin_key, end_key, list_fsts, &info);
114 std::cout << std::left << std::setw(50) <<
"far type" << info.
far_type 116 std::cout << std::left << std::setw(50) <<
"arc type" << Arc::Type()
118 std::cout << std::left << std::setw(50) <<
"fst type";
121 if (iter != info.
fst_types.begin()) std::cout <<
",";
125 std::cout << std::left << std::setw(50) <<
"# of FSTs" << info.
nfst <<
'\n';
126 std::cout << std::left << std::setw(50) <<
"total # of states" 128 std::cout << std::left << std::setw(50) <<
"total # of arcs" << info.
narc 130 std::cout << std::left << std::setw(50) <<
"total # of final states" 139 for (
const auto &key_info : info.
key_infos) {
140 if (key_info.key.size() + 2 > wkey) wkey = key_info.key.size() + 2;
141 if (key_info.type.size() + 2 > wtype) wtype = key_info.type.size() + 2;
142 if (ceil(log10(key_info.nstate)) + 2 > wnstate) {
143 wnstate = ceil(log10(key_info.nstate)) + 2;
145 if (ceil(log10(key_info.narc)) + 2 > wnarc) {
146 wnarc = ceil(log10(key_info.narc)) + 2;
148 if (ceil(log10(key_info.nfinal)) + 2 > wnfinal) {
149 wnfinal = ceil(log10(key_info.nfinal)) + 2;
152 std::cout << std::left << std::setw(wkey) <<
"key" << std::setw(wtype)
153 <<
"type" << std::right << std::setw(wnstate) <<
"# of states" 154 << std::setw(wnarc) <<
"# of arcs" << std::setw(wnfinal)
155 <<
"# of final states" <<
'\n';
156 for (
const auto &key_info : info.
key_infos) {
157 std::cout << std::left << std::setw(wkey) << key_info.key
158 << std::setw(wtype) << key_info.type << std::right
159 << std::setw(wnstate) << key_info.nstate << std::setw(wnarc)
160 << key_info.narc << std::setw(wnfinal) << key_info.nfinal
168 #endif // FST_EXTENSIONS_FAR_INFO_H_
std::string GetFarTypeString(FarType far_type)
void AccumulateStatesAndArcs(const Fst< Arc > &fst, size_t *nstate, size_t *narc, size_t *nfinal)
virtual Weight Final(StateId) const =0
void GetInfo(const std::vector< std::string > &sources, std::string_view begin_key, std::string_view end_key, const bool list_fsts, FarInfoData *far_info)
void Info(const std::vector< std::string > &sources, std::string_view begin_key, std::string_view end_key, const bool list_fsts)
std::set< std::string > fst_types
std::vector< KeyInfo > key_infos