39 typedef ArcTpl<CompactLatticeWeightTpl<Weight, Int> > CompactArc;
41 for(
int i = 0;
i < 100;
i++) {
54 VectorFst<Arc> *
fst = RandPairFst<Arc>(opts);
56 bool sorted = TopSort(fst);
59 ILabelCompare<Arc> ilabel_comp;
61 ArcSort(fst, ilabel_comp);
63 std::cout <<
"FST before lattice-determinizing is:\n";
65 FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL,
false,
true,
"\t");
66 fstprinter.Print(&std::cout,
"standard output");
68 VectorFst<Arc> det_fst;
74 bool ans = DeterminizeLatticePruned<Weight>(*fst, 10.0, &det_fst, lat_opts);
76 std::cout <<
"FST after lattice-determinizing is:\n";
78 FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL,
false,
true,
"\t");
79 fstprinter.Print(&std::cout,
"standard output");
81 KALDI_ASSERT(det_fst.Properties(kIDeterministic,
true) & kIDeterministic);
87 VectorFst<Arc> pruned_fst(*fst);
88 if (pruned_fst.NumStates() != 0)
91 VectorFst<CompactArc> compact_pruned_fst, compact_pruned_det_fst;
92 ConvertLattice<Weight, Int>(pruned_fst, &compact_pruned_fst,
false);
93 std::cout <<
"Compact pruned FST is:\n";
95 FstPrinter<CompactArc> fstprinter(compact_pruned_fst, NULL, NULL, NULL,
false,
true,
"\t");
96 fstprinter.Print(&std::cout,
"standard output");
98 ConvertLattice<Weight, Int>(det_fst, &compact_pruned_det_fst,
false);
100 std::cout <<
"Compact version of determinized FST is:\n";
102 FstPrinter<CompactArc> fstprinter(compact_pruned_det_fst, NULL, NULL, NULL,
false,
true,
"\t");
103 fstprinter.Print(&std::cout,
"standard output");
109 std::cout <<
"Failed to lattice-determinize this FST (probably not determinizable)\n";
121 for(
int i = 0;
i < 100;
i++) {
122 VectorFst<Arc> *
fst = RandPairFst<Arc>(opts);
123 std::cout <<
"FST before lattice-determinizing is:\n";
125 FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL,
false,
true,
"\t");
126 fstprinter.Print(&std::cout,
"standard output");
129 DeterminizeLatticePruned<Weight>(*fst, 10.0, &ofst);
130 std::cout <<
"FST after lattice-determinizing is:\n";
132 FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL,
false,
true,
"\t");
133 fstprinter.Print(&std::cout,
"standard output");
144 TestDeterminizeLatticePruned<kaldi::LatticeArc>();
145 TestDeterminizeLatticePruned2<kaldi::LatticeArc>();
146 std::cout <<
"Tests succeeded\n";
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void TestDeterminizeLatticePruned()
int Rand(struct RandomState *state)
fst::StdArc::Weight Weight
bool PruneLattice(BaseFloat beam, LatType *lat)
#define KALDI_ASSERT(cond)
void TestDeterminizeLatticePruned2()