Cambridge SMT System
lexicographic-tropical-tropical-funcs.h
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
15 #ifndef LEXICOGRAPHIC_TROPICAL_TROPICAL_FUNCS_H
16 #define LEXICOGRAPHIC_TROPICAL_TROPICAL_FUNCS_H
17 
25 namespace fst {
26 
27 template<class Arc>
28 struct GetWeight {
29  float operator () ( const typename Arc::Weight& weight ) {
30  return weight.Value();
31  }
32  // float getNotConst( typename Arc::Weight weight ) { return weight.Value();}
33 };
34 
35 template<>
37  float operator () ( const LexStdArc::Weight& weight ) {
38  return weight.Value1().Value();
39  }
40  // float getNotConst( LexStdArc::Weight weight ) { return weight.Value1().Value();}
41 };
42 
46 template<class Arc>
47 struct MakeWeight {
48  inline typename Arc::Weight operator () ( const float weight ) const {
49  return typename Arc::Weight ( weight );
50  };
51  inline typename Arc::Weight operator () ( const typename Arc::Weight& weight )
52  const {
53  return weight ;
54  };
55  inline void update() {};
56 };
57 
61 template<>
63  inline LexStdWeight operator () ( const float weight ) {
64  return LexStdWeight ( weight, StdArc::Weight::One() );
65  };
66  inline LexStdWeight operator () ( const StdArc::Weight& weight ) {
67  return LexStdWeight ( weight.Value(), StdArc::Weight::One() );
68  };
69  inline LexStdWeight operator () ( const LexStdWeight& weight ) {
70  return LexStdWeight ( weight.Value1(), StdArc::Weight::One() );
71  };
72  inline void update() {};
73 };
74 
79 template<class Arc>
80 struct MakeWeight2 {
81  typedef typename Arc::Weight Weight;
82  inline Weight operator () (float const weight ) const {
83  return Weight ( weight );
84  };
85  inline Weight operator () (Weight const & weight) const {
86 
87  return weight ;
88  };
89  inline void update() {};
90 };
91 
95 template<>
97  inline const LexStdWeight operator () ( const float weight ) const {
98  return LexStdWeight ( weight, weight );
99  };
100  inline const LexStdWeight operator () ( const StdArc::Weight& weight ) const {
101  return LexStdWeight ( weight.Value(), weight.Value() );
102  };
103  inline const LexStdWeight operator () ( const LexStdWeight& weight ) const {
104  return LexStdWeight ( weight.Value2(), weight.Value2() );
105  };
106  inline void update() {};
107 };
108 
112 template<class Arc>
113 struct ScaleWeight {
114  ScaleWeight ( float scale ) :
115  scale_ ( scale ) {
116  };
117 
118  inline typename Arc::Weight operator () ( const float weight ) const {
119  return typename Arc::Weight ( weight * scale_ );
120  };
121  inline typename Arc::Weight operator () ( const typename Arc::Weight& weight )
122  const {
123  return weight.Value() * scale_;
124  };
125 
126  float scale_;
127 
128 };
129 
134 template<>
136  ScaleWeight ( float scale ) :
137  scale_ ( scale ) {
138  };
139  inline const LexStdWeight operator () ( const float weight ) const {
140  return LexStdWeight ( weight * scale_, weight * scale_ );
141  };
142  inline const LexStdWeight operator () ( const LexStdWeight& weight ) const {
143  return LexStdWeight ( scale_ * weight.Value1().Value(),
144  scale_ * weight.Value2().Value() );
145  };
146  float scale_;
147 };
148 
149 struct LexToStd {
150  inline StdArc::Weight operator () ( const LexStdWeight& weight ) const {
151  return StdArc::Weight ( weight.Value1() );
152  };
153 };
154 
155 }; //namespace fst
156 
157 #endif
LexStdArc::Weight LexStdWeight
float operator()(const typename Arc::Weight &weight)
Definition: fstio.hpp:27
Function object that applies to every single weight a scaling factor.
Templated functor that creates a weight given a float.
Templated functor that creates a weight given a float.
LexicographicArc< StdArc::Weight, StdArc::Weight > LexStdArc