30 typedef int32 IntType;
35 for(
int i = 0;
i < 100;
i++) {
38 const Entry *e = NULL;
39 for(
int i = 0;
i < len;
i++) {
49 for(
int i = 0;
i < len2;
i++) {
53 vector<IntType> prefix, prefix2(
kaldi::Rand() % 10),
55 for(
int i = 0;
i < len &&
i < len2;
i++) {
56 if (str[
i] == str2[
i]) prefix.push_back(str[i]);
63 assert(prefix == prefix2);
64 assert(prefix == prefix3);
67 if (str.size() > prefix.size())
79 typedef ArcTpl<CompactLatticeWeightTpl<Weight, Int> > CompactArc;
81 for(
int i = 0;
i < 100;
i++) {
93 VectorFst<Arc> *
fst = RandFst<Arc>();
94 std::cout <<
"FST before lattice-determinizing is:\n";
96 FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL,
false,
true,
"\t");
97 fstprinter.Print(&std::cout,
"standard output");
99 VectorFst<Arc> det_fst;
104 if (!DeterminizeLattice<TropicalWeight, int32>(*fst, &det_fst, lat_opts, NULL))
105 throw std::runtime_error(
"could not determinize");
106 std::cout <<
"FST after lattice-determinizing is:\n";
108 FstPrinter<Arc> fstprinter(det_fst, NULL, NULL, NULL,
false,
true,
"\t");
109 fstprinter.Print(&std::cout,
"standard output");
111 assert(det_fst.Properties(kIDeterministic,
true) & kIDeterministic);
115 VectorFst<CompactArc> compact_fst, compact_det_fst;
116 ConvertLattice<Weight, Int>(*fst, &compact_fst,
false);
117 std::cout <<
"Compact FST is:\n";
119 FstPrinter<CompactArc> fstprinter(compact_fst, NULL, NULL, NULL,
false,
true,
"\t");
120 fstprinter.Print(&std::cout,
"standard output");
123 ConvertLattice<Weight, Int>(det_fst, &compact_det_fst,
false);
125 if (!DeterminizeLattice<TropicalWeight, int32>(*fst, &compact_det_fst, lat_opts, NULL))
126 throw std::runtime_error(
"could not determinize");
128 std::cout <<
"Compact version of determinized FST is:\n";
130 FstPrinter<CompactArc> fstprinter(compact_det_fst, NULL, NULL, NULL,
false,
true,
"\t");
131 fstprinter.Print(&std::cout,
"standard output");
134 assert(RandEquivalent(compact_det_fst, compact_fst, 5, 0.01,
kaldi::Rand(), 100));
136 std::cout <<
"Failed to lattice-determinize this FST (probably not determinizable)\n";
147 for(
int i = 0;
i < 100;
i++) {
148 VectorFst<Arc> *
fst = RandFst<Arc>(opts);
149 std::cout <<
"FST before lattice-determinizing is:\n";
151 FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL,
false,
true,
"\t");
152 fstprinter.Print(&std::cout,
"standard output");
155 DeterminizeLattice<TropicalWeight, int32>(*fst, &ofst);
156 std::cout <<
"FST after lattice-determinizing is:\n";
158 FstPrinter<Arc> fstprinter(ofst, NULL, NULL, NULL,
false,
true,
"\t");
159 fstprinter.Print(&std::cout,
"standard output");
171 TestDeterminizeLattice<StdArc>();
172 TestDeterminizeLattice2<StdArc>();
173 std::cout <<
"Tests succeeded\n";
const Entry * CommonPrefix(const Entry *a, const Entry *b)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void ConvertToVector(const Entry *entry, std::vector< IntType > *out) const
const Entry * Successor(const Entry *parent, IntType i)
const Entry * EmptyString()
void TestDeterminizeLattice2()
int Rand(struct RandomState *state)
fst::StdArc::Weight Weight
bool IsPrefixOf(const Entry *a, const Entry *b) const
void TestDeterminizeLattice()
void ReduceToCommonPrefix(const Entry *a, std::vector< IntType > *b)
void TestLatticeStringRepository()