diff options
author | Peng Wu <alexepico@gmail.com> | 2011-08-16 18:32:26 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-08-16 18:45:15 +0800 |
commit | 2b421aafedeba0a9e7d1684365a1e5671081e16b (patch) | |
tree | 20992d76096d3b3d98bc99e834cbec205c055406 /src/pinyin.cpp | |
parent | ada3ecdc29b23e420871f0dbacd070c67d1095ff (diff) | |
download | libpinyin-2b421aafedeba0a9e7d1684365a1e5671081e16b.tar.gz libpinyin-2b421aafedeba0a9e7d1684365a1e5671081e16b.tar.xz libpinyin-2b421aafedeba0a9e7d1684365a1e5671081e16b.zip |
pinyin apis WIP
Diffstat (limited to 'src/pinyin.cpp')
-rw-r--r-- | src/pinyin.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index ef21d5b..ca46287 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -52,7 +52,16 @@ bool pinyin_set_pinyin_keys(pinyin_context_t * context, /* the returned sentence should be freed by g_free(). */ bool pinyin_get_guessed_sentence(pinyin_context_t * context, - char ** sentence); + char ** sentence){ + bool retval = context->m_pinyin_lookup->get_best_match + (context->m_pinyin_keys, context->m_constraints, + context->m_match_results); + + retval = context->m_pinyin_lookup->convert_to_utf8 + (context->m_match_results, *sentence) && retval; + + return retval; +} bool pinyin_parse_full(pinyin_context_t * context, const char * onepinyin, @@ -104,9 +113,29 @@ bool pinyin_parse_more_doubles(pinyin_context_t * context, bool pinyin_get_candidates(pinyin_context_t * context, size_t offset, TokenVector tokens); + bool pinyin_choose_candidate(pinyin_context_t * context, - size_t offset, phrase_token_t token); -bool pinyin_clear_constraints(pinyin_context_t * context); + size_t offset, phrase_token_t token){ + bool retval = context->m_pinyin_lookup->add_constraint + (context->m_constraints, offset, token); + + retval = context->m_pinyin_lookup->validate_constraint + (context->m_constraints, context->m_pinyin_keys) && retval; + + return retval; +} + +bool pinyin_clear_constraints(pinyin_context_t * context){ + bool retval = true; + CandidateConstraints & constraints = context->m_constraints; + + for ( size_t i = 0; i < constraints->len; ++i ) { + retval = context->m_pinyin_lookup->clear_constraint + (constraints, i) && retval; + } + + return retval; +} /* the returned word should be freed by g_free. */ bool pinyin_translate_token(pinyin_context_t * context, |