summaryrefslogtreecommitdiff
path: root/klm/search/word.hh
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2012-09-11 14:30:16 +0100
committerKenneth Heafield <github@kheafield.com>2012-09-11 14:31:42 +0100
commit58d7f847cd5b3c56682e834a2d9b897c6943fafc (patch)
tree04b370b0d92240a4a60dbf921548c927e0a5f00d /klm/search/word.hh
parent7aa4baf365a80380bebacfc4d4a1ef1b9d757590 (diff)
Add search library to cdec (not used yet)
Diffstat (limited to 'klm/search/word.hh')
-rw-r--r--klm/search/word.hh47
1 files changed, 47 insertions, 0 deletions
diff --git a/klm/search/word.hh b/klm/search/word.hh
new file mode 100644
index 00000000..e7a15be9
--- /dev/null
+++ b/klm/search/word.hh
@@ -0,0 +1,47 @@
+#ifndef SEARCH_WORD__
+#define SEARCH_WORD__
+
+#include "lm/word_index.hh"
+
+#include <boost/functional/hash.hpp>
+
+#include <string>
+#include <utility>
+
+namespace search {
+
+class Word {
+ public:
+ // Construct a non-terminal.
+ Word() : entry_(NULL) {}
+
+ explicit Word(const std::pair<const std::string, lm::WordIndex> &entry) {
+ entry_ = &entry;
+ }
+
+ // Returns true for two non-terminals even if their labels are different (since we don't care about labels).
+ bool operator==(const Word &other) const {
+ return entry_ == other.entry_;
+ }
+
+ bool Terminal() const { return entry_ != NULL; }
+
+ const std::string &String() const { return entry_->first; }
+
+ lm::WordIndex Index() const { return entry_->second; }
+
+ protected:
+ friend size_t hash_value(const Word &word);
+
+ const std::pair<const std::string, lm::WordIndex> *Entry() const { return entry_; }
+
+ private:
+ const std::pair<const std::string, lm::WordIndex> *entry_;
+};
+
+inline size_t hash_value(const Word &word) {
+ return boost::hash_value(word.Entry());
+}
+
+} // namespace search
+#endif // SEARCH_WORD__