20 #ifndef FST_REWEIGHT_H_ 21 #define FST_REWEIGHT_H_ 46 const std::vector<typename Arc::Weight> &potential,
48 using Weight =
typename Arc::Weight;
53 if (type == REWEIGHT_TO_FINAL && !(Weight::Properties() &
kRightSemiring)) {
54 FSTERROR() <<
"Reweight: Reweighting to the final states requires " 55 <<
"Weight to be right distributive: " << Weight::Type();
63 FSTERROR() <<
"Reweight: Reweighting to the initial state requires " 64 <<
"Weight to be left distributive: " << Weight::Type();
70 for (; !siter.
Done(); siter.
Next()) {
71 const auto s = siter.
Value();
72 if (s == potential.size())
break;
73 const auto &weight = potential[s];
74 if (weight != Weight::Zero()) {
77 auto arc = aiter.Value();
78 if (arc.nextstate >= potential.size())
continue;
79 const auto &nextweight = potential[arc.nextstate];
80 if (nextweight == Weight::Zero())
continue;
85 if (type == REWEIGHT_TO_FINAL) {
95 if (type == REWEIGHT_TO_FINAL) {
100 for (; !siter.
Done(); siter.
Next()) {
101 const auto s = siter.
Value();
102 if (type == REWEIGHT_TO_FINAL) {
106 const auto startweight = fst->
Start() < potential.size()
107 ? potential[fst->
Start()]
109 bool added_start_epsilon =
false;
110 if ((startweight != Weight::One()) && (startweight != Weight::Zero())) {
112 const auto s = fst->
Start();
115 auto arc = aiter.Value();
117 arc.weight =
Times(startweight, arc.weight);
138 added_start_epsilon =
true;
148 #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)