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
path: root/mert
diff options
context:
space:
mode:
authorColin Cherry <Colin.Cherry@nrc-cnrc.gc.ca>2012-06-27 01:07:27 +0400
committerColin Cherry <Colin.Cherry@nrc-cnrc.gc.ca>2012-06-27 01:07:27 +0400
commit65df3865814d8ac60c6dc32c2cd3cec709bf81c1 (patch)
tree005ae3915f2afd1cecb114860edb60ee9e0e3cd8 /mert
parent58c3280c2c0388ee3a02064f3497b3201d0f7554 (diff)
parent1013634d3303814ffc1c457468210227befb95ab (diff)
Merge branch 'master' of https://github.com/moses-smt/mosesdecoder
Diffstat (limited to 'mert')
-rw-r--r--mert/Vocabulary.cpp22
-rw-r--r--mert/Vocabulary.h21
2 files changed, 25 insertions, 18 deletions
diff --git a/mert/Vocabulary.cpp b/mert/Vocabulary.cpp
index 40b04bf99..ccabe2d84 100644
--- a/mert/Vocabulary.cpp
+++ b/mert/Vocabulary.cpp
@@ -6,6 +6,28 @@ namespace {
Vocabulary* g_vocab = NULL;
} // namespace
+int Vocabulary::Encode(const std::string& token) {
+ iterator it = m_vocab.find(token);
+ int encoded_token;
+ if (it == m_vocab.end()) {
+ // Add an new entry to the vocaburary.
+ encoded_token = static_cast<int>(m_vocab.size());
+
+ m_vocab[token] = encoded_token;
+ } else {
+ encoded_token = it->second;
+ }
+ return encoded_token;
+}
+
+bool Vocabulary::Lookup(const std::string&str , int* v) const {
+
+ const_iterator it = m_vocab.find(str);
+ if (it == m_vocab.end()) return false;
+ *v = it->second;
+ return true;
+}
+
Vocabulary* VocabularyFactory::GetVocabulary() {
if (g_vocab == NULL) {
return Singleton<Vocabulary>::GetInstance();
diff --git a/mert/Vocabulary.h b/mert/Vocabulary.h
index a8630e951..0d9291260 100644
--- a/mert/Vocabulary.h
+++ b/mert/Vocabulary.h
@@ -21,28 +21,12 @@ class Vocabulary {
virtual ~Vocabulary() {}
/** Returns the assiged id for given "token". */
- int Encode(const std::string& token) {
- iterator it = m_vocab.find(token);
- int encoded_token;
- if (it == m_vocab.end()) {
- // Add an new entry to the vocaburary.
- encoded_token = static_cast<int>(m_vocab.size());
- m_vocab[token] = encoded_token;
- } else {
- encoded_token = it->second;
- }
- return encoded_token;
- }
+ int Encode(const std::string& token);
/**
* Return true iff the specified "str" is found in the container.
*/
- bool Lookup(const std::string&str , int* v) const {
- const_iterator it = m_vocab.find(str);
- if (it == m_vocab.end()) return false;
- *v = it->second;
- return true;
- }
+ bool Lookup(const std::string&str , int* v) const;
void clear() { m_vocab.clear(); }
@@ -62,6 +46,7 @@ class Vocabulary {
private:
std::map<std::string, int> m_vocab;
+
};
class VocabularyFactory {