diff options
author | Peng Wu <alexepico@gmail.com> | 2012-08-07 13:28:26 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-08-07 13:28:26 +0800 |
commit | 28062ae7f665da020fec7e75754966a6209c2525 (patch) | |
tree | bd6404bd893026289bf77895f0f75767fee99327 | |
parent | 839132342b4d5023e41fe96c120e4d16bf9928f7 (diff) | |
download | libpinyin-28062ae7f665da020fec7e75754966a6209c2525.tar.gz libpinyin-28062ae7f665da020fec7e75754966a6209c2525.tar.xz libpinyin-28062ae7f665da020fec7e75754966a6209c2525.zip |
add apis
-rw-r--r-- | src/pinyin.cpp | 32 | ||||
-rw-r--r-- | src/pinyin.h | 6 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 555ad15..755fb04 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -1604,6 +1604,17 @@ bool pinyin_clear_constraints(pinyin_instance_t * instance){ return retval; } +bool pinyin_lookup_token(pinyin_instance_t * instance, + const char * phrase, phrase_token_t * token){ + pinyin_context_t * & context = instance->m_context; + glong ucs4_len = 0; + ucs4_t * ucs4_phrase = g_utf8_to_ucs4(phrase, -1, NULL, &ucs4_len, NULL); + + int retval = context->m_phrase_table->search(ucs4_len, ucs4_phrase, *token); + + return SEARCH_OK == retval; +} + /* the returned word should be freed by g_free. */ bool pinyin_translate_token(pinyin_instance_t * instance, phrase_token_t token, char ** word){ @@ -1618,6 +1629,27 @@ bool pinyin_translate_token(pinyin_instance_t * instance, return ERROR_OK == retval; } +bool pinyin_get_pinyins_from_token(pinyin_instance_t * instance, + phrase_token_t token, GArray * pinyinkeys){ + pinyin_context_t * & context = instance->m_context; + FacadePhraseIndex * & phrase_index = context->m_phrase_index; + PhraseItem item; + + int retval = phrase_index->get_phrase_item(token, item); + if (1 != item.get_phrase_length()) + return false; + + guint8 npinyin = item.get_n_pronunciation(); + size_t i; + ChewingKey onekey; guint32 freq; + for (i = 0; i < npinyin; ++i){ + item.get_nth_pronunciation(i, &onekey, freq); + g_array_append_val(pinyinkeys, onekey); + } + return true; +} + + bool pinyin_train(pinyin_instance_t * instance){ if (!instance->m_context->m_user_dir) return false; diff --git a/src/pinyin.h b/src/pinyin.h index bfc13a0..4a01c5f 100644 --- a/src/pinyin.h +++ b/src/pinyin.h @@ -438,6 +438,9 @@ bool pinyin_clear_constraint(pinyin_instance_t * instance, */ bool pinyin_clear_constraints(pinyin_instance_t * instance); +bool pinyin_lookup_token(pinyin_instance_t * instance, + const char * phrase, phrase_token_t * token); + /** * pinyin_translate_token: * @instance: the pinyin instance. @@ -453,6 +456,9 @@ bool pinyin_clear_constraints(pinyin_instance_t * instance); bool pinyin_translate_token(pinyin_instance_t * instance, phrase_token_t token, char ** word); +bool pinyin_get_pinyins_from_token(pinyin_instance_t * instance, + phrase_token_t token, GArray * pinyinkeys); + /** * pinyin_train: * @instance: the pinyin instance. |