42 #ifndef KALDI_FSTEXT_DETERMINISTIC_FST_H_ 43 #define KALDI_FSTEXT_DETERMINISTIC_FST_H_ 56 #include <fst/fstlib.h> 57 #include <fst/fst-decl.h> 81 virtual StateId
Start() = 0;
83 virtual Weight
Final(StateId s) = 0;
86 virtual bool GetArc(StateId s, Label ilabel,
Arc *oarc) = 0;
108 StateId
Start() {
return fst_.Start(); }
110 Weight
Final(StateId s);
112 bool GetArc(StateId s, Label ilabel,
Arc *oarc);
115 inline StateId GetBackoffState(StateId s, Weight *w);
138 scale_(scale), det_fst_(*det_fst) { }
140 StateId
Start() {
return det_fst_.Start(); }
144 Weight
final = det_fst_.Final(s);
145 if (
final == Weight::Zero())
return Weight::Zero();
146 else return TropicalWeight(
final.Value() * scale_);
150 if (det_fst_.GetArc(s, ilabel, oarc)) {
151 oarc->weight = TropicalWeight(oarc->weight.Value() * scale_);
181 StateId
Start() {
return start_state_; };
183 Weight
Final(StateId s);
185 bool GetArc(StateId s, Label ilabel,
Arc *oarc);
188 typedef unordered_map<std::vector<Label>,
212 virtual StateId
Start() {
return start_state_; }
214 virtual Weight
Final(StateId s);
216 virtual bool GetArc(StateId s, Label ilabel,
Arc *oarc);
238 StateId num_cached_arcs = 100000);
240 virtual StateId
Start() {
return fst_->Start(); }
243 virtual Weight
Final(StateId s) {
return fst_->Final(s); }
245 virtual bool GetArc(StateId s, Label ilabel,
Arc *oarc);
249 inline size_t GetIndex(StateId src_state, Label ilabel);
273 virtual StateId
Start() {
return start_state_; }
276 virtual Weight
Final(StateId s);
278 virtual bool GetArc(StateId s, Label ilabel,
Arc *oarc);
282 inline size_t GetIndex(StateId src_state, Label ilabel);
305 MutableFst<Arc> *fst_composed);
324 MutableFst<Arc> *fst_composed);
This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministic...
std::vector< std::vector< Label > > state_vec_
fst::StdArc::StateId StateId
DeterministicOnDemandFst< StdArc > & det_fst_
virtual bool GetArc(StateId s, Label ilabel, Arc *oarc)=0
Note: ilabel must not be epsilon.
A hashing function-object for vectors.
virtual Weight Final(StateId s)=0
This class is for didactic purposes, it does not really do anything.
unordered_map< std::vector< Label >, StateId, kaldi::VectorHasher< Label > > MapType
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Class ScaleDeterministicOnDemandFst takes another DeterministicOnDemandFst and scales the weights (li...
void ComposeDeterministicOnDemand(const Fst< Arc > &fst1, DeterministicOnDemandFst< Arc > *fst2, MutableFst< Arc > *fst_composed)
ScaleDeterministicOnDemandFst(float scale, DeterministicOnDemandFst< StdArc > *det_fst)
unordered_map< std::vector< Label >, StateId, kaldi::VectorHasher< Label > > MapType
virtual StateId Start()=0
std::vector< std::vector< Label > > state_vec_
DeterministicOnDemandFst< Arc > * fst1_
void ComposeDeterministicOnDemandInverse(const Fst< Arc > &right, DeterministicOnDemandFst< Arc > *left, MutableFst< Arc > *fst_composed)
This function does '*fst_composed = Compose(Inverse(*fst2), fst1)' Note that the arguments are revers...
class DeterministicOnDemandFst is an "FST-like" base-class.
virtual ~DeterministicOnDemandFst()
unordered_map< std::pair< StateId, StateId >, StateId, kaldi::PairHasher< StateId > > MapType
virtual Weight Final(StateId s)
We don't bother caching the final-probs, just the arcs.
std::vector< std::pair< StateId, Arc > > cached_arcs_
DeterministicOnDemandFst< Arc > * fst_
bool GetArc(StateId s, Label ilabel, StdArc *oarc)
fst::StdArc::Weight Weight
DeterministicOnDemandFst< Arc > * fst2_
The class UnweightedNgramFst is a DeterministicOnDemandFst whose states encode an n-gram history...
std::vector< std::pair< StateId, StateId > > state_vec_
A hashing function-object for pairs of ints.