summaryrefslogtreecommitdiffstats
path: root/src/storage/ngram.h
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-04-18 16:16:59 +0800
committerPeng Wu <alexepico@gmail.com>2011-04-18 16:16:59 +0800
commit647b365bbf25bc1e8db10aa26427fddbbbaf4626 (patch)
tree1607db6f2cc152a00559599706d5b8865f775ba1 /src/storage/ngram.h
parent1ab6f0e8292074a8feac390db820305968147b3b (diff)
downloadlibpinyin-647b365bbf25bc1e8db10aa26427fddbbbaf4626.tar.gz
libpinyin-647b365bbf25bc1e8db10aa26427fddbbbaf4626.tar.xz
libpinyin-647b365bbf25bc1e8db10aa26427fddbbbaf4626.zip
refine bi-gram
Diffstat (limited to 'src/storage/ngram.h')
-rw-r--r--src/storage/ngram.h38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/storage/ngram.h b/src/storage/ngram.h
index 290a0bc..93e6ad7 100644
--- a/src/storage/ngram.h
+++ b/src/storage/ngram.h
@@ -26,6 +26,12 @@
namespace pinyin{
+enum {
+ ATTACH_READONLY = 1,
+ ATTACH_READWRITE = 0x1 << 1,
+ ATTACH_CREATE = 0x1 << 2,
+};
+
class Bigram;
/* Note:
@@ -93,44 +99,40 @@ public:
class Bigram{
private:
- DB * m_system;
- DB * m_user;
+ DB * m_db;
void reset(){
- if ( m_system ){
- m_system->close(m_system, 0);
- m_system = NULL;
- }
- if ( m_user ){
- m_user->close(m_user, 0);
- m_user = NULL;
+ if ( m_db ){
+ m_db->close(m_db, 0);
+ m_db = NULL;
}
}
public:
Bigram(){
- m_system = NULL; m_user = NULL;
+ m_db = NULL;
}
~Bigram(){
reset();
}
- /* attach system and user bi-gram */
- /* when with training systemdb is NULL, only user_gram */
- bool attach(const char * systemfile, const char * userfile);
+ /* load/save berkeley db in memory. */
+ bool load_db(const char * dbfile);
+ bool save_db(const char * dbfile);
+
+ /* attach bi-gram */
+ bool attach(const char * dbfile, guint32 flags);
/* load/store one single gram */
bool load(/* in */ phrase_token_t index,
- /* out */ SingleGram * & system_gram,
- /* out */ SingleGram * & user_gram);
+ /* out */ SingleGram * & single_gram);
bool store(/* in */ phrase_token_t index,
- /* in */ SingleGram * user_gram);
+ /* in */ SingleGram * single_gram);
/* array of phrase_token_t items, for parameter estimation. */
- bool get_all_items(/* out */ GArray * system,
- /* out */ GArray * user);
+ bool get_all_items(/* out */ GArray * items);
};
};