summaryrefslogtreecommitdiff
path: root/klm/alone/vocab.hh
blob: 3ac0f542abac24d3879caea20a2a97a7b187ba8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef ALONE_VOCAB__
#define ALONE_VOCAB__

#include "lm/word_index.hh"
#include "util/string_piece.hh"

#include <boost/functional/hash/hash.hpp>
#include <boost/unordered_map.hpp>

#include <string>

namespace lm { namespace base { class Vocabulary; } }

namespace alone {

class Vocab {
  public:
    explicit Vocab(const lm::base::Vocabulary &backing);

    const std::pair<const std::string, lm::WordIndex> &FindOrAdd(const StringPiece &str);

    const std::pair<const std::string, lm::WordIndex> &EndSentence() const { return end_sentence_; }

  private:
    typedef boost::unordered_map<std::string, lm::WordIndex> Map;
    Map map_;

    const lm::base::Vocabulary &backing_;

    const std::pair<const std::string, lm::WordIndex> &end_sentence_;
};

} // namespace alone
#endif // ALONE_VCOAB__