Cambridge SMT System
task.hifst.localpruningconditions.hpp
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 TASK_HIFST_LOCALPRUNINGCONDITIONS_HPP
16 #define TASK_HIFST_LOCALPRUNINGCONDITIONS_HPP
17 
25 namespace ucam {
26 namespace hifst {
27 
29 struct conditions {
31  cat ( 0 ),
32  span ( 0 ),
33  lpns ( 0 ),
34  lpw ( 0.0f ) {
35  };
36 
37  conditions ( unsigned category, unsigned span, unsigned numstates,
38  float weight ) :
39  cat ( category ),
40  span ( span ),
41  lpns ( numstates ),
42  lpw ( weight ) {
43  };
45  unsigned cat;
47  unsigned span;
49  unsigned lpns;
51  float lpw;
52 } ;
53 
61  //Private variables are shown here. Private methods go after public methods
62  private:
63 
65  std::map<uint64, conditions> lpc_;
66  public:
69 
71  inline void add ( const conditions& c ) {
72  lpc_[c.cat * 100000000000 + c.span * 100000000 + c.lpns % 100000000 ] = c;
73  };
74 
83  bool operator () ( unsigned cc, unsigned span, unsigned numstates , float& w ) {
84  if ( ! lpc_.size() ) return false;
85  uint64 catspan = cc * 100000000000 + span * 100000000 +
86  ( numstates % 100000000 );
88  std::map <uint64, conditions>::iterator itx;
89  itx = lpc_.lower_bound ( catspan );
90  if ( itx == lpc_.end() ) --itx;
91  else if ( itx->first != catspan && itx != lpc_.begin() ) --itx;
92  while ( itx->second.cat == cc && ( itx->second.span > span
93  || itx->second.lpns > numstates ) && itx != lpc_.begin() ) --itx;
94  LINFO ( "AT " << cc << ", ? ," << span - 1 << ": actual cell=" << catspan <<
95  " closest conditions=" << itx->first );
96  if ( itx->second.cat != cc || itx->second.span > span
97  || itx->second.lpns > numstates ) return false;
98  w = itx->second.lpw;
99  return true;
100  };
101 
103  inline std::size_t size() {
104  return lpc_.size();
105  };
106 
108  inline void clear() {
109  lpc_.clear();
110  };
111 
112  private:
114 
115 };
116 
117 }
118 } // end namespaces
119 
120 #endif //TASK_HIFST_LOCALPRUNINGCONDITIONS_HPP
#define ZDISALLOW_COPY_AND_ASSIGN(TypeName)
struct containing the elements that trigger local pruning.
#define LINFO(msg)
conditions(unsigned category, unsigned span, unsigned numstates, float weight)
void add(const conditions &c)
Add condition.
convenience class that takes care of local pruning conditions. Conditions are indexed by 1000*cc+y...
Definition: bleu.hpp:14