Cambridge SMT System
idbridge.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 IDBRIDGE_HPP
16 #define IDBRIDGE_HPP
17 
28 namespace ucam {
29 namespace fsttools {
30 
31 class IdBridge {
32  private:
33  typedef std::unordered_map<unsigned,unsigned> MapType;
34  // rmapper (reverse) for debugging purposes only
35  MapType mapper, rmapper;
36  // output mapper for nplm with two vocabularies
37  MapType omapper, romapper;
38  public:
39  IdBridge() {}
40 
41  inline unsigned const map (unsigned idx) const {
42  MapType::const_iterator itx = mapper.find (idx);
43  if (itx != mapper.end() ) {
44  return itx->second;
45  }
46  return 0;
47  };
48 
49  inline unsigned const rmap (unsigned idx) const {
50  MapType::const_iterator itx = rmapper.find (idx);
51  if (itx != rmapper.end() )
52  return itx->second;
53  return 0;
54  };
55 
56 
57  inline unsigned const mapOutput (unsigned idx) const {
58  MapType::const_iterator itx = omapper.find (idx);
59  if (itx != omapper.end() ) {
60  return itx->second;
61  }
62  return 0;
63  };
64 
65  inline unsigned const rmapOutput (unsigned idx) const {
66  MapType::const_iterator itx = romapper.find (idx);
67  if (itx != romapper.end() )
68  return itx->second;
69  return 0;
70  };
71 
72 
73  inline void add (unsigned grammar_idx, unsigned lm_idx) {
74  LDEBUG ("grammar idx=" << grammar_idx << ", lm_idx=" << lm_idx);
75  mapper[grammar_idx] = lm_idx;
76 #ifdef PRINTDEBUG1
77  rmapper[lm_idx] = grammar_idx;
78 #endif
79  }
80 
81 
82  inline void addOutput (unsigned grammar_idx, unsigned lm_idx) {
83  LDEBUG ("ovocab: grammar idx=" << grammar_idx << ", lm_idx=" << lm_idx);
84  omapper[grammar_idx] = lm_idx;
85 #ifdef PRINTDEBUG1
86  romapper[lm_idx] = grammar_idx;
87 #endif
88  }
89 };
90 
91 }} // end namespaces
92 #endif
unsigned const mapOutput(unsigned idx) const
Definition: idbridge.hpp:57
unsigned const rmap(unsigned idx) const
Definition: idbridge.hpp:49
#define LDEBUG(msg)
void addOutput(unsigned grammar_idx, unsigned lm_idx)
Definition: idbridge.hpp:82
unsigned const rmapOutput(unsigned idx) const
Definition: idbridge.hpp:65
unsigned const map(unsigned idx) const
Definition: idbridge.hpp:41
void add(unsigned grammar_idx, unsigned lm_idx)
Definition: idbridge.hpp:73
Definition: bleu.hpp:14