Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions openfst/lib/rmfinalepsilon.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,22 @@ void RmFinalEpsilon(MutableFst<Arc>* fst) {
const auto& arc = aiter.Value();
// Next state is in the list of finals.
if (finals.find(arc.nextstate) != finals.end()) {
// Sums up all epsilon arcs if the semiring is left distributive.
// When left distributivity does not hold, at most one arc can be
// removed.
if (arc.ilabel == 0 && arc.olabel == 0 &&
(weight == Weight::Zero() ||
(Weight::Properties() & kLeftSemiring))) {
weight = Plus(Times(arc.weight, fst->Final(arc.nextstate)), weight);
// If the semiring is left-distributive we don't need to check if the
// weight is zero.
constexpr bool kIsLeftSemiring =
(Weight::Properties() & kLeftSemiring) != 0;
if constexpr (kIsLeftSemiring) {
if (arc.ilabel == 0 && arc.olabel == 0) {
weight = Plus(Times(arc.weight, fst->Final(arc.nextstate)), weight);
} else {
arcs.push_back(arc);
}
} else {
arcs.push_back(arc);
if (arc.ilabel == 0 && arc.olabel == 0 && weight == Weight::Zero()) {
weight = Plus(Times(arc.weight, fst->Final(arc.nextstate)), weight);
} else {
arcs.push_back(arc);
}
}
} else {
arcs.push_back(arc);
Expand Down
Loading