Cambridge SMT System
common-helpers.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <registrypo.hpp>
4 #include <kenlmdetect.hpp>
5 
6 namespace ucam {
7 namespace fsttools {
8 
14 template <
15  template <template <class> class
16  , class> class TaskOneT
17  , template <template <class> class
18  , class> class TaskTwoT
19  , template <class> class DataT
20  , class ArcT
21  >
22 struct RunTask2 {
23  explicit RunTask2(util::RegistryPO const &rg){
24  using util::Runner2;
25  ( Runner2<
26  TaskOneT< DataT, ArcT>
27  , TaskTwoT< DataT, ArcT>
28  >
29  ( rg ) ) ();
30  }
31 };
32 
38 template <
39  template <template <class> class
40  , class> class TaskOneT
41  , template <template <class> class
42  , class> class TaskTwoT
43  , template <template <class> class
44  , class> class TaskThreeT
45  , template <class> class DataT
46  , class ArcT
47  >
48 struct RunTask3 {
49  explicit RunTask3(util::RegistryPO const &rg){
50  using util::Runner3;
51  ( Runner3<
52  TaskOneT< DataT, ArcT>
53  , TaskTwoT< DataT, ArcT>
54  , TaskThreeT< DataT, ArcT>
55  >
56  ( rg ) ) ();
57  }
58 };
59 
60 #ifdef KENLM_MAX_ORDER
61 
72 template< template < template <class, class> class
73  , class
74  , class> class RunTaskT
75  , template <class, class> class DataT
76  , class ArcT
77  >
78 inline void runTaskWithKenLMTemplate(ucam::util::RegistryPO const &rg) {
79  using namespace lm::ngram;
80  using namespace ucam::util;
81  // Detect here kenlm binary type
82  // it's a bit ugly this way of initializing the correct kenlm handler
83  ModelType kenmt = ucam::util::detectkenlm
84  (rg.getVectorString (HifstConstants::kLmLoad, 0) );
85 
86  switch (kenmt) {
87  case PROBING:
88  (RunTaskT<DataT, ProbingModel, ArcT>(rg));
89  break;
90  case REST_PROBING:
91  (RunTaskT<DataT, RestProbingModel, ArcT>(rg));
92  break;
93  case TRIE:
94  (RunTaskT<DataT, TrieModel, ArcT>(rg));
95  break;
96  case QUANT_TRIE:
97  (RunTaskT<DataT, QuantTrieModel, ArcT>(rg));
98  break;
99  case ARRAY_TRIE:
100  (RunTaskT<DataT, ArrayTrieModel, ArcT>(rg));
101  break;
102  case QUANT_ARRAY_TRIE:
103  (RunTaskT<DataT, QuantArrayTrieModel, ArcT>(rg));
104  break;
105  case KENLM_NPLM:
106 #ifdef WITH_NPLM
107  (RunTaskT<DataT, lm::np::Model, ArcT>(rg));
108  break;
109 #endif
110  std::cerr << "Unsuported format: KENLM_NPLM. Did you compile NPLM library?" << std::endl;
111  exit(EXIT_FAILURE);
112  }
113 };
114 #endif
115 
116 }} // end namespaces
Convenience wrapper class that can kick off three type of executions: singlethreaded, multithreaded, or server, triggered by program options. Possibly multithreading with 1 thread would do, but I keep both implementations as any plain bug that might arise will be easier to trace down with a single thread execution. The class is templated three functors, one for each type of execution Note that the details are up to the each of these functors.
Generic Runner2 class wrapper with the usual template structure required by the tasks in fsttools and...
RunTask2(util::RegistryPO const &rg)
Convenience wrapper class that can kick off two type of executions: single or multithreaded, triggered by program options. Possibly multithreading with 1 thread would do, but I keep both implementations as any plain bug that might arise will be easier to trace down with a serialized execution (threadpool uses two, actually). The class is templated with two classes, one for single threading and another for multithreading. Note that the multithreading details are up to the second templated class.
Generic Runner3 class wrapper with the usual template structure required by hifst. It can be used by other tools that should support a server mode (see Runner2/Runner3 details).
RunTask3(util::RegistryPO const &rg)
std::string const kLmLoad
Contains wrapper class RegistryPO, which uses boost::program_options to parse parameters, and provides methods to access them.
Definition: bleu.hpp:14