43 const Fst<Arc> &
fst,
const std::vector<typename Arc::Weight> &distance,
46 return fst.
Start() < distance.size() ? distance[fst.
Start()]
47 : Arc::Weight::Zero();
49 auto sum = Arc::Weight::Zero();
50 for (
typename Arc::StateId s = 0; s < distance.size(); ++s) {
62 using Weight =
typename Arc::Weight;
63 if ((weight == Weight::One()) || (weight == Weight::Zero()))
return;
71 const auto start = fst->
Start();
74 auto arc = aiter.Value();
93 using Weight =
typename Arc::Weight;
94 std::vector<Weight> distance;
97 if (remove_total_weight) {
117 template <
class Arc, ReweightType rtype>
120 using Label =
typename Arc::Label;
121 using Weight =
typename Arc::Weight;
122 if ((ptype & (kPushWeights | kPushLabels)) == kPushWeights) {
124 Push(ofst, rtype, delta, ptype & kPushRemoveTotalWeight);
125 }
else if (ptype & kPushLabels) {
129 std::vector<GallicWeight> gdistance;
132 if (ptype & kPushWeights) {
140 if (ptype & (kPushRemoveTotalWeight | kPushRemoveCommonAffix)) {
144 ptype & kPushRemoveCommonAffix
145 ? total_weight.Value1()
147 ptype & kPushRemoveTotalWeight ? total_weight.Value2()
151 if (ptype & (kPushRemoveTotalWeight | kPushRemoveCommonAffix)) {
159 LOG(WARNING) <<
"Push: pushing type is set to 0, so not pushing";
166 #endif // FST_PUSH_H_ void ArcMap(MutableFst< A > *fst, C *mapper)
constexpr uint8_t kPushRemoveCommonAffix
constexpr uint8_t kPushLabels
ErrorWeight Plus(const ErrorWeight &, const ErrorWeight &)
void RemoveWeight(MutableFst< Arc > *fst, const typename Arc::Weight &weight, bool at_final)
ErrorWeight Times(const ErrorWeight &, const ErrorWeight &)
virtual Weight Final(StateId) const =0
Arc::Weight ComputeTotalWeight(const Fst< Arc > &fst, const std::vector< typename Arc::Weight > &distance, bool reverse)
constexpr uint8_t kPushWeights
virtual StateId Start() const =0
static const GallicWeight & One()
constexpr float kShortestDelta
void Push(MutableFst< Arc > *fst, ReweightType type=REWEIGHT_TO_INITIAL, float delta=kShortestDelta, bool remove_total_weight=false)
ErrorWeight Divide(const ErrorWeight &, const ErrorWeight &)
virtual void SetFinal(StateId s, Weight weight=Weight::One())=0
void ShortestDistance(const Fst< Arc > &fst, std::vector< typename Arc::Weight > *distance, const ShortestDistanceOptions< Arc, Queue, ArcFilter > &opts)
virtual void SetOutputSymbols(const SymbolTable *osyms)=0
constexpr uint8_t kPushRemoveTotalWeight
void Reweight(MutableFst< Arc > *fst, const std::vector< typename Arc::Weight > &potential, ReweightType type)
virtual const SymbolTable * OutputSymbols() const =0