18 #ifndef FST_EXTENSIONS_FAR_INFO_H_ 19 #define FST_EXTENSIONS_FAR_INFO_H_ 37 siter.Next(), ++(*nstate)) {
39 for (; !aiter.Done(); aiter.Next(), ++(*narc)) {
41 if (fst.
Final(siter.Value()) != Arc::Weight::Zero()) ++(*nfinal);
65 void GetInfo(
const std::vector<std::string> &sources,
66 const std::string &begin_key,
const std::string &end_key,
71 LOG(ERROR) <<
"GetFarInfo: failed to create far reader.";
74 if (!begin_key.empty()) reader->Find(begin_key);
76 for (; !reader->Done(); reader->Next()) {
77 const auto &
key = reader->GetKey();
78 if (!end_key.empty() && end_key <
key)
break;
80 const auto *
fst = reader->GetFst();
101 void Info(
const std::vector<std::string> &sources,
const std::string &begin_key,
102 const std::string &end_key,
const bool list_fsts) {
104 GetInfo<Arc>(sources, begin_key, end_key, list_fsts, &info);
106 std::cout << std::left << std::setw(50) <<
"far type" << info.
far_type 108 std::cout << std::left << std::setw(50) <<
"arc type" << Arc::Type()
110 std::cout << std::left << std::setw(50) <<
"fst type";
113 if (iter != info.
fst_types.begin()) std::cout <<
",";
116 std::cout << std::endl;
117 std::cout << std::left << std::setw(50) <<
"# of FSTs" << info.
nfst 119 std::cout << std::left << std::setw(50) <<
"total # of states" 120 << info.
nstate << std::endl;
121 std::cout << std::left << std::setw(50) <<
"total # of arcs" << info.
narc 123 std::cout << std::left << std::setw(50) <<
"total # of final states" 124 << info.
nfinal << std::endl;
132 for (
const auto &key_info : info.
key_infos) {
133 if (key_info.key.size() + 2 > wkey) wkey = key_info.key.size() + 2;
134 if (key_info.type.size() + 2 > wtype) wtype = key_info.type.size() + 2;
135 if (ceil(log10(key_info.nstate)) + 2 > wnstate) {
136 wnstate = ceil(log10(key_info.nstate)) + 2;
138 if (ceil(log10(key_info.narc)) + 2 > wnarc) {
139 wnarc = ceil(log10(key_info.narc)) + 2;
141 if (ceil(log10(key_info.nfinal)) + 2 > wnfinal) {
142 wnfinal = ceil(log10(key_info.nfinal)) + 2;
145 std::cout << std::left << std::setw(wkey) <<
"key" << std::setw(wtype)
146 <<
"type" << std::right << std::setw(wnstate) <<
"# of states" 147 << std::setw(wnarc) <<
"# of arcs" << std::setw(wnfinal)
148 <<
"# of final states" << std::endl;
149 for (
const auto &key_info : info.
key_infos) {
150 std::cout << std::left << std::setw(wkey) << key_info.key
151 << std::setw(wtype) << key_info.type << std::right
152 << std::setw(wnstate) << key_info.nstate << std::setw(wnarc)
153 << key_info.narc << std::setw(wnfinal) << key_info.nfinal
161 #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)
void Info(const std::vector< std::string > &sources, const std::string &begin_key, const std::string &end_key, const bool list_fsts)
void GetInfo(const std::vector< std::string > &sources, const std::string &begin_key, const std::string &end_key, const bool list_fsts, FarInfoData *far_info)
virtual Weight Final(StateId) const =0
std::set< std::string > fst_types
std::vector< KeyInfo > key_infos