diff options
author | Peng Wu <alexepico@gmail.com> | 2012-12-04 11:05:33 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-12-04 11:05:33 +0800 |
commit | fdefa16aae400be58033fa0be6daa0b9beeb0492 (patch) | |
tree | cb2c6fc769bfdae944fbebe125f347cacd11b954 /src/pinyin.cpp | |
parent | 01b200662b3706c071658103c1cc73ea307d685f (diff) | |
download | libpinyin-fdefa16aae400be58033fa0be6daa0b9beeb0492.tar.gz libpinyin-fdefa16aae400be58033fa0be6daa0b9beeb0492.tar.xz libpinyin-fdefa16aae400be58033fa0be6daa0b9beeb0492.zip |
write pinyin_token_*
Diffstat (limited to 'src/pinyin.cpp')
-rw-r--r-- | src/pinyin.cpp | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index bba9f1a..8bb7a8b 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -721,7 +721,6 @@ bool pinyin_guess_sentence_with_prefix(pinyin_instance_t * instance, if (i > MAX_PHRASE_LENGTH) break; - phrase_token_t token = null_token; ucs4_t * start = ucs4_str + len_str - i; PhraseTokens tokens; @@ -1817,6 +1816,85 @@ bool pinyin_get_pinyin_string(pinyin_instance_t * instance, return true; } +bool pinyin_token_get_phrase(pinyin_instance_t * instance, + phrase_token_t token, + guint * len, + gchar ** utf8_str) { + *len = 0; *utf8_str = NULL; + pinyin_context_t * & context = instance->m_context; + PhraseItem item; + ucs4_t buffer[MAX_PHRASE_LENGTH]; + + int retval = context->m_phrase_index->get_phrase_item(token, item); + if (ERROR_OK != retval) + return false; + + item.get_phrase_string(buffer); + *len = item.get_phrase_length(); + *utf8_str = g_ucs4_to_utf8(buffer, *len, NULL, NULL, NULL); + return true; +} + +bool pinyin_token_get_n_pronunciation(pinyin_instance_t * instance, + phrase_token_t token, + guint * num){ + *num = 0; + pinyin_context_t * & context = instance->m_context; + PhraseItem item; + + int retval = context->m_phrase_index->get_phrase_item(token, item); + if (ERROR_OK != retval) + return false; + + *num = item.get_n_pronunciation(); + return true; +} + +bool pinyin_token_get_nth_pronunciation(pinyin_instance_t * instance, + phrase_token_t token, + guint nth, + ChewingKeyVector keys){ + g_array_set_size(keys, 0); + pinyin_context_t * & context = instance->m_context; + PhraseItem item; + ChewingKey buffer[MAX_PHRASE_LENGTH]; + guint32 freq = 0; + + int retval = context->m_phrase_index->get_phrase_item(token, item); + if (ERROR_OK != retval) + return false; + + item.get_nth_pronunciation(nth, buffer, freq); + guint8 len = item.get_phrase_length(); + g_array_append_vals(keys, buffer, len); + return true; +} + +bool pinyin_token_get_unigram_frequency(pinyin_instance_t * instance, + phrase_token_t token, + guint * freq) { + *freq = 0; + pinyin_context_t * & context = instance->m_context; + PhraseItem item; + + int retval = context->m_phrase_index->get_phrase_item(token, item); + if (ERROR_OK != retval) + return false; + + *freq = item.get_unigram_frequency(); + return true; +} + +bool pinyin_token_add_unigram_frequency(pinyin_instance_t * instance, + phrase_token_t token, + guint delta){ + pinyin_context_t * & context = instance->m_context; + int retval = context->m_phrase_index->add_unigram_frequency + (token, delta); + return ERROR_OK == retval; +} + + /** * Note: prefix is the text before the pre-edit string. |