summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-05-08 14:22:03 +0800
committerPeng Wu <alexepico@gmail.com>2012-05-08 14:22:03 +0800
commit4deccf8c77857f899198f267dc58b55301f1ea13 (patch)
treef87e6851c8c939eb6ac587fb422578652d753d86
parentf383ccfbdd0bf1b3eca3e094879e9283287ad610 (diff)
downloadlibpinyin-4deccf8c77857f899198f267dc58b55301f1ea13.tar.gz
libpinyin-4deccf8c77857f899198f267dc58b55301f1ea13.tar.xz
libpinyin-4deccf8c77857f899198f267dc58b55301f1ea13.zip
improves _get_previous_token
-rw-r--r--src/pinyin.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 55e1957..0e3e99b 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -521,8 +521,31 @@ static phrase_token_t _get_previous_token(pinyin_instance_t * instance,
ssize_t i;
if (0 == offset) {
+ /* get previous token from prefixes. */
prev_token = sentence_start;
+ size_t prev_token_len = 0;
+
+ pinyin_context_t * context = instance->m_context;
+ TokenVector prefixes = instance->m_prefixes;
+ PhraseItem item;
+
+ for (size_t i = 0; i < prefixes->len; ++i) {
+ phrase_token_t token = g_array_index(prefixes, phrase_token_t, i);
+ if (sentence_start == token)
+ continue;
+
+ int retval = context->m_phrase_index->get_phrase_item(token, item);
+ if (ERROR_OK == retval) {
+ size_t token_len = item.get_phrase_length();
+ if (token_len > prev_token_len) {
+ /* found longer match, and save it. */
+ prev_token = token;
+ prev_token_len = token_len;
+ }
+ }
+ }
} else {
+ /* get previous token from match results. */
assert (0 < offset);
phrase_token_t cur_token = g_array_index