Cambridge SMT System
task.hifst.expandednumstates.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_EXPANDEDNUMSTATES_HPP
16 #define TASK_HIFST_EXPANDEDNUMSTATES_HPP
17 
26 namespace ucam {
27 namespace hifst {
28 
35 template<class Arc>
37  private:
39  unordered_map< uint , uint > rtnnumstates_;
40  public:
43 
45  inline uint operator() ( uint cc, uint x, uint y ) {
46  uint hieroindex = APBASETAG + cc * APCCTAG + x * APXTAG + y * APYTAG;
47  return rtnnumstates_[hieroindex];
48  };
49 
61  void update ( uint cc, uint x, uint y, fst::VectorFst<Arc> *myfst ) {
62  uint hieroindex = APBASETAG + cc * APCCTAG + x * APXTAG + y * APYTAG;
63  uint& ns = rtnnumstates_[hieroindex];
64  ns = myfst->NumStates();
65  LDEBUG ( "AT: " << cc << "," << x << "," << y << ":" << ",NS=" <<
66  rtnnumstates_[hieroindex] );
67  typedef typename Arc::StateId StateId;
68  for ( fst::StateIterator< fst::VectorFst<Arc> > si ( *myfst ); !si.Done();
69  si.Next() ) {
70  StateId state_id = si.Value();
71  for ( fst::ArcIterator< fst::VectorFst<Arc> > ai ( *myfst , si.Value() );
72  !ai.Done(); ai.Next() ) {
73  const Arc& arc = ai.Value();
74  if ( arc.ilabel < APBASETAG ) continue;
75  ns += rtnnumstates_[arc.ilabel] - 2;
76  }
77  }
78  LINFO ( "AT: " << cc << "," << x << "," << y << ":" << "NS (expanded) =" <<
79  ns );
80  };
81 
82  private:
83  DISALLOW_COPY_AND_ASSIGN ( ExpandedNumStatesRTN );
84 };
85 
86 }
87 } // end namespaces
88 
89 #endif //ifndef TASK_HIFST_EXPANDEDNUMSTATES_HPP
#define APBASETAG
#define LINFO(msg)
#define LDEBUG(msg)
#define APXTAG
void update(uint cc, uint x, uint y, fst::VectorFst< Arc > *myfst)
Estimates (expanded) number of states of rtn_[cc][x][y] Traverses arcs and and add number of states o...
uint operator()(uint cc, uint x, uint y)
Returns estimated number of states for an rtn with a root fst at (cc,x,y)
#define APYTAG
Utility class that, given an RTN with root at (cc,x,y), estimates the number of states of an expanded...
#define APCCTAG
Definition: bleu.hpp:14