15 before (0), after (0) {
26 const std::vector<FunctionWeight>& distance,
PruneStats& stats) {
32 void Prune (fst::MutableFst<FunctionArc> *
fst) {
33 std::map<StatePair, int> dupeArcs;
34 std::map<StatePair, FunctionWeight> summedWeights;
36 for (fst::StateIterator < fst::MutableFst<FunctionArc> > siter (*fst);
37 !siter.Done(); siter.Next() ) {
40 for (fst::ArcIterator < fst::MutableFst<FunctionArc> > aiter (*fst,
41 siter.Value() ); !aiter.Done(); aiter.Next() ) {
47 if (summedWeights.count (pair) == 0) {
48 summedWeights[pair] = arc.
weight;
51 summedWeights[pair] =
Plus (summedWeights[pair], arc.
weight);
58 for (std::map<StatePair, int>::iterator it = dupeArcs.begin(); it
59 != dupeArcs.end(); ++it) {
61 for (fst::MutableArcIterator < fst::MutableFst<FunctionArc> > aiter (fst,
62 it->first.first); !aiter.Done(); aiter.Next() ) {
66 for (MertList::const_iterator miter =
67 summedWeights[it->first].Value().begin(); miter
68 != summedWeights[it->first].Value().end(); ++miter) {
85 const std::vector<FunctionWeight>& distance) {
87 for (fst::StateIterator < fst::MutableFst<FunctionArc> > siter (*fst);
88 !siter.Done(); siter.Next() ) {
89 std::map<FunctionArc::StateId, FunctionWeight> otherArcs;
90 for (fst::ArcIterator < fst::Fst<FunctionArc> > aiter (*fst, siter.Value() );
91 !aiter.Done(); aiter.Next() ) {
93 if (otherArcs.count (arc.
nextstate) == 0) {
104 std::set<FunctionArc::StateId> toDelete;
105 for (std::map<FunctionArc::StateId, FunctionWeight>::iterator outer =
106 otherArcs.begin(); outer != otherArcs.end(); ++outer) {
108 for (std::map<FunctionArc::StateId, FunctionWeight>::iterator inner =
109 otherArcs.begin(); inner != otherArcs.end(); ++inner) {
110 if (outer->first != inner->first) {
111 otherSum =
Plus (otherSum, inner->second);
114 if (otherSum == distance[siter.Value()]) {
115 toDelete.insert (outer->first);
118 for (fst::MutableArcIterator < fst::MutableFst<FunctionArc> > aiter (fst,
119 siter.Value() ); !aiter.Done(); aiter.Next() ) {
121 if (toDelete.count (arc.
nextstate) > 0) {
123 aiter.SetValue (arc);
132 for (fst::StateIterator < fst::Fst<FunctionArc> > siter (fst); !siter.Done();
135 for (fst::ArcIterator < fst::Fst<FunctionArc> > aiter (fst, siter.Value() );
136 !aiter.Done(); aiter.Next() ) {
void Prune(fst::MutableFst< FunctionArc > *fst, PruneStats &stats)
static const FunctionWeight & Zero()
const MertList & Value() const
TropicalSparseTupleWeight< T > Plus(const TropicalSparseTupleWeight< T > &vw1, const TropicalSparseTupleWeight< T > &vw2)
void FullPrune(fst::MutableFst< FunctionArc > *fst, const std::vector< FunctionWeight > &distance, PruneStats &stats)
TropicalSparseTupleWeight< T > Times(const TropicalSparseTupleWeight< T > &w1, const TropicalSparseTupleWeight< T > &w2)
pair< FunctionArc::StateId, FunctionArc::StateId > StatePair
int ArcCount(const fst::Fst< FunctionArc > &fst)