46 const Fst<Arc> &
fst,
const std::vector<typename Arc::Weight> &distance,
49 return fst.
Start() < distance.size() ? distance[fst.
Start()]
50 : Arc::Weight::Zero();
52 auto sum = Arc::Weight::Zero();
53 for (
typename Arc::StateId s = 0; s < distance.size(); ++s) {
65 using Weight =
typename Arc::Weight;
66 if ((weight == Weight::One()) || (weight == Weight::Zero()))
return;
74 const auto start = fst->
Start();
77 auto arc = aiter.Value();
96 using Weight =
typename Arc::Weight;
97 std::vector<Weight> distance;
100 if (remove_total_weight) {
120 template <
class Arc, ReweightType rtype>
123 using Label =
typename Arc::Label;
124 using Weight =
typename Arc::Weight;
125 if ((ptype & (kPushWeights | kPushLabels)) == kPushWeights) {
127 Push(ofst, rtype, delta, ptype & kPushRemoveTotalWeight);
128 }
else if (ptype & kPushLabels) {
132 std::vector<GallicWeight> gdistance;
135 if (ptype & kPushWeights) {
143 if (ptype & (kPushRemoveTotalWeight | kPushRemoveCommonAffix)) {
147 ptype & kPushRemoveCommonAffix
148 ? total_weight.Value1()
150 ptype & kPushRemoveTotalWeight ? total_weight.Value2()
154 if (ptype & (kPushRemoveTotalWeight | kPushRemoveCommonAffix)) {
162 LOG(WARNING) <<
"Push: pushing type is set to 0, so not pushing";
169 #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