23 #ifndef KALDI_FSTEXT_FSTEXT_UTILS_H_ 24 #define KALDI_FSTEXT_FSTEXT_UTILS_H_ 29 #include <fst/fstlib.h> 30 #include <fst/fst-decl.h> 35 #include "fst/script/print-impl.h" 56 template<
class Arc,
class I>
59 std::vector<I> *symbols);
63 template<
class Arc,
class I>
66 std::vector<I> *symbols);
74 MutableFst<Arc> *
fst);
79 std::vector<I> *syms_out);
90 template<ReweightType rtype>
91 void PushInLog(VectorFst<StdArc> *
fst, uint32 ptype,
float delta = kDelta) {
95 VectorFst<LogArc> *fst_log =
new VectorFst<LogArc>;
97 VectorFst<StdArc> tmp;
99 VectorFst<LogArc> *fst_pushed_log =
new VectorFst<LogArc>;
100 Push<LogArc, rtype>(*fst_log, fst_pushed_log, ptype, delta);
101 Cast(*fst_pushed_log, fst);
103 delete fst_pushed_log;
116 Map(fst, QuantizeMapper<Arc>(delta));
117 EncodeMapper<Arc> encoder(kEncodeLabels | kEncodeWeights, ENCODE);
118 Encode(fst, &encoder);
119 internal::AcceptorMinimize(fst);
120 Decode(fst, encoder);
132 template<
class Arc,
class I>
134 std::vector<I> *isymbols_out,
135 std::vector<I> *osymbols_out,
146 std::vector<VectorFst<Arc> > *fsts_out);
156 std::vector<VectorFst<Arc> > *fsts_out);
162 template<
class Arc,
class I>
170 template<
class Arc,
class I>
172 MutableFst<Arc> *ofst);
200 template<
class Arc,
class I>
202 MutableFst<Arc> *fst);
207 template<
class Arc,
class I>
209 MutableFst<Arc> *fst);
234 template<
class Arc,
class F>
246 template<
class Arc,
class F>
262 template<
class Arc,
class F>
279 template<
class Arc,
class F>
307 VectorFst<Arc>*
MakeLoopFst(
const std::vector<
const ExpandedFst<Arc> *> &fsts);
334 int rand_seed, MutableFst<Arc> *ofst,
int num_retries = 10);
358 const Fst<Arc> &fst2,
360 MutableFst<Arc> *fst);
382 MutableFst<Arc> *fst);
391 const Fst<Arc> &fst2,
393 MutableFst<Arc> *fst);
410 float delta = kDelta,
419 float delta = kDelta,
fst::StdArc::StateId StateId
void GetSymbols(const SymbolTable &symtab, bool include_eps, std::vector< I > *syms_out)
void MakePrecedingInputSymbolsSame(bool start_is_epsilon, MutableFst< Arc > *fst)
MakePrecedingInputSymbolsSame ensures that all arcs entering any given fst state have the same input ...
void PropagateFinal(typename Arc::Label phi_label, MutableFst< Arc > *fst)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void PhiCompose(const Fst< Arc > &fst1, const Fst< Arc > &fst2, typename Arc::Label phi_label, MutableFst< Arc > *ofst)
void MinimizeEncoded(VectorFst< Arc > *fst, float delta=kDelta)
void ClearSymbols(bool clear_input, bool clear_output, MutableFst< Arc > *fst)
ClearSymbols sets all the symbols on the input and/or output side of the FST to zero, as specified.
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
void GetInputSymbols(const Fst< Arc > &fst, bool include_eps, std::vector< I > *symbols)
GetInputSymbols gets the list of symbols on the input of fst (including epsilon, if include_eps == tr...
void RemoveUselessArcs(MutableFst< Arc > *fst)
void MakeLinearAcceptorWithAlternatives(const std::vector< std::vector< I > > &labels, MutableFst< Arc > *ofst)
Creates an unweighted acceptor with a linear structure, with alternatives at each position...
void DeterminizeStarInLog(VectorFst< StdArc > *fst, float delta, bool *debug_ptr, int max_states)
void MakeLinearAcceptor(const std::vector< I > &labels, MutableFst< Arc > *ofst)
Creates unweighted linear acceptor from symbol sequence.
bool EqualAlign(const Fst< Arc > &ifst, typename Arc::StateId length, int rand_seed, MutableFst< Arc > *ofst, int num_retries)
EqualAlign is similar to RandGen, but it generates a sequence with exactly "length" input symbols...
void PushInLog(VectorFst< StdArc > *fst, uint32 ptype, float delta=kDelta)
void ConvertNbestToVector(const Fst< Arc > &fst, std::vector< VectorFst< Arc > > *fsts_out)
This function converts an FST with a special structure, which is output by the OpenFst functions Shor...
void NbestAsFsts(const Fst< Arc > &fst, size_t n, std::vector< VectorFst< Arc > > *fsts_out)
Takes the n-shortest-paths (using ShortestPath), but outputs the result as a vector of up to n fsts...
Arc::Label HighestNumberedOutputSymbol(const Fst< Arc > &fst)
Returns the highest numbered output symbol id of the FST (or zero for an empty FST.
bool IsStochasticFstInLog(const Fst< StdArc > &fst, float delta, StdArc::Weight *min_sum, StdArc::Weight *max_sum)
VectorFst< Arc > * MakeLoopFst(const std::vector< const ExpandedFst< Arc > *> &fsts)
MakeLoopFst creates an FST that has a state that is both initial and final (weight == Weight::One())...
bool PrecedingInputSymbolsAreSame(bool start_is_epsilon, const Fst< Arc > &fst)
Returns true if and only if the FST is such that the input symbols on arcs entering any given state a...
bool IsStochasticFst(const Fst< LogArc > &fst, float delta, LogArc::Weight *min_sum, LogArc::Weight *max_sum)
void ApplyProbabilityScale(float scale, MutableFst< Arc > *fst)
ApplyProbabilityScale is applicable to FSTs in the log or tropical semiring.
bool PrecedingInputSymbolsAreSameClass(bool start_is_epsilon, const Fst< Arc > &fst, const F &f)
This is as PrecedingInputSymbolsAreSame, but with a functor f that maps labels to classes...
void MakePrecedingInputSymbolsSameClass(bool start_is_epsilon, MutableFst< Arc > *fst, const F &f)
As MakePrecedingInputSymbolsSame, but takes a functor object that maps labels to classes.
fst::StdArc::Weight Weight
bool FollowingInputSymbolsAreSame(bool end_is_epsilon, const Fst< Arc > &fst)
Returns true if and only if the FST is such that the input symbols on arcs exiting any given state al...
Arc::Label HighestNumberedInputSymbol(const Fst< Arc > &fst)
Returns the highest numbered input symbol id of the FST (or zero for an empty FST.
void MapInputSymbols(const std::vector< I > &symbol_mapping, MutableFst< Arc > *fst)
void RemoveWeights(MutableFst< Arc > *ifst)
void SafeDeterminizeWrapper(MutableFst< Arc > *ifst, MutableFst< Arc > *ofst, float delta)
Does PreDeterminize and DeterminizeStar and then removes the disambiguation symbols.
void SafeDeterminizeMinimizeWrapperInLog(VectorFst< StdArc > *ifst, VectorFst< StdArc > *ofst, float delta)
SafeDeterminizeMinimizeWapperInLog is as SafeDeterminizeMinimizeWrapper except it first casts tothe l...
void SafeDeterminizeMinimizeWrapper(MutableFst< Arc > *ifst, VectorFst< Arc > *ofst, float delta)
SafeDeterminizeMinimizeWapper is as SafeDeterminizeWrapper except that it also minimizes (encoded min...
void RhoCompose(const Fst< Arc > &fst1, const Fst< Arc > &fst2, typename Arc::Label rho_label, MutableFst< Arc > *ofst)
bool FollowingInputSymbolsAreSameClass(bool end_is_epsilon, const Fst< Arc > &fst, const F &f)
Arc::StateId NumArcs(const ExpandedFst< Arc > &fst)
Returns the total number of arcs in an FST.
void MakeFollowingInputSymbolsSameClass(bool end_is_epsilon, MutableFst< Arc > *fst, const F &f)
As MakeFollowingInputSymbolsSame, but takes a functor object that maps labels to classes.
void MakeFollowingInputSymbolsSame(bool end_is_epsilon, MutableFst< Arc > *fst)
MakeFollowingInputSymbolsSame ensures that all arcs exiting any given fst state have the same input s...
void GetOutputSymbols(const Fst< Arc > &fst, bool include_eps, std::vector< I > *symbols)
GetOutputSymbols gets the list of symbols on the output of fst (including epsilon, if include_eps == true)
void RemoveSomeInputSymbols(const std::vector< I > &to_remove, MutableFst< Arc > *fst)
RemoveSomeInputSymbols removes any symbol that appears in "to_remove", from the input side of the FST...