34 VectorFst<Arc> *fst1 = RandFst<Arc>();
36 VectorFst<Arc> *fst2 = RandFst<Arc>();
38 ILabelCompare<Arc> ilabel_comp;
39 OLabelCompare<Arc> olabel_comp;
48 ArcSort(fst1, olabel_comp);
49 ArcSort(fst2, ilabel_comp);
51 VectorFst<Arc> composed;
55 if (!connect) Connect(&composed);
57 VectorFst<Arc> composed_baseline;
59 Compose(*fst1, *fst2, &composed_baseline);
62 std::cout <<
"Connect = "<< (connect?
"True\n":
"False\n");
64 std::cout <<
"Table-Composed FST\n";
66 FstPrinter<Arc> fstprinter(composed, NULL, NULL, NULL,
false,
true,
"\t");
67 fstprinter.Print(&std::cout,
"standard output");
70 std::cout <<
" Baseline-Composed FST\n";
72 FstPrinter<Arc> fstprinter(composed_baseline, NULL, NULL, NULL,
false,
true,
"\t");
73 fstprinter.Print(&std::cout,
"standard output");
76 if ( !RandEquivalent(composed, composed_baseline, 3, 0.01,
kaldi::Rand(), 20)) {
78 Difference(composed, composed_baseline, &diff1);
79 std::cout <<
" Diff1 (composed - baseline) \n";
81 FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL,
false,
true,
"\t");
82 fstprinter.Print(&std::cout,
"standard output");
87 Difference(composed_baseline, composed, &diff2);
88 std::cout <<
" Diff2 (baseline - composed) \n";
90 FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL,
false,
true,
"\t");
91 fstprinter.Print(&std::cout,
"standard output");
110 VectorFst<Arc> *fst1 = RandFst<Arc>();
117 opts.connect = connect;
121 for (
size_t i = 0;
i < 3;
i++) {
123 VectorFst<Arc> *fst2 = RandFst<Arc>();
125 ILabelCompare<Arc> ilabel_comp;
126 OLabelCompare<Arc> olabel_comp;
129 ArcSort(fst1, olabel_comp);
130 ArcSort(fst2, ilabel_comp);
132 VectorFst<Arc> composed;
136 if (!connect) Connect(&composed);
138 VectorFst<Arc> composed_baseline;
140 Compose(*fst1, *fst2, &composed_baseline);
143 std::cout <<
"Connect = "<< (connect?
"True\n":
"False\n");
146 if ( !RandEquivalent(composed, composed_baseline, 3, 0.01,
kaldi::Rand(), 100)) {
147 VectorFst<Arc> diff1;
148 Difference(composed, composed_baseline, &diff1);
149 std::cout <<
" Diff1 (composed - baseline) \n";
151 FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL,
false,
true,
"\t");
152 fstprinter.Print(&std::cout,
"standard output");
156 VectorFst<Arc> diff2;
157 Difference(composed_baseline, composed, &diff2);
158 std::cout <<
" Diff2 (baseline - composed) \n";
160 FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL,
false,
true,
"\t");
161 fstprinter.Print(&std::cout,
"standard output");
179 VectorFst<Arc> *fst2 = RandFst<Arc>();
180 ILabelCompare<Arc> ilabel_comp;
181 ArcSort(fst2, ilabel_comp);
192 for (
size_t i = 0;
i < 2;
i++) {
194 VectorFst<Arc> *fst1 = RandFst<Arc>();
197 OLabelCompare<Arc> olabel_comp;
200 ArcSort(fst1, olabel_comp);
202 VectorFst<Arc> composed;
206 if (!connect) Connect(&composed);
208 VectorFst<Arc> composed_baseline;
210 Compose(*fst1, *fst2, &composed_baseline);
213 std::cout <<
"Connect = "<< (connect?
"True\n":
"False\n");
216 if ( !RandEquivalent(composed, composed_baseline, 5, 0.01,
kaldi::Rand(), 20)) {
217 VectorFst<Arc> diff1;
218 Difference(composed, composed_baseline, &diff1);
219 std::cout <<
" Diff1 (composed - baseline) \n";
221 FstPrinter<Arc> fstprinter(diff1, NULL, NULL, NULL,
false,
true,
"\t");
222 fstprinter.Print(&std::cout,
"standard output");
226 VectorFst<Arc> diff2;
227 Difference(composed_baseline, composed, &diff2);
228 std::cout <<
" Diff2 (baseline - composed) \n";
230 FstPrinter<Arc> fstprinter(diff2, NULL, NULL, NULL,
false,
true,
"\t");
231 fstprinter.Print(&std::cout,
"standard output");
247 for (
int i = 0;
i < 1;
i++) {
248 TestTableMatcher<fst::StdArc>(
true,
true);
249 TestTableMatcher<fst::StdArc>(
false,
true);
250 TestTableMatcher<fst::StdArc>(
true,
false);
251 TestTableMatcher<fst::StdArc>(
false,
false);
252 TestTableMatcherCacheLeft<fst::StdArc>(
true);
253 TestTableMatcherCacheLeft<fst::StdArc>(
false);
254 TestTableMatcherCacheRight<fst::StdArc>(
true);
255 TestTableMatcherCacheRight<fst::StdArc>(
false);
fst::StdArc::StateId StateId
void TableCompose(const Fst< Arc > &ifst1, const Fst< Arc > &ifst2, MutableFst< Arc > *ofst, const TableComposeOptions &opts=TableComposeOptions())
void TestTableMatcherCacheLeft(bool connect)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void TestTableMatcher(bool connect, bool left)
TableComposeCache lets us do multiple compositions while caching the same matcher.
void TestTableMatcherCacheRight(bool connect)
int Rand(struct RandomState *state)
fst::StdArc::Weight Weight
MatchType table_match_type