15 #ifndef HIFSTENUMERATE_HPP 16 #define HIFSTENUMERATE_HPP 24 #include <lm/config.hh> 25 #include <lm/enumerate_vocab.hh> 37 template<
class WordMapperT>
47 virtual void Add (WordIndex index,
const StringPiece& str) {
48 std::string s = str.as_string();
52 void Add (WordIndex index,
const std::string& s) {
54 LDEBUG (
"Converting ... s=" << s <<
",lm_idx=" << index);
55 if (s ==
"<s>") t = 1;
56 else if (s ==
"</s>") t = 2;
57 else if (s ==
"<unk>") t = 0;
59 else if (s ==
"<null>") t = 3;
61 else if (wm_ == NULL) t = ucam::util::toNumber<unsigned> (s);
64 LDEBUG (
"Found gidx = " << t);
66 if (t < std::numeric_limits<unsigned>::max() ) {
67 LDEBUG (
"Adding " << t <<
" => " << index);
72 void AddOutput (WordIndex index,
const std::string& s) {
74 LDEBUG (
"Converting ... s=" << s <<
",lm_idx=" << index);
75 if (s ==
"<s>") t = 1;
76 else if (s ==
"</s>") t = 2;
77 else if (s ==
"<unk>") t = 0;
79 else if (s ==
"<null>") t = 3;
81 else if (wm_ == NULL) t = ucam::util::toNumber<unsigned> (s);
84 LDEBUG (
"Found gidx = " << t);
86 if (t < std::numeric_limits<unsigned>::max() ) {
87 LDEBUG (
"Adding " << t <<
" => " << index);
virtual void Add(WordIndex index, const StringPiece &str)
This class extends EnumerateVocab in kenlm code. This class creates a grammar-integer to lm-integer h...
virtual ~HifstEnumerateVocab()
void Add(WordIndex index, const std::string &s)
HifstEnumerateVocab(IdBridge &idb, WordMapperT *wm)
void AddOutput(WordIndex index, const std::string &s)