Add debugging code to trie_load.cc
This commit is contained in:
parent
818ea6a40f
commit
83a89dcae6
@ -5,8 +5,13 @@
|
||||
#include "ctcdecode/scorer.h"
|
||||
#include "alphabet.h"
|
||||
|
||||
using namespace std;
|
||||
#ifdef DEBUG
|
||||
#include <limits>
|
||||
#include <unordered_map>
|
||||
#include "ctcdecode/path_trie.h"
|
||||
#endif // DEBUG
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@ -22,5 +27,40 @@ int main(int argc, char** argv)
|
||||
return err;
|
||||
}
|
||||
Scorer scorer;
|
||||
|
||||
#ifndef DEBUG
|
||||
return scorer.init(0.0, 0.0, kenlm_path, trie_path, alphabet);
|
||||
#else
|
||||
// Print some info about the FST
|
||||
using FstType = fst::ConstFst<fst::StdArc>;
|
||||
|
||||
auto dict = scorer.dictionary.get();
|
||||
|
||||
struct state_info {
|
||||
int range_min = std::numeric_limits<int>::max();
|
||||
int range_max = std::numeric_limits<int>::min();
|
||||
};
|
||||
|
||||
auto print_states_from = [&](int i) {
|
||||
std::unordered_map<int, state_info> sinfo;
|
||||
for (fst::ArcIterator<FstType> aiter(*dict, i); !aiter.Done(); aiter.Next()) {
|
||||
const fst::StdArc& arc = aiter.Value();
|
||||
sinfo[arc.nextstate].range_min = std::min(sinfo[arc.nextstate].range_min, arc.ilabel-1);
|
||||
sinfo[arc.nextstate].range_max = std::max(sinfo[arc.nextstate].range_max, arc.ilabel-1);
|
||||
}
|
||||
|
||||
for (auto it = sinfo.begin(); it != sinfo.end(); ++it) {
|
||||
state_info s = it->second;
|
||||
printf("%d -> state %d (chars 0x%X - 0x%X, '%c' - '%c')\n", i, it->first, (unsigned int)s.range_min, (unsigned int)s.range_max, (char)s.range_min, (char)s.range_max);
|
||||
}
|
||||
};
|
||||
|
||||
print_states_from(0);
|
||||
|
||||
// for (int i = 1; i < 10; ++i) {
|
||||
// print_states_from(i);
|
||||
// }
|
||||
#endif // DEBUG
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user