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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
* libpinyin
* Library to deal with pinyin.
*
* Copyright (C) 2013 Peng Wu <alexepico@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef NGRAM_BDB_H
#define NGRAM_BDB_H
#include <db.h>
namespace pinyin{
class SingleGram;
/**
* Bigram:
*
* The Bi-gram class.
*
*/
class Bigram{
private:
DB * m_db;
void reset();
public:
/**
* Bigram::Bigram:
*
* The constructor of the Bigram.
*
*/
Bigram();
/**
* Bigram::~Bigram:
*
* The destructor of the Bigram.
*
*/
~Bigram();
/**
* Bigram::load_db:
* @dbfile: the Berkeley DB file name.
* @returns: whether the load operation is successful.
*
* Load the Berkeley DB into memory.
*
*/
bool load_db(const char * dbfile);
/**
* Bigram::save_db:
* @dbfile: the Berkeley DB file name.
* @returns: whether the save operation is successful.
*
* Save the in-memory Berkeley DB into disk.
*
*/
bool save_db(const char * dbfile);
/**
* Bigram::attach:
* @dbfile: the Berkeley DB file name.
* @flags: the flags of enum ATTACH_FLAG.
* @returns: whether the attach operation is successful.
*
* Attach this Bigram with the Berkeley DB.
*
*/
bool attach(const char * dbfile, guint32 flags);
/**
* Bigram::load:
* @index: the previous token in the bi-gram.
* @single_gram: the single gram of the previous token.
* @copy: whether copy content to the single gram.
* @returns: whether the load operation is successful.
*
* Load the single gram of the previous token.
*
*/
bool load(/* in */ phrase_token_t index,
/* out */ SingleGram * & single_gram, bool copy=false);
/**
* Bigram::store:
* @index: the previous token in the bi-gram.
* @single_gram: the single gram of the previous token.
* @returns: whether the store operation is successful.
*
* Store the single gram of the previous token.
*
*/
bool store(/* in */ phrase_token_t index,
/* in */ SingleGram * single_gram);
/**
* Bigram::remove:
* @index: the previous token in the bi-gram.
* @returns: whether the remove operation is successful.
*
* Remove the single gram of the previous token.
*
*/
bool remove(/* in */ phrase_token_t index);
/**
* Bigram::get_all_items:
* @items: the GArray to store all previous tokens.
* @returns: whether the get operation is successful.
*
* Get the array of all previous tokens for parameter estimation.
*
*/
bool get_all_items(/* out */ GArray * items);
/**
* Bigram::mask_out:
* @mask: the mask.
* @value: the value.
* @returns: whether the mask out operation is successful.
*
* Mask out the matched items.
*
*/
bool mask_out(phrase_token_t mask, phrase_token_t value);
};
};
#endif
|