summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-09-17 13:31:26 +0800
committerPeng Wu <alexepico@gmail.com>2013-09-17 13:31:26 +0800
commit49ee09185e26a549134833928da911a3518555a9 (patch)
tree0a19853f4ca7d6a4113c2a1657f27900d3f4e886
parent6d5f16ffc0aa2ee3a8a3cd7adf1ae430b4f3384a (diff)
downloadlibzhuyin-49ee09185e26a549134833928da911a3518555a9.tar.gz
libzhuyin-49ee09185e26a549134833928da911a3518555a9.tar.xz
libzhuyin-49ee09185e26a549134833928da911a3518555a9.zip
drop ChewingSimpleParser2
-rw-r--r--src/pinyin.cpp4
-rw-r--r--src/storage/pinyin_parser2.cpp82
-rw-r--r--src/storage/pinyin_parser2.h48
3 files changed, 10 insertions, 124 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 4a811e7..7cb57a7 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -37,7 +37,7 @@ struct _pinyin_context_t{
pinyin_option_t m_options;
FullPinyinParser2 * m_full_pinyin_parser;
- ChewingSimpleParser2 * m_chewing_parser;
+ ChewingDiscreteParser2 * m_chewing_parser;
FacadeChewingTable * m_pinyin_table;
FacadePhraseTable2 * m_phrase_table;
@@ -178,7 +178,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
check_format(context);
context->m_full_pinyin_parser = new FullPinyinParser2;
- context->m_chewing_parser = new ChewingSimpleParser2;
+ context->m_chewing_parser = new ChewingDiscreteParser2;
/* load chewing table. */
context->m_pinyin_table = new FacadeChewingTable;
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index 9a73d3e..85875f2 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -470,7 +470,7 @@ static bool search_chewing_tones(const chewing_tone_item_t * tone_table,
return false;
}
-
+#if 0
bool ChewingSimpleParser2::parse_one_key(pinyin_option_t options,
ChewingKey & key,
const char * str, int len) const {
@@ -519,85 +519,7 @@ bool ChewingSimpleParser2::parse_one_key(pinyin_option_t options,
return false;
}
-
-/* only characters in chewing keyboard scheme are accepted here. */
-int ChewingSimpleParser2::parse(pinyin_option_t options,
- ChewingKeyVector & keys,
- ChewingKeyRestVector & key_rests,
- const char *str, int len) const {
- g_array_set_size(keys, 0);
- g_array_set_size(key_rests, 0);
-
- int maximum_len = 0; int i;
- /* probe the longest possible chewing string. */
- for (i = 0; i < len; ++i) {
- if (!in_chewing_scheme(options, str[i], NULL))
- break;
- }
- maximum_len = i;
-
- /* maximum forward match for chewing. */
- int parsed_len = 0;
- while (parsed_len < maximum_len) {
- const char * cur_str = str + parsed_len;
- i = std_lite::min(maximum_len - parsed_len,
- (int)max_chewing_length);
-
- ChewingKey key; ChewingKeyRest key_rest;
- for (; i > 0; --i) {
- bool success = parse_one_key(options, key, cur_str, i);
- if (success)
- break;
- }
-
- if (0 == i) /* no more possible chewings. */
- break;
-
- key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i;
- parsed_len += i;
-
- /* save the pinyin. */
- g_array_append_val(keys, key);
- g_array_append_val(key_rests, key_rest);
- }
-
- return parsed_len;
-}
-
-
-bool ChewingSimpleParser2::set_scheme(ChewingScheme scheme) {
- switch(scheme) {
- default:
- assert(FALSE);
- }
-
- return false;
-}
-
-
-bool ChewingSimpleParser2::in_chewing_scheme(pinyin_option_t options,
- const char key,
- const char ** symbol) const {
- const gchar * chewing = NULL;
- unsigned char tone = CHEWING_ZERO_TONE;
-
- if (search_chewing_symbols(m_symbol_table, key, &chewing)) {
- if (symbol)
- *symbol = chewing;
- return true;
- }
-
- if (!(options & USE_TONE))
- return false;
-
- if (search_chewing_tones(m_tone_table, key, &tone)) {
- if (symbol)
- *symbol = chewing_tone_table[tone];
- return true;
- }
-
- return false;
-}
+#endif
bool ChewingDiscreteParser2::parse_one_key(pinyin_option_t options,
ChewingKey & key,
diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h
index 16c078c..a58c7b6 100644
--- a/src/storage/pinyin_parser2.h
+++ b/src/storage/pinyin_parser2.h
@@ -145,46 +145,6 @@ public:
bool set_scheme(PinyinScheme scheme);
};
-/**
- * ChewingSimpleParser2:
- *
- * Parse the chewing string into an array of struct ChewingKeys.
- *
- * Several keyboard scheme are supported:
- * * Chewing_STANDARD Standard ZhuYin keyboard, which maps 1 to Bo(ㄅ), q to Po(ㄆ) etc.
- * * Chewing_IBM IBM ZhuYin keyboard, which maps 1 to Bo(ㄅ), 2 to Po(ㄆ) etc.
- * * Chewing_GINYIEH Gin-Yieh ZhuYin keyboard.
- * * Chewing_ETEN Eten (倚天) ZhuYin keyboard.
- *
- */
-
-/* Note: maybe yunmus shuffle will be supported later.
- * currently this feature is postponed.
- */
-class ChewingSimpleParser2 : public PhoneticParser2
-{
- /* Note: some internal pointers to chewing scheme table. */
-protected:
- const chewing_symbol_item_t * m_symbol_table;
- const chewing_tone_item_t * m_tone_table;
-
-public:
- ChewingSimpleParser2() {
- m_symbol_table = NULL; m_tone_table = NULL;
- set_scheme(CHEWING_DEFAULT);
- }
-
- virtual ~ChewingSimpleParser2() {}
-
- virtual bool parse_one_key(pinyin_option_t options, ChewingKey & key, const char *str, int len) const;
-
- virtual int parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
-
-public:
- bool set_scheme(ChewingScheme scheme);
- bool in_chewing_scheme(pinyin_option_t options, const char key, const char ** symbol) const;
-};
-
/**
* ChewingDiscreteParser2:
@@ -193,8 +153,12 @@ public:
*
* Initially will support HSU, HSU Dvorak and ETEN26.
*
- * Plan to replace ChewingSimpleParser2 in future,
- * as this class is more powerful.
+ * Several keyboard scheme are supported:
+ * * Chewing_STANDARD Standard ZhuYin keyboard.
+ * * Chewing_IBM IBM ZhuYin keyboard.
+ * * Chewing_GINYIEH Gin-Yieh ZhuYin keyboard.
+ * * Chewing_ETEN Eten (倚天) ZhuYin keyboard.
+ * * ...
*/
class ChewingDiscreteParser2 : public PhoneticParser2