15 #ifndef FSTUTILS_MAPPER_HPP 16 #define FSTUTILS_MAPPER_HPP 31 template<
class Arc,
class WeightMakerFunctorT>
41 return Arc ( arc.ilabel, arc.olabel,
mw_ ( arc.weight ), arc.nextstate );
45 return MAP_COPY_SYMBOLS;
48 return MAP_COPY_SYMBOLS;
51 return MAP_NO_SUPERFINAL;
58 WeightMakerFunctorT
const &
mw_;
68 template<
class FromArc,
class ToArc,
class WeightMakerFunctorT >
74 if ( arc.weight == FromArc::Weight::Zero() )
75 return ToArc ( arc.ilabel, arc.olabel, ToArc::Weight::Zero(), arc.nextstate );
76 if ( arc.weight == FromArc::Weight::One() )
77 return ToArc ( arc.ilabel, arc.olabel, ToArc::Weight::One(), arc.nextstate );
78 return ToArc ( arc.ilabel, arc.olabel,
mw_ ( arc.weight ), arc.nextstate );
82 return MAP_COPY_SYMBOLS;
85 return MAP_COPY_SYMBOLS;
88 return MAP_NO_SUPERFINAL;
91 return ( props & kWeightInvariantProperties ) | kUnweighted;
96 WeightMakerFunctorT
const &
mw_;
100 template<
class FromArc,
class ToArc,
class ArcMakerFunctorT >
110 return MAP_COPY_SYMBOLS;
113 return MAP_COPY_SYMBOLS;
116 return MAP_NO_SUPERFINAL;
119 return ( props & kWeightInvariantProperties ) | kUnweighted;
123 ArcMakerFunctorT
const &ma_;
127 template<
class Arc,
class ArcMakerFunctorT >
137 return MAP_COPY_SYMBOLS;
140 return MAP_COPY_SYMBOLS;
143 return MAP_NO_SUPERFINAL;
146 return ( props & kWeightInvariantProperties ) | kUnweighted;
150 ArcMakerFunctorT
const &ma_;
164 unordered_set<typename Arc::Label> epsilons) :
165 epsilons_ (epsilons),
171 if (epsilons_.find (arc.ilabel) != epsilons_.end() )
172 return Arc ( arc.ilabel, arc.olabel, arc.weight, arc.nextstate );
173 return Arc ( arc.ilabel, arc.olabel,
Times (arc.weight, wp_), arc.nextstate );
177 return MAP_COPY_SYMBOLS;
180 return MAP_COPY_SYMBOLS;
183 return MAP_NO_SUPERFINAL;
199 typedef ToArc::Weight
W;
203 CHECK (!i || i == 1 || i == 2);
207 FromArc::Weight w1 = (i_ == 1
208 || !i_) ? arc.weight.Value() : FromArc::Weight::One();
209 FromArc::Weight w2 = (i_ == 2
210 || !i_) ? arc.weight.Value() : FromArc::Weight::One();
212 return LexStdArc (arc.ilabel, arc.olabel, w, arc.nextstate);
216 return MAP_COPY_SYMBOLS;
219 return MAP_COPY_SYMBOLS;
222 return MAP_NO_SUPERFINAL;
234 typedef ToArc::Weight
W;
239 CHECK (i == 1 || i == 2 || i == 0);
245 w =
Times ( arc.weight.Value1(), arc.weight.Value2() );
247 w = arc.weight.Value1();
249 w = arc.weight.Value2();
250 return StdArc (arc.ilabel, arc.olabel, w, arc.nextstate);
254 return MAP_COPY_SYMBOLS;
258 return MAP_COPY_SYMBOLS;
262 return MAP_NO_SUPERFINAL;
WordPenaltyMapper(typename Arc::Weight wp, unordered_set< typename Arc::Label > epsilons)
Constructor.
GenericArcAutoMapper(const ArcMakerFunctorT &ma)
MapFinalAction FinalAction() const
templated Mapper that inserts a word penalty over an FST, skipping user defined epsilon arcs...
MapSymbolsAction InputSymbolsAction() const
MapSymbolsAction OutputSymbolsAction() const
MapSymbolsAction InputSymbolsAction() const
MapSymbolsAction InputSymbolsAction() const
templated Mapper that modifies weights over an FST, passing through the other values of the arc...
uint Properties(uint props) const
StdArc to LexStdArc mapper.
MapSymbolsAction OutputSymbolsAction() const
MapSymbolsAction OutputSymbolsAction() const
MapFinalAction FinalAction() const
Arc operator()(const Arc &arc) const
Takes arc as input parameter and returns modified arc.
LexStdArc to StdArc Mapper.
MapSymbolsAction OutputSymbolsAction() const
MapFinalAction FinalAction() const
unordered_set< typename Arc::Label > epsilons_
MapFinalAction FinalAction() const
MapSymbolsAction InputSymbolsAction() const
templated Mapper that modifies weights when copying from one FST to another, passing through the othe...
uint Properties(uint props) const
Arc::Weight wp_
Specialized functor that modifies arc weights.
uint Properties(uint props) const
MapFinalAction FinalAction() const
MapFinalAction FinalAction() const
StdToLexStdMapper(int i=0)
LexicographicArc< StdArc::Weight, StdArc::Weight > LexStdArc
MapSymbolsAction InputSymbolsAction() const
TropicalSparseTupleWeight< T > Times(const TropicalSparseTupleWeight< T > &w1, const TropicalSparseTupleWeight< T > &w2)
WeightMakerFunctorT const & mw_
Specialized functor that modifies arc weights.
MapSymbolsAction InputSymbolsAction() const
uint Properties(uint props) const
uint Properties(uint props) const
MapSymbolsAction OutputSymbolsAction() const
MapFinalAction FinalAction() const
MapSymbolsAction InputSymbolsAction() const
uint Properties(uint props) const
GenericArcMapper(const ArcMakerFunctorT &ma)
uint Properties(uint props) const
MapSymbolsAction OutputSymbolsAction() const
MapSymbolsAction OutputSymbolsAction() const
GenericWeightMapper(const WeightMakerFunctorT &mw)
GenericWeightAutoMapper(const WeightMakerFunctorT &mw)
Constructor.