Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'moses/TranslationModel/ProbingPT/StoreVocab.h')
-rw-r--r--moses/TranslationModel/ProbingPT/StoreVocab.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/moses/TranslationModel/ProbingPT/StoreVocab.h b/moses/TranslationModel/ProbingPT/StoreVocab.h
new file mode 100644
index 000000000..05d279f4c
--- /dev/null
+++ b/moses/TranslationModel/ProbingPT/StoreVocab.h
@@ -0,0 +1,64 @@
+/*
+ * StoreVocab.h
+ *
+ * Created on: 15 Jun 2016
+ * Author: hieu
+ */
+#pragma once
+#include <string>
+#include <boost/unordered_map.hpp>
+#include "moses/OutputFileStream.h"
+#include "moses/Util.h"
+
+namespace Moses
+{
+
+template<typename VOCABID>
+class StoreVocab
+{
+protected:
+ std::string m_path;
+
+ typedef boost::unordered_map<std::string, VOCABID> Coll;
+ Coll m_vocab;
+
+public:
+ StoreVocab(const std::string &path)
+ :m_path(path)
+ {}
+
+ virtual ~StoreVocab() {}
+
+ VOCABID GetVocabId(const std::string &word)
+ {
+ typename Coll::iterator iter = m_vocab.find(word);
+ if (iter == m_vocab.end()) {
+ VOCABID ind = m_vocab.size() + 1;
+ m_vocab[word] = ind;
+ return ind;
+ }
+ else {
+ return iter->second;
+ }
+ }
+
+ void Insert(VOCABID id, const std::string &word)
+ {
+ m_vocab[word] = id;
+ }
+
+ void Save()
+ {
+ OutputFileStream strme(m_path);
+
+ typename Coll::const_iterator iter;
+ for (iter = m_vocab.begin(); iter != m_vocab.end(); ++iter) {
+ strme << iter->first << "\t" << iter->second << std::endl;
+ }
+
+ strme.Close();
+ }
+};
+
+} /* namespace Moses2 */
+