summaryrefslogtreecommitdiff
path: root/klm
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2012-09-13 04:04:17 -0700
committerKenneth Heafield <github@kheafield.com>2012-09-13 04:04:17 -0700
commit8d0baa1dfb5c18f5be45b4d12b3f925dc04afc48 (patch)
treeaf96b81bfa50321d36a02bc036eabfeb29c32538 /klm
parenta548c46f3d636093d26f44d5b7642c98def6f351 (diff)
parent816f33174b2c2938a3df9c75b2834da6f5184a3e (diff)
Merge branch 'master' of github.com:kpu/cdec
Diffstat (limited to 'klm')
-rw-r--r--klm/search/config.hh6
-rw-r--r--klm/search/weights.cc2
-rw-r--r--klm/search/weights.hh17
3 files changed, 15 insertions, 10 deletions
diff --git a/klm/search/config.hh b/klm/search/config.hh
index e21e4b7c..ef8e2354 100644
--- a/klm/search/config.hh
+++ b/klm/search/config.hh
@@ -8,15 +8,15 @@ namespace search {
class Config {
public:
- Config(StringPiece weight_str, unsigned int pop_limit) :
- weights_(weight_str), pop_limit_(pop_limit) {}
+ Config(const Weights &weights, unsigned int pop_limit) :
+ weights_(weights), pop_limit_(pop_limit) {}
const Weights &GetWeights() const { return weights_; }
unsigned int PopLimit() const { return pop_limit_; }
private:
- search::Weights weights_;
+ Weights weights_;
unsigned int pop_limit_;
};
diff --git a/klm/search/weights.cc b/klm/search/weights.cc
index 82ff3f12..d65471ad 100644
--- a/klm/search/weights.cc
+++ b/klm/search/weights.cc
@@ -49,6 +49,8 @@ Weights::Weights(StringPiece text) {
word_penalty_ = Steal("WordPenalty");
}
+Weights::Weights(Score lm, Score oov, Score word_penalty) : lm_(lm), oov_(oov), word_penalty_(word_penalty) {}
+
search::Score Weights::DotNoLM(StringPiece text) const {
DotProduct dot;
Parse<const Map, DotProduct>(text, map_, dot);
diff --git a/klm/search/weights.hh b/klm/search/weights.hh
index 4a4388c7..df1c419f 100644
--- a/klm/search/weights.hh
+++ b/klm/search/weights.hh
@@ -23,25 +23,28 @@ class Weights {
// Parses weights, sets lm_weight_, removes it from map_.
explicit Weights(StringPiece text);
- search::Score DotNoLM(StringPiece text) const;
+ // Just the three scores we care about adding.
+ Weights(Score lm, Score oov, Score word_penalty);
- search::Score LM() const { return lm_; }
+ Score DotNoLM(StringPiece text) const;
- search::Score OOV() const { return oov_; }
+ Score LM() const { return lm_; }
- search::Score WordPenalty() const { return word_penalty_; }
+ Score OOV() const { return oov_; }
+
+ Score WordPenalty() const { return word_penalty_; }
// Mostly for testing.
- const boost::unordered_map<std::string, search::Score> &GetMap() const { return map_; }
+ const boost::unordered_map<std::string, Score> &GetMap() const { return map_; }
private:
float Steal(const std::string &str);
- typedef boost::unordered_map<std::string, search::Score> Map;
+ typedef boost::unordered_map<std::string, Score> Map;
Map map_;
- search::Score lm_, oov_, word_penalty_;
+ Score lm_, oov_, word_penalty_;
};
} // namespace search