diff options
| author | Peng Wu <alexepico@gmail.com> | 2024-09-29 13:36:15 +0800 |
|---|---|---|
| committer | Peng Wu <alexepico@gmail.com> | 2024-09-29 13:36:15 +0800 |
| commit | bfcf58960acfa5d6aa64f2f67fa05b0ce2b63c8e (patch) | |
| tree | 7bf3f2cadd7a7f616d7510e1967f74c789a8a071 /src/storage | |
| parent | 1601e32083f5e7aec1e883a95519514b8ce8583b (diff) | |
| download | libpinyin-bfcf58960acfa5d6aa64f2f67fa05b0ce2b63c8e.tar.gz libpinyin-bfcf58960acfa5d6aa64f2f67fa05b0ce2b63c8e.tar.xz libpinyin-bfcf58960acfa5d6aa64f2f67fa05b0ce2b63c8e.zip | |
Update class PunctTable
Diffstat (limited to 'src/storage')
| -rw-r--r-- | src/storage/punct_table.cpp | 58 | ||||
| -rw-r--r-- | src/storage/punct_table_bdb.cpp | 32 | ||||
| -rw-r--r-- | src/storage/punct_table_bdb.h | 2 | ||||
| -rw-r--r-- | src/storage/punct_table_kyotodb.cpp | 32 | ||||
| -rw-r--r-- | src/storage/punct_table_kyotodb.h | 2 |
5 files changed, 62 insertions, 64 deletions
diff --git a/src/storage/punct_table.cpp b/src/storage/punct_table.cpp index 461d4bc..249f6c3 100644 --- a/src/storage/punct_table.cpp +++ b/src/storage/punct_table.cpp @@ -143,3 +143,61 @@ bool PunctTableEntry::remove_punctuation(const gchar * punct) { return false; } + +bool PunctTable::get_all_punctuations(/* in */ phrase_token_t index, + /* out */ gchar ** & puncts) { + assert(NULL == puncts); + + if (!load_entry(index)) + return false; + + return m_entry->get_all_punctuations(puncts); +} + +bool PunctTable::append_punctuation(/* in */ phrase_token_t index, + /* in */ const gchar * punct) { + if (!load_entry(index)) + return false; + if (!m_entry->append_punctuation(punct)) + return false; + if (!store_entry(index)) + return false; + return true; +} + +bool PunctTable::remove_punctuation(/* in */ phrase_token_t index, + /* in */ const gchar * punct) { + if (!load_entry(index)) + return false; + if (!m_entry->remove_punctuation(punct)) + return false; + if (!store_entry(index)) + return false; + return true; +} + +bool PunctTable::load_text(FILE * infile) { + phrase_token_t token; + char phrase[256]; + char punct[256]; + size_t freq; + + while (!feof(infile)) { +#ifdef __APPLE__ + int num = fscanf(infile, "%u %255[^ \t] %255[^ \t] %ld", + &token, phrase, punct, &freq); +#else + int num = fscanf(infile, "%u %255s %255s %ld", + &token, phrase, punct, &freq); +#endif + + if (4 != num) + continue; + + if (feof(infile)) + break; + + append_punctuation(token, punct); + } + return true; +} diff --git a/src/storage/punct_table_bdb.cpp b/src/storage/punct_table_bdb.cpp index b4e52d9..bdc7b84 100644 --- a/src/storage/punct_table_bdb.cpp +++ b/src/storage/punct_table_bdb.cpp @@ -179,38 +179,6 @@ bool PunctTable::store_entry(phrase_token_t index) { return true; } -bool PunctTable::get_all_punctuations(/* in */ phrase_token_t index, - /* out */ gchar ** & puncts) { - assert(NULL == puncts); - - if (!load_entry(index)) - return false; - - return m_entry->get_all_punctuations(puncts); -} - -bool PunctTable::append_punctuation(/* in */ phrase_token_t index, - /* in */ const gchar * punct) { - if (!load_entry(index)) - return false; - if (!m_entry->append_punctuation(punct)) - return false; - if (!store_entry(index)) - return false; - return true; -} - -bool PunctTable::remove_punctuation(/* in */ phrase_token_t index, - /* in */ const gchar * punct) { - if (!load_entry(index)) - return false; - if (!m_entry->remove_punctuation(punct)) - return false; - if (!store_entry(index)) - return false; - return true; -} - bool PunctTable::remove_all_punctuations(/* in */ phrase_token_t index) { if (NULL == m_db) return false; diff --git a/src/storage/punct_table_bdb.h b/src/storage/punct_table_bdb.h index 6f5eb8a..e4372d7 100644 --- a/src/storage/punct_table_bdb.h +++ b/src/storage/punct_table_bdb.h @@ -62,6 +62,8 @@ public: bool remove_all_punctuations(/* in */ phrase_token_t index); bool get_all_items(/* out */ GArray * items); + + bool load_text(FILE * infile); }; }; diff --git a/src/storage/punct_table_kyotodb.cpp b/src/storage/punct_table_kyotodb.cpp index 698af1b..cc0fd5f 100644 --- a/src/storage/punct_table_kyotodb.cpp +++ b/src/storage/punct_table_kyotodb.cpp @@ -152,38 +152,6 @@ bool PunctTable::store_entry(phrase_token_t index) { return m_db->set(kbuf, sizeof(phrase_token_t), vbuf, vsiz); } -bool PunctTable::get_all_punctuations(/* in */ phrase_token_t index, - /* out */ gchar ** & puncts) { - assert(NULL == puncts); - - if (!load_entry(index)) - return false; - - return m_entry->get_all_punctuations(puncts); -} - -bool PunctTable::append_punctuation(/* in */ phrase_token_t index, - /* in */ const gchar * punct) { - if (!load_entry(index)) - return false; - if (!m_entry->append_punctuation(punct)) - return false; - if (!store_entry(index)) - return false; - return true; -} - -bool PunctTable::remove_punctuation(/* in */ phrase_token_t index, - /* in */ const gchar * punct) { - if (!load_entry(index)) - return false; - if (!m_entry->remove_punctuation(punct)) - return false; - if (!store_entry(index)) - return false; - return true; -} - bool PunctTable::remove_all_punctuations(/* in */ phrase_token_t index) { if (NULL == m_db) return false; diff --git a/src/storage/punct_table_kyotodb.h b/src/storage/punct_table_kyotodb.h index c030bff..c2afcf5 100644 --- a/src/storage/punct_table_kyotodb.h +++ b/src/storage/punct_table_kyotodb.h @@ -62,6 +62,8 @@ public: bool remove_all_punctuations(/* in */ phrase_token_t index); bool get_all_items(/* out */ GArray * items); + + bool load_text(FILE * infile); }; }; |
