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

Vocabulary.cpp « mert - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ccabe2d8419bab5a1918a12280482488f53e3491 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "Vocabulary.h"
#include "Singleton.h"

namespace mert {
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();
  } else {
    return g_vocab;
  }
}

void VocabularyFactory::SetVocabulary(Vocabulary* vocab) {
  g_vocab = vocab;
}

} // namespace mert