20 #ifndef FST_REWEIGHT_H_ 21 #define FST_REWEIGHT_H_ 47 const std::vector<typename Arc::Weight> &potential,
49 using Weight =
typename Arc::Weight;
54 if (type == REWEIGHT_TO_FINAL && !(Weight::Properties() &
kRightSemiring)) {
55 FSTERROR() <<
"Reweight: Reweighting to the final states requires " 56 <<
"Weight to be right distributive: " << Weight::Type();
64 FSTERROR() <<
"Reweight: Reweighting to the initial state requires " 65 <<
"Weight to be left distributive: " << Weight::Type();
71 for (; !siter.
Done(); siter.
Next()) {
72 const auto s = siter.
Value();
73 if (s == potential.size())
break;
74 const auto &weight = potential[s];
75 if (weight != Weight::Zero()) {
78 auto arc = aiter.Value();
79 if (arc.nextstate >= potential.size())
continue;
80 const auto &nextweight = potential[arc.nextstate];
81 if (nextweight == Weight::Zero())
continue;
86 if (type == REWEIGHT_TO_FINAL) {
96 if (type == REWEIGHT_TO_FINAL) {
101 for (; !siter.
Done(); siter.
Next()) {
102 const auto s = siter.
Value();
103 if (type == REWEIGHT_TO_FINAL) {
107 const auto startweight = fst->
Start() < potential.size()
108 ? potential[fst->
Start()]
110 bool added_start_epsilon =
false;
111 if ((startweight != Weight::One()) && (startweight != Weight::Zero())) {
113 const auto s = fst->
Start();
116 auto arc = aiter.Value();
118 arc.weight =
Times(startweight, arc.weight);
139 added_start_epsilon =
true;
149 #endif // FST_REWEIGHT_H_
virtual uint64_t Properties(uint64_t mask, bool test) const =0
ErrorWeight Times(const ErrorWeight &, const ErrorWeight &)
constexpr uint64_t kError
constexpr uint64_t kInitialAcyclic
virtual Weight Final(StateId) const =0
virtual void SetStart(StateId)=0
constexpr uint64_t kRightSemiring
virtual void SetProperties(uint64_t props, uint64_t mask)=0
uint64_t ReweightProperties(uint64_t inprops, bool added_start_epsilon)
virtual StateId Start() const =0
constexpr uint64_t kFstProperties
virtual void AddArc(StateId, const Arc &)=0
ErrorWeight Divide(const ErrorWeight &, const ErrorWeight &)
virtual StateId AddState()=0
virtual void SetFinal(StateId s, Weight weight=Weight::One())=0
virtual StateId NumStates() const =0
constexpr uint64_t kLeftSemiring
void Reweight(MutableFst< Arc > *fst, const std::vector< typename Arc::Weight > &potential, ReweightType type)