20 #ifndef FST_REVERSE_H_ 21 #define FST_REVERSE_H_ 47 template <
class FromArc,
class ToArc>
49 bool require_superinitial =
true) {
50 using StateId =
typename FromArc::StateId;
51 using Weight =
typename FromArc::Weight;
58 StateId istart = ifst.
Start();
61 uint64_t dfs_iprops = 0;
62 uint64_t dfs_oprops = 0;
63 if (!require_superinitial) {
65 const auto s = siter.Value();
66 if (ifst.
Final(s) == Weight::Zero())
continue;
75 std::vector<StateId> scc;
78 if (std::count(scc.begin(), scc.end(), scc[ostart]) > 1) {
83 if (aiter.Value().nextstate == ostart) {
97 const auto is = siter.Value();
98 const auto os = is + offset;
100 if (is == istart) ofst->
SetFinal(os);
101 const auto weight = ifst.
Final(is);
102 if ((weight != Weight::Zero()) && (offset == 1)) {
103 const ToArc oarc(0, 0, weight.Reverse(), os);
108 const auto &iarc = aiter.Value();
109 const auto nos = iarc.nextstate + offset;
110 auto weight = iarc.weight.Reverse();
111 if (!offset && (nos == ostart)) {
112 weight =
Times(ifst.
Final(ostart).Reverse(), weight);
114 const ToArc oarc(iarc.ilabel, iarc.olabel, weight, os);
120 if (offset == 0 && ostart == istart) {
131 #endif // FST_REVERSE_H_ virtual uint64_t Properties(uint64_t mask, bool test) const =0
ErrorWeight Times(const ErrorWeight &, const ErrorWeight &)
void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, bool access_only=false)
constexpr uint64_t kInitialAcyclic
virtual void SetInputSymbols(const SymbolTable *isyms)=0
virtual Weight Final(StateId) const =0
virtual void SetStart(StateId)=0
void Reverse(const Fst< Arc > &ifst, const std::vector< std::pair< typename Arc::Label, typename Arc::Label >> &parens, std::vector< typename Arc::Label > *assignments, MutableFst< RevArc > *ofst)
uint64_t ReverseProperties(uint64_t inprops, bool has_superinitial)
constexpr uint64_t kCopyProperties
virtual void SetProperties(uint64_t props, uint64_t mask)=0
virtual StateId Start() const =0
constexpr uint64_t kFstProperties
virtual void AddArc(StateId, const Arc &)=0
virtual const SymbolTable * InputSymbols() const =0
Arc::StateId CountStates(const Fst< Arc > &fst)
virtual StateId AddState()=0
virtual void ReserveStates(size_t)
virtual void SetFinal(StateId s, Weight weight=Weight::One())=0
virtual void DeleteStates(const std::vector< StateId > &)=0
virtual void SetOutputSymbols(const SymbolTable *osyms)=0
virtual StateId NumStates() const =0
constexpr uint64_t kExpanded
virtual const SymbolTable * OutputSymbols() const =0