ZGen  0.2.0
a linearization system for natural language.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
word_alphabet.h
Go to the documentation of this file.
1 #ifndef __ZGEN_WORD_ALPHABET_H__
2 #define __ZGEN_WORD_ALPHABET_H__
3 
4 #include <iostream>
5 #include <boost/unordered_map.hpp>
6 #include <boost/serialization/string.hpp>
7 #include <boost/serialization/vector.hpp>
8 #include <boost/serialization/version.hpp>
9 #include <boost/serialization/split_member.hpp>
10 #include <boost/serialization/singleton.hpp>
11 #include "alphabet.h"
12 
13 
14 namespace ZGen {
15 
16 namespace Engine {
17 
19 public:
20  WordAlphabet();
21 
22  ~WordAlphabet();
23 
31  int insert(const char* name);
32 
40  const char* decode(int id) const;
41 
47  int encode(const char* name) const;
48 
53  bool save(std::ostream& ofs) const;
54 
60  bool load(std::istream& ifs);
61 
62  enum SPECIAL_WORD {
64  };
65 
66 private:
67  typedef boost::unordered_map<std::string, int> map_t;
68 
70 
71  std::vector<std::string> id2name;
72 
73  map_t name2id;
74 
75  int global_id;
76 
77  template<class Archive>
78  void serialize(Archive & ar, const unsigned int version) {
79  ar & global_id;
80  ar & name2id;
81  ar & id2name;
82  }
83 };
84 
85 
86 } // end for namespace Engine
87 
88 } // end for namespace ZGen
89 
90 #endif // end for __ZGEN_WORD_ALPHABET_H__
bool save(std::ostream &ofs) const
Definition: word_alphabet.cc:59
Definition: word_alphabet.h:63
Definition: word_alphabet.h:63
int insert(const char *name)
Definition: word_alphabet.cc:25
bool load(std::istream &ifs)
Definition: word_alphabet.cc:72
Definition: alphabet.h:30
const char * decode(int id) const
Definition: word_alphabet.cc:40
friend class boost::serialization::access
Definition: word_alphabet.h:69
SPECIAL_WORD
Definition: word_alphabet.h:62
~WordAlphabet()
Definition: word_alphabet.cc:21
WordAlphabet()
Definition: word_alphabet.cc:11
int encode(const char *name) const
Definition: word_alphabet.cc:49
void serialize(Archive &ar, boost::unordered_map< Key, Type, Hash, Compare, Allocator > &t, const unsigned int file_version)
Definition: unordered_map.h:64
Definition: word_alphabet.h:18
Definition: word_alphabet.h:63