00001 #ifndef MERT_VOCABULARY_H_ 00002 #define MERT_VOCABULARY_H_ 00003 00004 #include <boost/unordered_map.hpp> 00005 #include <string> 00006 00007 namespace mert { 00008 00015 class Vocabulary { 00016 public: 00017 typedef boost::unordered_map<std::string, int>::iterator iterator; 00018 typedef boost::unordered_map<std::string, int>::const_iterator const_iterator; 00019 00020 Vocabulary() {} 00021 virtual ~Vocabulary() {} 00022 00024 int Encode(const std::string& token); 00025 00029 bool Lookup(const std::string&str , int* v) const; 00030 00031 void clear() { m_vocab.clear(); } 00032 00033 bool empty() const { return m_vocab.empty(); } 00034 00035 std::size_t size() const { return m_vocab.size(); } 00036 00037 iterator find(const std::string& str) { return m_vocab.find(str); } 00038 const_iterator find(const std::string& str) const { return m_vocab.find(str); } 00039 00040 int& operator[](const std::string& str) { return m_vocab[str]; } 00041 00042 iterator begin() { return m_vocab.begin(); } 00043 const_iterator begin() const { return m_vocab.begin(); } 00044 iterator end() { return m_vocab.end(); } 00045 const_iterator end() const { return m_vocab.end(); } 00046 00047 private: 00048 boost::unordered_map<std::string, int> m_vocab; 00049 }; 00050 00051 class VocabularyFactory { 00052 public: 00053 static Vocabulary* GetVocabulary(); 00054 static void SetVocabulary(Vocabulary* vocab); 00055 00056 private: 00057 VocabularyFactory() {} 00058 virtual ~VocabularyFactory() {} 00059 }; 00060 00061 } // namespace mert 00062 00063 #endif // MERT_VOCABULARY_H_