21 #ifndef KALDI_FSTEXT_PRUNE_SPECIAL_INL_H_ 22 #define KALDI_FSTEXT_PRUNE_SPECIAL_INL_H_ 47 ofst_->DeleteStates();
48 if (
ifst_.Start() == kNoStateId)
55 if (
Done(task))
break;
59 if (
beam_ != Weight::One())
69 Task(InputStateId istate, OutputStateId ostate,
size_t position,
70 Weight weight): istate(istate), ostate(ostate), position(position),
95 for (ArcIterator<Fst<Arc> > aiter(
ifst_, istate); !aiter.Done();
97 const Arc &arc = aiter.Value();
98 Task new_task(istate, ostate, aiter.Position(),
99 Times(weight, arc.weight));
103 Weight
final =
ifst_.Final(istate);
104 if (
final != Weight::Zero()) {
105 Task final_task(istate, ostate, static_cast<size_t>(-1),
106 Times(weight,
final));
121 typedef typename unordered_map<InputStateId, OutputStateId>::iterator IterType;
130 if (task.
position == static_cast<size_t>(-1)) {
139 const Arc &arc = aiter.Value();
140 InputStateId next_istate = arc.nextstate;
142 Arc oarc(arc.ilabel, arc.olabel, arc.weight, next_ostate);
162 VectorFst<Arc> *ofst,
fst::StdArc::StateId StateId
void ProcessTask(const Task &task)
Arc::StateId OutputStateId
void PruneSpecial(const Fst< Arc > &ifst, VectorFst< Arc > *ofst, typename Arc::Weight beam, size_t max_states)
The function PruneSpecial is like the standard OpenFst function "prune", except it does not expand th...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
PruneSpecialClass(const Fst< Arc > &ifst, VectorFst< Arc > *ofst, Weight beam, size_t max_states)
Arc::StateId InputStateId
std::priority_queue< Task > queue_
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
bool operator<(const Task &other) const
unordered_map< InputStateId, OutputStateId > state_map_
Task(InputStateId istate, OutputStateId ostate, size_t position, Weight weight)
fst::StdArc::Weight Weight
int Compare(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
Compare returns -1 if w1 < w2, +1 if w1 > w2, and 0 if w1 == w2.
#define KALDI_ASSERT(cond)
OutputStateId ProcessState(InputStateId istate, const Weight &weight)
This class is used to implement the function PruneSpecial.
OutputStateId GetOutputStateId(InputStateId istate, const Weight &weight)
bool Done(const Task &task)