forked from synesthesiam/jsgf2fst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fstprint-all.cc
43 lines (35 loc) · 1.05 KB
/
fstprint-all.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <fst/fst.h>
void printAll(const fst::StdFst& fst,
const fst::StdArc::StateId state,
std::vector<fst::StdArc> path) {
for (fst::ArcIterator<fst::StdFst> aiter(fst, state);
!aiter.Done();
aiter.Next()) {
const fst::StdArc &arc = aiter.Value();
path.push_back(arc);
if (fst.Final(arc.nextstate) != fst::StdArc::Weight::Zero()) {
for (size_t i = 0; i < path.size(); ++i) {
if (path[i].olabel != 0) { // assume <eps> is 0
std::cout << fst.OutputSymbols()->Find(path[i].olabel) << " ";
}
}
std::cout << std::endl;
} else {
printAll(fst, arc.nextstate, path);
}
path.pop_back();
}
}
int main(int argc, char** argv) {
if (argc < 2) {
std::cerr << "Usage: fstprint-all FST" << std::endl;
return 1;
}
std::string in_filename(argv[1]);
const fst::StdFst *in_fst =
fst::StdFst::Read(in_filename);
const auto startState = in_fst->Start();
std::vector<fst::StdArc> path;
printAll(*in_fst, startState, path);
return 0;
}