summaryrefslogtreecommitdiffstats
path: root/src/pinyin.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-08-16 15:39:50 +0800
committerPeng Wu <alexepico@gmail.com>2011-08-16 16:40:20 +0800
commitada3ecdc29b23e420871f0dbacd070c67d1095ff (patch)
tree315daa2160a70a977083b8ae14715def61c7745c /src/pinyin.cpp
parentb17795c4a34228f6f3962309ccb0fefe05e2fb3a (diff)
downloadlibpinyin-ada3ecdc29b23e420871f0dbacd070c67d1095ff.tar.gz
libpinyin-ada3ecdc29b23e420871f0dbacd070c67d1095ff.tar.xz
libpinyin-ada3ecdc29b23e420871f0dbacd070c67d1095ff.zip
pinyin apis write in progress
Diffstat (limited to 'src/pinyin.cpp')
-rw-r--r--src/pinyin.cpp69
1 files changed, 57 insertions, 12 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 9ed172b..ef21d5b 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -7,9 +7,11 @@
*/
struct _pinyin_context_t{
+ PinyinCustomSettings m_custom;
+
+ BitmapPinyinValidator m_validator;
PinyinDefaultParser * m_default_parser;
PinyinShuangPinParser * m_shuang_pin_parser;
- PinyinCustomSettings * m_custom;
PinyinLargeTable * m_pinyin_table;
PhraseLargeTable * m_phrase_table;
@@ -23,7 +25,6 @@ struct _pinyin_context_t{
MatchResults m_match_results;
CandidateConstraints m_constraints;
- BitmapPinyinValidator * m_validator;
const char * m_system_dir;
const char * m_user_dir;
};
@@ -33,10 +34,20 @@ void pinyin_fini(pinyin_context_t * context);
/* copy from custom to context->m_custom. */
bool pinyin_set_options(pinyin_context_t * context,
- PinyinCustomSettings * custom);
-/* copy from pinyin_keys to m_pinyins. */
+ PinyinCustomSettings * custom){
+ guint32 option = custom->to_value();
+ context->m_custom.from_value(option);
+ return true;
+}
+
+/* copy from pinyin_keys to m_pinyin_keys. */
bool pinyin_set_pinyin_keys(pinyin_context_t * context,
- PinyinKeyVector pinyin_keys);
+ PinyinKeyVector pinyin_keys){
+ g_array_set_size(context->m_pinyin_keys, 0);
+ g_array_append_vals(context->m_pinyin_keys,
+ pinyin_keys->data, pinyin_keys->len);
+ return true;
+}
/* the returned sentence should be freed by g_free(). */
@@ -45,17 +56,51 @@ bool pinyin_get_guessed_sentence(pinyin_context_t * context,
bool pinyin_parse_full(pinyin_context_t * context,
const char * onepinyin,
- PinyinKey * onekey);
+ PinyinKey * onekey){
+ int pinyin_len = strlen(onepinyin);
+ int parse_len = context->m_default_parser->parse_one_key
+ ( context->m_validator, *onekey, onepinyin, pinyin_len);
+ return pinyin_len == parse_len;
+}
+
bool pinyin_parse_more_fulls(pinyin_context_t * context,
const char * pinyins,
- PinyinKeyVector pinyin_keys);
+ PinyinKeyVector pinyin_keys){
+ int pinyin_len = strlen(pinyins);
+ PinyinKeyPosVector poses;
+ poses = g_array_new(FALSE, FALSE, sizeof(PinyinKeyPos));
+
+ int parse_len = context->m_default_parser->parse
+ ( context->m_validator, pinyin_keys,
+ poses, pinyins, pinyin_len);
+
+ g_array_free(poses, TRUE);
+ return pinyin_len == parse_len;
+}
bool pinyin_parse_double(pinyin_context_t * context,
const char * onepinyin,
- PinyinKey * onekey);
+ PinyinKey * onekey){
+ int pinyin_len = strlen(onepinyin);
+ int parse_len = context->m_shuang_pin_parser->parse_one_key
+ ( context->m_validator, *onekey, onepinyin, pinyin_len);
+ return pinyin_len == parse_len;
+}
+
bool pinyin_parse_more_doubles(pinyin_context_t * context,
const char * pinyins,
- PinyinKeyVector pinyin_keys);
+ PinyinKeyVector pinyin_keys){
+ int pinyin_len = strlen(pinyins);
+ PinyinKeyPosVector poses;
+ poses = g_array_new(FALSE, FALSE, sizeof(PinyinKeyPos));
+
+ int parse_len = context->m_shuang_pin_parser->parse
+ ( context->m_validator, pinyin_keys,
+ poses, pinyins, pinyin_len);
+
+ g_array_free(poses, TRUE);
+ return pinyin_len == parse_len;
+}
bool pinyin_get_candidates(pinyin_context_t * context,
size_t offset, TokenVector tokens);
@@ -70,15 +115,15 @@ bool pinyin_translate_token(pinyin_context_t * context,
utf16_t buffer[MAX_PHRASE_LENGTH];
bool retval = context->m_phrase_index->get_phrase_item(token, item);
- m_cache_phrase_item.get_phrase_string(buffer);
- guint8 length = m_cache_phrase_item.get_phrase_length();
+ item.get_phrase_string(buffer);
+ guint8 length = item.get_phrase_length();
*word = g_utf16_to_utf8(buffer, length, NULL, NULL, NULL);
return retval;
}
bool pinyin_train(pinyin_context_t * context){
bool retval = context->m_pinyin_lookup->train_result
- (context->m_piinyin_keys, context->m_constraints,
+ (context->m_pinyin_keys, context->m_constraints,
context->m_match_results);
return retval;
}