Cambridge SMT System
tropical-sparse-tuple-weight.makeweight.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 TROPICALSPARSETUPLEWEIGHT_MAKEWEIGHT_H_
16 #define TROPICALSPARSETUPLEWEIGHT_MAKEWEIGHT_H_
17 
25 namespace fst {
26 
28 template<typename Arc = StdArc>
30  explicit MakeSparseVectorWeight ( int32_t k ) :
31  k ( k ) {
32  }
33 
34  inline TropicalSparseTupleWeight<float> operator() ( const typename Arc::Weight&
35  w ) const {
37  result.Push ( k + 1, w.Value() );
38  return result;
39  }
40 
41  private:
42  int32_t k;
43 };
44 
46 template<>
48  explicit MakeSparseVectorWeight ( int32_t k ) :
49  k ( k ) {
50  }
51 
52  inline TropicalSparseTupleWeight<float> operator() ( const LexStdArc::Weight&
53  w ) const {
55  result.Push ( k + 1, w.Value1().Value() );
56  return result;
57  }
58  private:
59  int32_t k;
60 };
61 
63 template<>
66  explicit MakeWeight ( int32_t k = 0 ) :
67  k_ ( k ) {
68  };
69 
71  inline TupleArc32::Weight operator () ( const float weight ) const {
73  result.Push ( k_ + 1, weight );
74  return result;
75  };
77  inline TupleArc32::Weight operator () ( const TupleArc32::Weight& weight )
78  const {
79  return weight ;
80  };
81 
83  inline void update() {
84  ++k_;
85  };
86  inline int32_t get_k() {
87  return k_;
88  };
89  private:
90  int32_t k_;
91 };
92 
93 } //namespace fst
94 
95 #endif /* TROPICALSPARSETUPLEWEIGHT_MAKEWEIGHT_H_ */
Definition: fstio.hpp:27
Templated Functor to generate a sparse vector weight from any other representation.
Implements Tropical Sparse tuple weight semiring, extending from openfst SparsePowerWeight class...
Templated functor that creates a weight given a float.
void update()
Increases index. Provides a way to do sequentially transparent operations, e.g. language model compos...
TropicalSparseTupleWeight< float > operator()(const typename Arc::Weight &w) const
fst::ArcTpl< TupleW32 > TupleArc32
LexicographicArc< StdArc::Weight, StdArc::Weight > LexStdArc
MakeWeight(int32_t k=0)
It is specially important that k defaults to 0 in this case, as MakeWeight is used by applylanguagemo...