Cambridge SMT System
task.lmbr.common.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_LMBR_COMMON_HPP
16 #define TASK_LMBR_COMMON_HPP
17 
25 namespace ucam {
26 namespace lmbr {
27 
29 template<class Arc>
30 inline uint extractNGrams (fst::VectorFst<Arc> myfst,
31  std::vector<fst::NGramList>& ngramlist, uint minorder = 1, uint maxorder = 4) {
32  if (!myfst.NumStates() ) return 0;
33  std::vector<fst::NGram> tmplist;
34  fst::extractNGrams<Arc> (myfst, tmplist, maxorder);
35  if (ngramlist.size() < maxorder + 1)
36  ngramlist.resize (maxorder + 1);
37  for (std::vector<fst::NGram>::iterator it = tmplist.begin();
38  it != tmplist.end();
39  it++) {
40  uint n = it->size();
41  if (n >= minorder && n <= maxorder) {
42  ngramlist[n][*it] = fst::StdArc::Weight::One();
43  }
44  }
45  return tmplist.size();
46 };
47 
48 }
49 } // end namespaces
50 
51 #endif //TASK_LMBR_COMMON_HPP
Definition: bleu.hpp:14
uint extractNGrams(fst::VectorFst< Arc > myfst, std::vector< fst::NGramList > &ngramlist, uint minorder=1, uint maxorder=4)
Interfaces with extractNGrams and generates information in the right format for lmbr classes...