diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pinyin.cpp | 29 | ||||
-rw-r--r-- | src/pinyin.h | 5 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index fb43394..93ddff5 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -307,6 +307,15 @@ bool pinyin_choose_candidate(pinyin_context_t * context, return retval; } +bool pinyin_clear_constraint(pinyin_context_t * context, size_t offset){ + CandidateConstraints & constraints = context->m_constraints; + + bool retval = context->m_pinyin_lookup->clear_constraint + (constraints, offset); + + return retval; +} + bool pinyin_clear_constraints(pinyin_context_t * context){ bool retval = true; CandidateConstraints & constraints = context->m_constraints; @@ -319,6 +328,24 @@ bool pinyin_clear_constraints(pinyin_context_t * context){ return retval; } +bool phrase_segment(pinyin_context_t * context, + const char * sentence, + TokenVector tokens){ + + const glong num_of_chars = g_utf8_strlen(sentence, -1); + glong utf16_len = 0; + utf16_t * utf16 = g_utf8_to_utf16(sentence, -1, NULL, &utf16_len, NULL); + + g_return_val_if_fail(num_of_chars == utf16_len, false); + + bool retval = context->m_phrase_lookup-> + get_best_match(utf16_len, utf16, tokens); + + g_free(utf16); + + return retval; +} + /* the returned word should be freed by g_free. */ bool pinyin_translate_token(pinyin_context_t * context, phrase_token_t token, char ** word){ @@ -377,7 +404,5 @@ bool pinyin_reset(pinyin_context_t * context){ * Note: prefix is the text before the pre-edit string. * bool pinyin_get_guessed_sentence_with_prefix(...); * bool pinyin_get_candidates_with_prefix(...); - * bool phrase_segment(...); - * bool pinyin_clear_constraint(...); * For context-dependent order of the candidates list. */ diff --git a/src/pinyin.h b/src/pinyin.h index 90c9221..c1cd88e 100644 --- a/src/pinyin.h +++ b/src/pinyin.h @@ -48,7 +48,12 @@ bool pinyin_get_candidates(pinyin_context_t * context, bool pinyin_choose_candidate(pinyin_context_t * context, size_t offset, phrase_token_t token); +bool pinyin_clear_constraint(pinyin_context_t * context, + size_t offset); bool pinyin_clear_constraints(pinyin_context_t * context); + +bool phrase_segment(pinyin_context_t * context, const char * sentence, + TokenVector tokens); bool pinyin_translate_token(pinyin_context_t * context, phrase_token_t token, char ** word); |