3 * Library to deal with pinyin.
5 * Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "pinyin_parser2.h"
29 #include "pinyin_phrase2.h"
30 #include "pinyin_custom2.h"
31 #include "chewing_key.h"
32 #include "pinyin_parser_table.h"
33 #include "double_pinyin_table.h"
34 #include "chewing_table.h"
37 using namespace pinyin;
39 static bool check_pinyin_options(pinyin_option_t options, const pinyin_index_item_t * item) {
40 guint32 flags = item->m_flags;
41 assert (flags & IS_PINYIN);
43 /* handle incomplete pinyin. */
44 if (flags & PINYIN_INCOMPLETE) {
45 if (!(options & PINYIN_INCOMPLETE))
49 /* handle correct pinyin, currently only one flag per item. */
50 flags &= PINYIN_CORRECT_ALL;
51 options &= PINYIN_CORRECT_ALL;
54 if ((flags & options) != flags)
61 static bool check_chewing_options(pinyin_option_t options, const chewing_index_item_t * item) {
62 guint32 flags = item->m_flags;
63 assert (flags & IS_CHEWING);
65 /* handle incomplete chewing. */
66 if (flags & CHEWING_INCOMPLETE) {
67 if (!(options & CHEWING_INCOMPLETE))
75 gint ChewingKey::get_table_index() {
76 assert(m_initial < CHEWING_NUMBER_OF_INITIALS);
77 assert(m_middle < CHEWING_NUMBER_OF_MIDDLES);
78 assert(m_final < CHEWING_NUMBER_OF_FINALS);
80 gint index = chewing_key_table[(m_initial * CHEWING_NUMBER_OF_MIDDLES + m_middle) * CHEWING_NUMBER_OF_FINALS + m_final];
81 return index == -1 ? 0 : index;
84 gchar * ChewingKey::get_pinyin_string() {
85 assert(m_tone < CHEWING_NUMBER_OF_TONES);
86 gint index = get_table_index();
87 assert(index < G_N_ELEMENTS(content_table));
88 const content_table_item_t & item = content_table[index];
90 if (CHEWING_ZERO_TONE == m_tone) {
91 return g_strdup(item.m_pinyin_str);
93 return g_strdup_printf("%s%d", item.m_pinyin_str, m_tone);
97 gchar * ChewingKey::get_chewing_string() {
98 assert(m_tone < CHEWING_NUMBER_OF_TONES);
99 gint index = get_table_index();
100 assert(index < G_N_ELEMENTS(content_table));
101 const content_table_item_t & item = content_table[index];
103 if (CHEWING_ZERO_TONE == m_tone) {
104 return g_strdup(item.m_chewing_str);
106 return g_strdup_printf("%s%s", item.m_chewing_str,
107 chewing_tone_table[m_tone]);
114 /* internal information for pinyin parsers. */
115 struct parse_value_t{
117 ChewingKeyRest m_key_rest;
131 const guint16 max_full_pinyin_length = 7; /* include tone. */
133 const guint16 max_double_pinyin_length = 3; /* include tone. */
135 const guint16 max_chewing_length = 4; /* include tone. */
137 static bool compare_pinyin_less_than(const pinyin_index_item_t & lhs,
138 const pinyin_index_item_t & rhs){
139 return 0 > strcmp(lhs.m_pinyin_input, rhs.m_pinyin_input);
142 static inline bool search_pinyin_index(pinyin_option_t options,
145 pinyin_index_item_t item;
146 memset(&item, 0, sizeof(item));
147 item.m_pinyin_input = pinyin;
149 std_lite::pair<const pinyin_index_item_t *,
150 const pinyin_index_item_t *> range;
151 range = std_lite::equal_range
152 (pinyin_index, pinyin_index + G_N_ELEMENTS(pinyin_index),
153 item, compare_pinyin_less_than);
155 guint16 range_len = range.second - range.first;
156 assert(range_len <= 1);
157 if (range_len == 1) {
158 const pinyin_index_item_t * index = range.first;
160 if (!check_pinyin_options(options, index))
163 key = content_table[index->m_table_index].m_chewing_key;
164 assert(key.get_table_index() == index->m_table_index);
171 static bool compare_chewing_less_than(const chewing_index_item_t & lhs,
172 const chewing_index_item_t & rhs){
173 return 0 > strcmp(lhs.m_chewing_input, rhs.m_chewing_input);
176 static inline bool search_chewing_index(pinyin_option_t options,
177 const char * chewing,
179 chewing_index_item_t item;
180 memset(&item, 0, sizeof(item));
181 item.m_chewing_input = chewing;
183 std_lite::pair<const chewing_index_item_t *,
184 const chewing_index_item_t *> range;
185 range = std_lite::equal_range
186 (chewing_index, chewing_index + G_N_ELEMENTS(chewing_index),
187 item, compare_chewing_less_than);
189 guint16 range_len = range.second - range.first;
190 assert (range_len <= 1);
192 if (range_len == 1) {
193 const chewing_index_item_t * index = range.first;
195 if (!check_chewing_options(options, index))
198 key = content_table[index->m_table_index].m_chewing_key;
199 assert(key.get_table_index() == index->m_table_index);
206 /* Full Pinyin Parser */
207 FullPinyinParser2::FullPinyinParser2 (){
208 m_parse_steps = g_array_new(TRUE, FALSE, sizeof(parse_value_t));
212 bool FullPinyinParser2::parse_one_key (pinyin_option_t options,
214 const char * pinyin, int len) const {
215 /* "'" are not accepted in parse_one_key. */
216 gchar * input = g_strndup(pinyin, len);
217 assert(NULL == strchr(input, '\''));
219 guint16 tone = CHEWING_ZERO_TONE; guint16 tone_pos = 0;
220 guint16 parsed_len = len;
223 if (options & USE_TONE) {
224 /* find the tone in the last character. */
225 char chr = input[parsed_len - 1];
226 if ( '0' < chr && chr <= '5' ) {
229 tone_pos = parsed_len;
233 /* parse pinyin core staff here. */
235 /* Note: optimize here? */
236 input[parsed_len] = '\0';
237 if (!search_pinyin_index(options, input, key)) {
242 if (options & USE_TONE) {
243 /* post processing tone. */
244 if ( parsed_len == tone_pos ) {
245 if (tone != CHEWING_ZERO_TONE) {
253 return parsed_len == len;
257 int FullPinyinParser2::parse (pinyin_option_t options, ChewingKeyVector & keys,
258 ChewingKeyRestVector & key_rests,
259 const char *str, int len) const {
262 g_array_set_size(keys, 0);
263 g_array_set_size(key_rests, 0);
265 /* init m_parse_steps, and prepare dynamic programming. */
266 int step_len = len + 1;
267 g_array_set_size(m_parse_steps, 0);
269 for (i = 0; i < step_len; ++i) {
270 g_array_append_val(m_parse_steps, value);
274 gchar * input = g_strndup(str, len);
275 parse_value_t * curstep = NULL, * nextstep = NULL;
277 for (i = 0; i < len; ++i) {
278 if (input[i] == '\'') {
279 curstep = &g_array_index(m_parse_steps, parse_value_t, i);
280 nextstep = &g_array_index(m_parse_steps, parse_value_t, i + 1);
282 /* propagate current step into next step. */
283 nextstep->m_key = ChewingKey();
284 nextstep->m_key_rest = ChewingKeyRest();
285 nextstep->m_num_keys = curstep->m_num_keys;
286 nextstep->m_parsed_len = curstep->m_parsed_len + 1;
287 nextstep->m_last_step = i;
292 /* forward to next "'" */
293 if ( 0 == next_sep ) {
295 for (k = i; k < len; ++k) {
296 if (input[k] == '\'')
302 /* dynamic programming here. */
303 /* for (size_t m = i; m < next_sep; ++m) */
306 curstep = &g_array_index(m_parse_steps, parse_value_t, m);
307 size_t try_len = std_lite::min
308 (m + max_full_pinyin_length, next_sep);
309 for (size_t n = m + 1; n < try_len + 1; ++n) {
310 nextstep = &g_array_index(m_parse_steps, parse_value_t, n);
313 const char * onepinyin = input + m;
314 gint16 onepinyinlen = n - m;
315 value = parse_value_t();
317 ChewingKey key; ChewingKeyRest rest;
318 bool parsed = parse_one_key
319 (options, key, onepinyin, onepinyinlen);
320 rest.m_raw_begin = m; rest.m_raw_end = n;
324 //printf("onepinyin:%s len:%d\n", onepinyin, onepinyinlen);
326 value.m_key = key; value.m_key_rest = rest;
327 value.m_num_keys = curstep->m_num_keys + 1;
328 value.m_parsed_len = curstep->m_parsed_len + onepinyinlen;
329 value.m_last_step = m;
332 /* no previous result */
333 if (-1 == nextstep->m_last_step)
335 /* prefer the longest pinyin */
336 if (value.m_parsed_len > nextstep->m_parsed_len)
338 /* prefer the shortest keys with the same pinyin length */
339 if (value.m_parsed_len == nextstep->m_parsed_len &&
340 value.m_num_keys < nextstep->m_num_keys)
343 /* handle with the same pinyin length and the number of keys */
344 if (value.m_parsed_len == nextstep->m_parsed_len &&
345 value.m_num_keys == nextstep->m_num_keys) {
348 /* prefer the complete pinyin with shengmu
349 * over without shengmu,
350 * ex: "kaneiji" -> "ka'nei'ji".
352 if ((value.m_key.m_initial != CHEWING_ZERO_INITIAL &&
353 !(value.m_key.m_middle == CHEWING_ZERO_MIDDLE &&
354 value.m_key.m_final == CHEWING_ZERO_FINAL)) &&
355 nextstep->m_key.m_initial == CHEWING_ZERO_INITIAL)
358 /* prefer the complete pinyin 'er'
359 * over the in-complete pinyin 'r',
360 * ex: "xierqi" -> "xi'er'qi."
362 if ((value.m_key.m_initial == CHEWING_ZERO_INITIAL &&
363 value.m_key.m_middle == CHEWING_ZERO_MIDDLE &&
364 value.m_key.m_final == CHEWING_ER) &&
365 (nextstep->m_key.m_initial == CHEWING_R &&
366 nextstep->m_key.m_middle == CHEWING_ZERO_MIDDLE &&
367 nextstep->m_key.m_final == CHEWING_ZERO_FINAL))
371 /* prefer the 'a' at the end of clause,
372 * ex: "zheyanga$" -> "zhe'yang'a$".
374 if (value.m_parsed_len == len &&
375 (nextstep->m_key.m_initial != CHEWING_ZERO_INITIAL &&
376 nextstep->m_key.m_final == CHEWING_A) &&
377 (value.m_key.m_initial == CHEWING_ZERO_INITIAL &&
378 value.m_key.m_middle == CHEWING_ZERO_MIDDLE &&
379 value.m_key.m_final == CHEWING_A))
386 /* final step for back tracing. */
387 gint16 parsed_len = final_step(step_len, keys, key_rests);
389 /* post processing for re-split table. */
390 if (options & USE_RESPLIT_TABLE) {
391 post_process2(options, keys, key_rests, str, len);
398 int FullPinyinParser2::final_step(size_t step_len, ChewingKeyVector & keys,
399 ChewingKeyRestVector & key_rests) const{
401 gint16 parsed_len = 0;
402 parse_value_t * curstep = NULL;
404 /* find longest match, which starts from the beginning of input. */
405 for (i = step_len - 1; i >= 0; --i) {
406 curstep = &g_array_index(m_parse_steps, parse_value_t, i);
407 if (i == curstep->m_parsed_len)
410 /* prepare saving. */
411 parsed_len = curstep->m_parsed_len;
412 gint16 num_keys = curstep->m_num_keys;
413 g_array_set_size(keys, num_keys);
414 g_array_set_size(key_rests, num_keys);
416 /* save the match. */
417 while (curstep->m_last_step != -1) {
418 gint16 pos = curstep->m_num_keys - 1;
421 if (0 != curstep->m_key.get_table_index()) {
422 ChewingKey * key = &g_array_index(keys, ChewingKey, pos);
423 ChewingKeyRest * rest = &g_array_index
424 (key_rests, ChewingKeyRest, pos);
425 *key = curstep->m_key; *rest = curstep->m_key_rest;
429 curstep = &g_array_index(m_parse_steps, parse_value_t,
430 curstep->m_last_step);
435 bool FullPinyinParser2::post_process2(pinyin_option_t options,
436 ChewingKeyVector & keys,
437 ChewingKeyRestVector & key_rests,
441 assert(keys->len == key_rests->len);
442 gint num_keys = keys->len;
444 ChewingKey * cur_key = NULL, * next_key = NULL;
445 ChewingKeyRest * cur_rest = NULL, * next_rest = NULL;
446 guint16 next_tone = CHEWING_ZERO_TONE;
448 for (i = 0; i < num_keys - 1; ++i) {
449 cur_rest = &g_array_index(key_rests, ChewingKeyRest, i);
450 next_rest = &g_array_index(key_rests, ChewingKeyRest, i + 1);
453 if (cur_rest->m_raw_end != next_rest->m_raw_begin)
456 cur_key = &g_array_index(keys, ChewingKey, i);
457 next_key = &g_array_index(keys, ChewingKey, i + 1);
460 if (CHEWING_ZERO_TONE != cur_key->m_tone)
464 if (options & USE_TONE) {
465 next_tone = next_key->m_tone;
466 if (CHEWING_ZERO_TONE != next_tone) {
467 next_key->m_tone = CHEWING_ZERO_TONE;
468 next_rest->m_raw_end --;
472 /* lookup re-split table */
474 const resplit_table_item_t * item = NULL;
476 item = retrieve_resplit_item_by_original_pinyins
477 (options, cur_key, cur_rest, next_key, next_rest,
482 if (item->m_orig_freq >= item->m_new_freq)
486 const char * onepinyin = str + cur_rest->m_raw_begin;
487 size_t len = strlen(item->m_new_keys[0]);
489 assert(parse_one_key(options, *cur_key, onepinyin, len));
490 cur_rest->m_raw_end = cur_rest->m_raw_begin + len;
492 next_rest->m_raw_begin = cur_rest->m_raw_end;
493 onepinyin = str + next_rest->m_raw_begin;
494 len = strlen(item->m_new_keys[1]);
496 assert(parse_one_key(options, *next_key, onepinyin, len));
500 if (options & USE_TONE) {
501 if (CHEWING_ZERO_TONE != next_tone) {
502 next_key->m_tone = next_tone;
503 next_rest->m_raw_end ++;
511 const divided_table_item_t * FullPinyinParser2::retrieve_divided_item
512 (pinyin_option_t options, ChewingKey * key, ChewingKeyRest * rest,
513 const char * str, int len) const {
515 /* lookup divided table */
517 const divided_table_item_t * item = NULL;
518 for (k = 0; k < G_N_ELEMENTS(divided_table); ++k) {
519 item = divided_table + k;
521 const char * onepinyin = str + rest->m_raw_begin;
522 size_t len = strlen(item->m_orig_key);
524 if (rest->length() != len)
527 if (0 == strncmp(onepinyin, item->m_orig_key, len))
531 /* found the match */
532 if (k < G_N_ELEMENTS(divided_table)) {
534 item = divided_table + k;
542 const resplit_table_item_t * FullPinyinParser2::retrieve_resplit_item_by_original_pinyins
543 (pinyin_option_t options,
544 ChewingKey * cur_key, ChewingKeyRest * cur_rest,
545 ChewingKey * next_key, ChewingKeyRest * next_rest,
546 const char * str, int len) const{
547 /* lookup re-split table */
549 const resplit_table_item_t * item = NULL;
551 for (k = 0; k < G_N_ELEMENTS(resplit_table); ++k) {
552 item = resplit_table + k;
554 const char * onepinyin = str + cur_rest->m_raw_begin;
555 size_t len = strlen(item->m_orig_keys[0]);
557 if (cur_rest->length() != len)
560 if (0 != strncmp(onepinyin, item->m_orig_keys[0], len))
563 onepinyin = str + next_rest->m_raw_begin;
564 len = strlen(item->m_orig_keys[1]);
566 if (next_rest->length() != len)
569 if (0 == strncmp(onepinyin, item->m_orig_keys[1], len))
573 /* found the match */
574 if (k < G_N_ELEMENTS(resplit_table)) {
575 item = resplit_table + k;
582 const resplit_table_item_t * FullPinyinParser2::retrieve_resplit_item_by_resplit_pinyins
583 (pinyin_option_t options,
584 ChewingKey * cur_key, ChewingKeyRest * cur_rest,
585 ChewingKey * next_key, ChewingKeyRest * next_rest,
586 const char * str, int len) const {
587 /* lookup divide table */
589 const resplit_table_item_t * item = NULL;
591 for (k = 0; k < G_N_ELEMENTS(resplit_table); ++k) {
592 item = resplit_table + k;
594 const char * onepinyin = str + cur_rest->m_raw_begin;
595 size_t len = strlen(item->m_orig_keys[0]);
597 if (cur_rest->length() != len)
600 if (0 != strncmp(onepinyin, item->m_orig_keys[0], len))
603 onepinyin = str + next_rest->m_raw_begin;
604 len = strlen(item->m_orig_keys[1]);
606 if (next_rest->length() != len)
609 if (0 == strncmp(onepinyin, item->m_orig_keys[1], len))
613 /* found the match */
614 if (k < G_N_ELEMENTS(resplit_table)) {
615 item = resplit_table + k;
622 #define IS_KEY(x) (('a' <= x && x <= 'z') || x == ';')
624 bool DoublePinyinParser2::parse_one_key(pinyin_option_t options,
626 const char *str, int len) const {
627 options &= ~(PINYIN_CORRECT_ALL|PINYIN_AMB_ALL);
630 if (!(options & PINYIN_INCOMPLETE))
637 int charid = ch == ';' ? 26 : ch - 'a';
638 const char * sheng = m_shengmu_table[charid].m_shengmu;
639 if (NULL == sheng || strcmp(sheng, "'") == 0)
642 if (search_pinyin_index(options, sheng, key)) {
649 ChewingTone tone = CHEWING_ZERO_TONE;
650 options &= ~(PINYIN_INCOMPLETE|CHEWING_INCOMPLETE);
654 if (!(options & USE_TONE))
657 if (!('0' < ch && ch <= '5'))
659 tone = (ChewingTone) (ch - '0');
662 if (2 == len || 3 == len) {
663 /* parse shengmu here. */
668 int charid = ch == ';' ? 26 : ch - 'a';
669 const char * sheng = m_shengmu_table[charid].m_shengmu;
672 if (strcmp(sheng, "'") == 0)
675 /* parse yunmu here. */
680 charid = ch == ';' ? 26 : ch - 'a';
682 const char * yun = m_yunmu_table[charid].m_yunmus[0];
686 gchar * pinyin = g_strdup_printf("%s%s", sheng, yun);
687 if (search_pinyin_index(options, pinyin, key)) {
695 yun = m_yunmu_table[charid].m_yunmus[1];
699 pinyin = g_strdup_printf("%s%s", sheng, yun);
700 if (search_pinyin_index(options, pinyin, key)) {
713 /* only 'a'-'z' and ';' are accepted here. */
714 int DoublePinyinParser2::parse(pinyin_option_t options, ChewingKeyVector & keys,
715 ChewingKeyRestVector & key_rests,
716 const char *str, int len) const {
717 g_array_set_size(keys, 0);
718 g_array_set_size(key_rests, 0);
720 int maximum_len = 0; int i;
721 /* probe the longest possible double pinyin string. */
722 for (i = 0; i < len; ++i) {
723 const char ch = str[i];
724 if (!(IS_KEY(ch) || ('0' < ch && ch <= '5')))
729 /* maximum forward match for double pinyin. */
731 while (parsed_len < maximum_len) {
732 const char * cur_str = str + parsed_len;
733 i = std_lite::min(maximum_len - parsed_len,
734 (int)max_double_pinyin_length);
736 ChewingKey key; ChewingKeyRest key_rest;
738 bool success = parse_one_key(options, key, cur_str, i);
743 if (0 == i) /* no more possible double pinyins. */
746 key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i;
749 /* save the pinyin */
750 g_array_append_val(keys, key);
751 g_array_append_val(key_rests, key_rest);
759 bool DoublePinyinParser2::set_scheme(DoublePinyinScheme scheme) {
762 case DOUBLE_PINYIN_ZRM:
763 m_shengmu_table = double_pinyin_zrm_sheng;
764 m_yunmu_table = double_pinyin_zrm_yun;
766 case DOUBLE_PINYIN_MS:
767 m_shengmu_table = double_pinyin_mspy_sheng;
768 m_yunmu_table = double_pinyin_mspy_yun;
770 case DOUBLE_PINYIN_ZIGUANG:
771 m_shengmu_table = double_pinyin_zgpy_sheng;
772 m_yunmu_table = double_pinyin_zgpy_yun;
774 case DOUBLE_PINYIN_ABC:
775 m_shengmu_table = double_pinyin_abc_sheng;
776 m_yunmu_table = double_pinyin_abc_yun;
778 case DOUBLE_PINYIN_PYJJ:
779 m_shengmu_table = double_pinyin_pyjj_sheng;
780 m_yunmu_table = double_pinyin_pyjj_yun;
782 case DOUBLE_PINYIN_XHE:
783 m_shengmu_table = double_pinyin_xhe_sheng;
784 m_yunmu_table = double_pinyin_xhe_yun;
786 case DOUBLE_PINYIN_CUSTOMIZED:
790 return false; /* no such scheme. */
793 /* the chewing string must be freed with g_free. */
794 static bool search_chewing_symbols(const chewing_symbol_item_t * symbol_table,
795 const char key, const char ** chewing) {
797 /* just iterate the table, as we only have < 50 items. */
798 while (symbol_table->m_input != '\0') {
799 if (symbol_table->m_input == key) {
800 *chewing = symbol_table->m_chewing;
808 static bool search_chewing_tones(const chewing_tone_item_t * tone_table,
809 const char key, char * tone) {
810 *tone = CHEWING_ZERO_TONE;
811 /* just iterate the table, as we only have < 10 items. */
812 while (tone_table->m_input != '\0') {
813 if (tone_table->m_input == key) {
814 *tone = tone_table->m_tone;
823 bool ChewingParser2::parse_one_key(pinyin_option_t options,
825 const char *str, int len) const {
826 options &= ~(PINYIN_CORRECT_ALL|PINYIN_AMB_ALL);
827 char tone = CHEWING_ZERO_TONE;
829 int symbols_len = len;
830 /* probe whether the last key is tone key in str. */
831 if (options & USE_TONE) {
832 char ch = str[len - 1];
833 /* remove tone from input */
834 if (search_chewing_tones(m_tone_table, ch, &tone))
839 gchar * chewing = NULL; const char * onechar = NULL;
841 /* probe the possible chewing map in the rest of str. */
842 for (i = 0; i < symbols_len; ++i) {
843 if (!search_chewing_symbols(m_symbol_table, str[i], &onechar)) {
849 chewing = g_strdup(onechar);
851 gchar * tmp = chewing;
852 chewing = g_strconcat(chewing, onechar, NULL);
857 /* search the chewing in the chewing index table. */
858 if (chewing && search_chewing_index(options, chewing, key)) {
859 /* save back tone if available. */
870 /* only characters in chewing keyboard scheme are accepted here. */
871 int ChewingParser2::parse(pinyin_option_t options, ChewingKeyVector & keys,
872 ChewingKeyRestVector & key_rests,
873 const char *str, int len) const {
874 g_array_set_size(keys, 0);
875 g_array_set_size(key_rests, 0);
877 int maximum_len = 0; int i;
878 /* probe the longest possible chewing string. */
879 for (i = 0; i < len; ++i) {
880 if (!in_chewing_scheme(options, str[i], NULL))
885 /* maximum forward match for chewing. */
887 while (parsed_len < maximum_len) {
888 const char * cur_str = str + parsed_len;
889 i = std_lite::min(maximum_len - parsed_len,
890 (int)max_chewing_length);
892 ChewingKey key; ChewingKeyRest key_rest;
894 bool success = parse_one_key(options, key, cur_str, i);
899 if (0 == i) /* no more possible chewings. */
902 key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i;
905 /* save the pinyin. */
906 g_array_append_val(keys, key);
907 g_array_append_val(key_rests, key_rest);
914 bool ChewingParser2::set_scheme(ChewingScheme scheme) {
916 case CHEWING_STANDARD:
917 m_symbol_table = chewing_standard_symbols;
918 m_tone_table = chewing_standard_tones;
921 m_symbol_table = chewing_ibm_symbols;
922 m_tone_table = chewing_ibm_tones;
924 case CHEWING_GINYIEH:
925 m_symbol_table = chewing_ginyieh_symbols;
926 m_tone_table = chewing_ginyieh_tones;
929 m_symbol_table = chewing_eten_symbols;
930 m_tone_table = chewing_eten_tones;
938 bool ChewingParser2::in_chewing_scheme(pinyin_option_t options,
939 const char key, const char ** symbol)
941 const gchar * chewing = NULL;
942 char tone = CHEWING_ZERO_TONE;
944 if (search_chewing_symbols(m_symbol_table, key, &chewing)) {
950 if (!(options & USE_TONE))
953 if (search_chewing_tones(m_tone_table, key, &tone)) {
955 *symbol = chewing_tone_table[tone];