32 struct stat stFileInfo;
37 intStat = stat(strFilename.c_str(), &stFileInfo);
68 fst->AddArc(0,
StdArc(10, 10, 0.0, 1));
71 fst->AddArc(1,
StdArc(12, 12, 0.0, 4));
72 fst->AddArc(1,
StdArc(0,0, 0.1,2));
75 fst->AddArc(2,
StdArc(13, 13, 0.2, 4));
76 fst->AddArc(2,
StdArc(0,0, 0.3,3));
79 fst->AddArc(3,
StdArc(14, 14, 0.4, 4));
82 fst->AddArc(4,
StdArc(15, 15, 0.5, 5));
85 fst->SetFinal(5, 0.6);
95 fst->AddArc(0,
StdArc(10, 10, 0.0, 1));
98 fst->AddArc(1,
StdArc(12, 12, 0.0, 4));
99 fst->AddArc(1,
StdArc(13,13,0.3,4));
100 fst->AddArc(1,
StdArc(14,14,0.8,4));
106 fst->AddArc(4,
StdArc(15, 15, 0.5, 5));
109 fst->SetFinal(5, 0.6);
122 StateId isrc=ifst->Start();
123 StateId dsrc=dfst->
Start();
124 Weight totalCost = Weight::One();
126 while (ifst->Final(isrc) == Weight::Zero()) {
127 fst::ArcIterator<StdVectorFst> aiter(*ifst, isrc);
128 const StdArc &iarc = aiter.Value();
129 if (dfst->
GetArc(dsrc, iarc.olabel, &oarc)) {
130 Weight cost =
Times(iarc.weight, oarc.weight);
132 totalCost =
Times(totalCost, cost);
134 cout <<
" Can't match arc ["<<iarc.ilabel<<
","<<iarc.olabel<<
","<<iarc.weight<<
"] from "<<isrc<<endl;
137 isrc = iarc.nextstate;
138 KALDI_LOG <<
"Setting dsrc = " << oarc.nextstate;
139 dsrc = oarc.nextstate;
141 totalCost =
Times(totalCost, dfst->
Final(dsrc));
143 cout <<
" Total cost: " << totalCost << endl;
150 cout <<
"Test with single generated backoff FST" << endl;
155 ArcSort(nfst, StdILabelCompare());
160 for (StateIterator<StdVectorFst> riter(*rfst); !riter.Done(); riter.Next()) {
161 StateId rsrc = riter.Value();
164 for (ArcIterator<StdVectorFst> aiter(*rfst, rsrc); !aiter.Done(); aiter.Next()) {
165 StdArc rarc = aiter.Value();
167 if (dfst1.
GetArc(rsrc, rarc.ilabel, &darc)) {
168 assert(
ApproxEqual(rarc.weight, darc.weight, 0.001));
169 assert(rarc.ilabel==darc.ilabel);
170 assert(rarc.olabel==darc.olabel);
171 assert(rarc.nextstate == darc.nextstate);
172 cerr <<
" Got same arc at state "<<rsrc<<
": "<<rarc.ilabel<<
" "<<darc.ilabel<<endl;
174 cerr <<
"Couldn't find arc "<<rarc.ilabel<<
" for state "<<rsrc<<endl;
184 cout <<
"Test with single generated backoff FST" << endl;
188 StdVectorFst composed_fst;
189 Compose(*rfst, *rfst, &composed_fst);
192 ArcSort(nfst, StdILabelCompare());
198 std::map<StateId, StateId> state_map;
199 state_map[composed_fst.Start()] = dfst1.
Start();
201 VectorFst<StdArc> path_fst;
202 ShortestPath(composed_fst, &path_fst);
218 bool b = lm_eg.
GetArc(0, 100, &arc);
219 KALDI_ASSERT(b && arc.nextstate == 1 && arc.ilabel == 100 && arc.olabel == 100
220 && arc.weight.Value() == 0.25);
This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministic...
fst::StdArc::StateId StateId
virtual bool GetArc(StateId s, Label ilabel, Arc *oarc)=0
Note: ilabel must not be epsilon.
virtual Weight Final(StateId s)=0
This class is for didactic purposes, it does not really do anything.
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
bool ApproxEqual(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2, float delta=kDelta)
fst::StdVectorFst StdVectorFst
virtual StateId Start()=0
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
Weight WalkSinglePath(StdVectorFst *ifst, DeterministicOnDemandFst< StdArc > *dfst)
virtual bool GetArc(StateId s, Label ilabel, Arc *oarc)
Note: ilabel must not be epsilon.
virtual Weight Final(StateId s)
We don't bother caching the final-probs, just the arcs.
void DeleteTestFst(StdVectorFst *fst)
fst::StdArc::Weight Weight
StdVectorFst * CreateBackoffFst()
#define KALDI_ASSERT(cond)
virtual bool GetArc(StateId s, Label ilabel, Arc *oarc)
Note: ilabel must not be epsilon.
bool FileExists(std::string strFilename)
virtual Weight Final(StateId s)
We don't bother caching the final-probs, just the arcs.
StdVectorFst * CreateResultFst()
void TestBackoffAndCache()