38 VectorFst<Arc> *
fst =
new VectorFst<Arc>();
40 cout <<
"Testing pre-determinize with "<<n_syms<<
" symbols, "<<n_states<<
" states and "<<n_arcs<<
" arcs and "<<n_final<<
" final states.\n";
41 SymbolTable *sptr = NULL;
43 vector<Label> all_syms;
46 all_syms.push_back(
i);
49 vector<StateId> all_states;
50 for (
size_t i = 0;
i < (
size_t)n_states;
i++) {
51 StateId this_state = fst->AddState();
52 if (
i == 0) fst->SetStart(
i);
53 all_states.push_back(this_state);
56 for (
size_t j = 0;
j < (
size_t)n_final;
j++) {
59 printf(
"calling SetFinal with %d and %f\n",
id, weight.Value());
60 fst->SetFinal(
id, weight);
63 for (
size_t i = 0;
i < (
size_t)n_arcs;
i++) {
69 StateId start_state = all_states[
kaldi::Rand() % n_states];
70 fst->AddArc(start_state, a);
73 std::cout <<
" printing before trimming\n";
75 FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL,
false,
true,
"\t");
76 fstprinter.Print(&std::cout,
"standard output");
81 std::cout <<
" printing after trimming\n";
83 FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL,
false,
true,
"\t");
84 fstprinter.Print(&std::cout,
"standard output");
87 vector<Label> extra_syms;
88 if (fst->Start() != kNoStateId) {
92 std::cout <<
" printing after predeterminization\n";
94 FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL,
false,
true,
"\t");
95 fstprinter.Print(&std::cout,
"standard output");
101 Weight weight_threshold = Weight::Zero();
103 double delta = kDelta;
105 RmEpsilon(fst, connect, weight_threshold, nstate, delta);
108 std::cout <<
" printing after double-epsilon removal\n";
110 FstPrinter<Arc> fstprinter(*fst, sptr, sptr, NULL,
false,
true,
"\t");
111 fstprinter.Print(&std::cout,
"standard output");
113 VectorFst<Arc> ofst_star;
116 printf(
"Converting to Gallic semiring");
117 VectorFst<GallicArc<Arc> > gallic_fst;
118 VectorFst<GallicArc<Arc> > gallic_fst_noeps;
119 VectorFst<GallicArc<Arc> > gallic_fst_det;
123 printf(
"Determinizing with DeterminizeStar, converting to Gallic\n");
128 std::cout <<
" printing gallic FST\n";
129 FstPrinter<GallicArc<Arc> > fstprinter(gallic_fst, sptr, sptr, NULL,
false,
true,
"\t");
130 fstprinter.Print(&std::cout,
"standard output");
136 printf(
"Converting gallic back to regular\n");
138 typename Arc::Weight, GALLIC_LEFT> > fwfst(gallic_fst);
140 std::cout <<
" printing factor-weight FST\n";
141 FstPrinter<GallicArc<Arc> > fstprinter(fwfst, sptr, sptr, NULL,
false,
true,
"\t");
142 fstprinter.Print(&std::cout,
"standard output");
145 Map(fwfst, &ofst_star, FromGallicMapper<Arc, GALLIC_LEFT>());
148 std::cout <<
" printing after converting back to regular FST\n";
149 FstPrinter<Arc> fstprinter(ofst_star, sptr, sptr, NULL,
false,
true,
"\t");
150 fstprinter.Print(&std::cout,
"standard output");
154 VectorFst<GallicArc<Arc> > new_gallic_fst;
155 Map(ofst_star, &new_gallic_fst, ToGallicMapper<Arc, GALLIC_LEFT>());
157 assert(RandEquivalent(gallic_fst, new_gallic_fst, 5, 0.01,
kaldi::Rand(), 100));
171 if (
sizeof(inttype) == 1) N = 64;
172 vector<vector<Label> > strings(N);
173 vector<inttype> ids(N);
175 for (
size_t i = 0;
i < N;
i++) {
179 if (
i < 500 && vec.size() == 0) ids[
i] = sr.
IdOfEmpty();
180 else if (
i < 500 && vec.size() == 1) ids[
i] = sr.
IdOfLabel(vec[0]);
186 for (
size_t i = 0;
i < N;
i++) {
190 assert(tmpv == strings[i]);
191 assert(sr.
IdOfSeq(strings[i]) == ids[
i]);
192 if (strings[i].size() == 0) assert(ids[i] == sr.
IdOfEmpty());
193 if (strings[i].size() == 1) assert(ids[i] == sr.
IdOfLabel(strings[i][0]));
195 if (
sizeof(inttype) != 1) {
196 size_t prefix_len =
kaldi::Rand() % (strings[
i].size() + 1);
200 for (
size_t j = 0;
j < strings[
i].size()-prefix_len;
j++) {
201 assert(vec2[
j] == strings[i][
j+prefix_len]);
211 for (
int i = 0;
i < 25;
i++) {
212 fst::TestFactor<fst::StdArc>();
fst::StdArc::StateId StateId
TrivialFactorWeightFst takes as template parameter a FactorIterator as defined above.
void PreDeterminize(MutableFst< Arc > *fst, typename Arc::Label first_new_sym, std::vector< Int > *symsOut)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
StringId IdOfSeq(const std::vector< Label > &v)
StringId RemovePrefix(StringId id, size_t prefix_len)
void SeqOfId(StringId id, std::vector< Label > *v)
StringId IdOfLabel(Label l)
int Rand(struct RandomState *state)
fst::StdArc::Weight Weight
void TestStringRepository()
bool DeterminizeStar(F &ifst, MutableFst< typename F::Arc > *ofst, float delta, bool *debug_ptr, int max_states, bool allow_partial)
This function implements the normal version of DeterminizeStar, in which the output strings are repre...