Cambridge SMT System
kenlmdetect.hpp
Go to the documentation of this file.
1 // Adapted from kenlm code
2 #ifndef KENLM_UTIL_HPP
3 #define KENLM_UTIL_HPP
4 
5 #ifndef KENLM_MAX_ORDER
6 #else
7 
8 
9 #include <lm/binary_format.hh>
10 #include <lm/model.hh>
11 #ifdef WITH_NPLM
12 #include <lm/wrappers/nplm.hh>
13 #endif
14 
18 namespace ucam {
19 namespace util {
20 
21 
26 enum {KENLM_NPLM=-1};
27 
28 inline int detectkenlm (std::string const& kenlmfile) {
29  lm::ngram::ModelType model_type;
30  if (kenlmfile == "" ) {
31  FORCELINFO("Empty language model file name. Sets to Probing.");
32  return lm::ngram::PROBING;
33  }
34  if (lm::ngram::RecognizeBinary (kenlmfile.c_str(), model_type) ) {
35  switch (model_type) {
36  case lm::ngram::PROBING:
37  case lm::ngram::REST_PROBING:
38  case lm::ngram::TRIE:
39  case lm::ngram::QUANT_TRIE:
40  case lm::ngram::ARRAY_TRIE:
41  case lm::ngram::QUANT_ARRAY_TRIE:
42  return model_type;
43  default:
44  LERROR ("Unrecognized kenlm model type " << model_type );
45  exit (EXIT_FAILURE);
46  }
47 #ifdef WITH_NPLM
48  } else if (lm::np::Model::Recognize(kenlmfile)) {
49  return KENLM_NPLM;
50 #endif
51  } else { // arpa file, right?
52  return lm::ngram::PROBING;
53  }
54 }
55 
56 }} // end namespaces
57 
58 #endif
59 #endif
#define FORCELINFO(msg)
#define LERROR(msg)
Definition: bleu.hpp:14