summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-08-29 16:04:08 +0800
committerPeng Wu <alexepico@gmail.com>2011-08-29 16:04:08 +0800
commitd8ccee5041c8ecbaf4568e42b0f187fe615ae7ad (patch)
tree0b03cc4a623b324766d36a8ccce100bb9a1f1c9e
parenta5871126f29fb0bdf4a994221f4e51301c77aed1 (diff)
downloadlibpinyin-d8ccee5041c8ecbaf4568e42b0f187fe615ae7ad.zip
libpinyin-d8ccee5041c8ecbaf4568e42b0f187fe615ae7ad.tar.gz
libpinyin-d8ccee5041c8ecbaf4568e42b0f187fe615ae7ad.tar.xz
add pinyin apis
-rw-r--r--src/pinyin.cpp29
-rw-r--r--src/pinyin.h5
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);