summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2015-04-14 11:20:04 +0800
committerPeng Wu <alexepico@gmail.com>2015-04-14 11:20:04 +0800
commite8d9463f45a7214e0eb36cfe09f45cce3b7baeb9 (patch)
tree5ce31a8563adafc6d5823650e04e8ba37c87c49d /src
parentebbe25e0cae57e530a11ae12b965a330ff9496f4 (diff)
downloadlibpinyin-e8d9463f45a7214e0eb36cfe09f45cce3b7baeb9.tar.gz
libpinyin-e8d9463f45a7214e0eb36cfe09f45cce3b7baeb9.tar.xz
libpinyin-e8d9463f45a7214e0eb36cfe09f45cce3b7baeb9.zip
add ngram_kyotodb.h
Diffstat (limited to 'src')
-rw-r--r--src/storage/ngram_bdb.h7
-rw-r--r--src/storage/ngram_kyotodb.h155
2 files changed, 162 insertions, 0 deletions
diff --git a/src/storage/ngram_bdb.h b/src/storage/ngram_bdb.h
index cbfb8f3..f1c15f2 100644
--- a/src/storage/ngram_bdb.h
+++ b/src/storage/ngram_bdb.h
@@ -19,6 +19,9 @@
* 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{
@@ -35,6 +38,8 @@ class Bigram{
private:
DB * m_db;
+ /* Note: sync mask_out code with ngram_kyotodb.cpp. */
+
void reset();
public:
@@ -142,3 +147,5 @@ public:
};
};
+
+#endif
diff --git a/src/storage/ngram_kyotodb.h b/src/storage/ngram_kyotodb.h
new file mode 100644
index 0000000..6c5eea0
--- /dev/null
+++ b/src/storage/ngram_kyotodb.h
@@ -0,0 +1,155 @@
+/*
+ * 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_KYOTODB_H
+#define NGRAM_KYOTODB_H
+
+#include <kchashdb.h>
+#include "memory_chunk.h"
+
+namespace pinyin{
+
+class SingleGram;
+
+/**
+ * Bigram:
+ *
+ * The Bi-gram class.
+ *
+ */
+class Bigram{
+private:
+ kyotocabinet::DB * m_db;
+
+ /* memory chunk for Kyoto Cabinet. */
+ MemoryChunk m_chunk;
+
+ /* Note: sync mask_out code with ngram_bdb.cpp. */
+
+ 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.
+ * @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);
+
+ /**
+ * 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