20 #ifndef KALDI_FSTEXT_EPSILON_PROPERTY_INL_H_ 21 #define KALDI_FSTEXT_EPSILON_PROPERTY_INL_H_ 29 std::vector<char> *epsilon_info) {
31 typedef VectorFst<Arc> Fst;
32 epsilon_info->clear();
33 epsilon_info->resize(fst.NumStates(),
static_cast<char>(0));
34 for (StateId s = 0; s < fst.NumStates(); s++) {
35 for (ArcIterator<Fst> aiter(fst, s); !aiter.Done(); aiter.Next()) {
36 const Arc &arc = aiter.Value();
37 if (arc.ilabel == 0 && arc.olabel == 0) {
53 typedef VectorFst<Arc> Fst;
54 std::vector<char> epsilon_info;
58 StateId num_states_old = fst->NumStates();
59 StateId non_coaccessible_state = fst->AddState();
65 std::vector<StateId> new_state_vec(num_states_old, kNoStateId);
66 for (StateId s = 0; s < num_states_old; s++) {
69 assert(s != fst->Start());
71 StateId new_state = fst->AddState();
72 new_state_vec[s] = new_state;
73 fst->AddArc(new_state,
Arc(0, 0, Weight::One(), s));
79 for (StateId s = 0; s < num_states_old; s++) {
80 for (MutableArcIterator<Fst> aiter(fst, s);
81 !aiter.Done(); aiter.Next()) {
82 Arc arc = aiter.Value();
83 if (arc.ilabel != 0 || arc.olabel != 0) {
84 StateId replacement_state;
85 if (arc.nextstate >= 0 && arc.nextstate < num_states_old &&
86 (replacement_state = new_state_vec[arc.nextstate]) !=
88 arc.nextstate = replacement_state;
97 for (StateId s = 0; s < num_states_old; s++) {
103 StateId new_state = fst->AddState();
104 for (MutableArcIterator<Fst> aiter(fst, s); !aiter.Done();
106 Arc arc = aiter.Value();
107 if (arc.ilabel != 0 || arc.olabel != 0) {
108 assert(arc.nextstate != s);
110 fst->AddArc(new_state, arc);
111 arc.nextstate = non_coaccessible_state;
116 fst->AddArc(s,
Arc(0, 0, Weight::One(), new_state));
fst::StdArc::StateId StateId
void EnsureEpsilonProperty(VectorFst< Arc > *fst)
This function modifies the fst (while maintaining equivalence) in such a way that, after the modification, all states of the FST which have epsilon-arcs entering them, have no non-epsilon arcs entering them, and all states which have epsilon-arcs leaving them, have no non-epsilon arcs leaving them.
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void ComputeStateInfo(const VectorFst< Arc > &fst, std::vector< char > *epsilon_info)
This function will set epsilon_info to have size equal to the NumStates() of the FST, containing a logical-or of the enum values kStateHasEpsilonArcsEntering, kStateHasNonEpsilonArcsEntering, kStateHasEpsilonArcsLeaving, and kStateHasNonEpsilonArcsLeaving.
fst::StdArc::Weight Weight