summaryrefslogtreecommitdiff
path: root/klm/search/weights.hh
blob: 4a4388c797678cd514b11b7c65a58e9ee72d78ef (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// For now, the individual features are not kept.  
#ifndef SEARCH_WEIGHTS__
#define SEARCH_WEIGHTS__

#include "search/types.hh"
#include "util/exception.hh"
#include "util/string_piece.hh"

#include <boost/unordered_map.hpp>

#include <string>

namespace search {

class WeightParseException : public util::Exception {
  public:
    WeightParseException() {}
    ~WeightParseException() throw() {}
};

class Weights {
  public:
    // Parses weights, sets lm_weight_, removes it from map_.
    explicit Weights(StringPiece text);

    search::Score DotNoLM(StringPiece text) const;

    search::Score LM() const { return lm_; }

    search::Score OOV() const { return oov_; }

    search::Score WordPenalty() const { return word_penalty_; }

    // Mostly for testing.  
    const boost::unordered_map<std::string, search::Score> &GetMap() const { return map_; }

  private:
    float Steal(const std::string &str);

    typedef boost::unordered_map<std::string, search::Score> Map;

    Map map_;

    search::Score lm_, oov_, word_penalty_;
};

} // namespace search

#endif // SEARCH_WEIGHTS__