summaryrefslogtreecommitdiff
path: root/klm/alone/vocab.cc
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2012-09-12 15:07:44 +0100
committerKenneth Heafield <github@kheafield.com>2012-09-12 15:07:44 +0100
commit173910593bf6bf3dc52902f99a683560d8c73942 (patch)
tree746ea920283178f3bf6b7f86e7b9e6b195821676 /klm/alone/vocab.cc
parent143ba7317dcaee3058d66f9e6558316f88f95212 (diff)
Add the alone stuff, using a wrapper to the edge class.
Diffstat (limited to 'klm/alone/vocab.cc')
-rw-r--r--klm/alone/vocab.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/klm/alone/vocab.cc b/klm/alone/vocab.cc
new file mode 100644
index 00000000..ffe55301
--- /dev/null
+++ b/klm/alone/vocab.cc
@@ -0,0 +1,19 @@
+#include "alone/vocab.hh"
+
+#include "lm/virtual_interface.hh"
+#include "util/string_piece.hh"
+
+namespace alone {
+
+Vocab::Vocab(const lm::base::Vocabulary &backing) : backing_(backing), end_sentence_(FindOrAdd("</s>")) {}
+
+const std::pair<const std::string, lm::WordIndex> &Vocab::FindOrAdd(const StringPiece &str) {
+ Map::const_iterator i(FindStringPiece(map_, str));
+ if (i != map_.end()) return *i;
+ std::pair<std::string, lm::WordIndex> to_ins;
+ to_ins.first.assign(str.data(), str.size());
+ to_ins.second = backing_.Index(str);
+ return *map_.insert(to_ins).first;
+}
+
+} // namespace alone