summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-09-06 13:57:57 +0800
committerPeng Wu <alexepico@gmail.com>2011-09-06 13:57:57 +0800
commitf31c2e6b65d7bfa50af449dd26206b0805968d81 (patch)
treec6b5ab95cac80ec872a7684bceff399892acb282
parenta4901dd10796363b9f74db459965c8a9d4628ddb (diff)
downloadlibpinyin-f31c2e6b65d7bfa50af449dd26206b0805968d81.zip
libpinyin-f31c2e6b65d7bfa50af449dd26206b0805968d81.tar.gz
libpinyin-f31c2e6b65d7bfa50af449dd26206b0805968d81.tar.xz
add chewing support
-rw-r--r--src/pinyin.cpp28
-rw-r--r--src/pinyin.h8
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/test_chewing.cpp0
4 files changed, 41 insertions, 2 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 822ebe9..8e5773d 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -9,6 +9,7 @@ struct _pinyin_context_t{
BitmapPinyinValidator m_validator;
PinyinDefaultParser * m_default_parser;
PinyinShuangPinParser * m_shuang_pin_parser;
+ PinyinZhuYinParser * m_chewing_parser;
PinyinLargeTable * m_pinyin_table;
PhraseLargeTable * m_phrase_table;
@@ -40,6 +41,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
context->m_validator.initialize(context->m_pinyin_table);
context->m_default_parser = new PinyinDefaultParser;
context->m_shuang_pin_parser = new PinyinShuangPinParser;
+ context->m_chewing_parser = new PinyinZhuYinParser;
context->m_phrase_table = new PhraseLargeTable;
chunk = new MemoryChunk;
@@ -86,6 +88,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
void pinyin_fini(pinyin_context_t * context){
delete context->m_default_parser;
delete context->m_shuang_pin_parser;
+ delete context->m_chewing_parser;
delete context->m_pinyin_table;
delete context->m_phrase_table;
delete context->m_phrase_index;
@@ -223,6 +226,31 @@ bool pinyin_parse_more_doubles(pinyin_context_t * context,
return pinyin_len == parse_len;
}
+bool pinyin_parse_chewing(pinyin_context_t * context,
+ const char * onechewing,
+ PinyinKey * onekey){
+ int chewing_len = strlen(onechewing);
+ int parse_len = context->m_chewing_parser->parse_one_key
+ ( context->m_validator, *onekey, onechewing, chewing_len );
+ return chewing_len == parse_len;
+}
+
+bool pinyin_parse_more_chewing(pinyin_context_t * context,
+ const char * chewings,
+ PinyinKeyVector * pinyin_keys){
+ int chewing_len = strlen(chewings);
+ PinyinKeyPosVector poses;
+ poses = g_array_new(FALSE, FALSE, sizeof(PinyinKeyPos));
+
+ int parse_len = context->m_chewing_parser->parse
+ ( context->m_validator, pinyin_keys,
+ poses, chewings, chewing_len);
+
+ g_array_free(poses, TRUE);
+ return pinyin_len == parse_len;
+}
+
+
static gint compare_token( gconstpointer lhs, gconstpointer rhs){
phrase_token_t token_lhs = *((phrase_token_t *)lhs);
phrase_token_t token_rhs = *((phrase_token_t *)rhs);
diff --git a/src/pinyin.h b/src/pinyin.h
index 0c612b7..2ac1001 100644
--- a/src/pinyin.h
+++ b/src/pinyin.h
@@ -72,8 +72,14 @@ bool pinyin_parse_double(pinyin_context_t * context,
const char * onepinyin,
PinyinKey * onekey);
bool pinyin_parse_more_doubles(pinyin_context_t * context,
- const char * onepinyin,
+ const char * pinyins,
PinyinKeyVector pinyin_keys);
+bool pinyin_parse_chewing(pinyin_context_t * context,
+ const char * onechewing,
+ PinyinKey * onekey);
+bool pinyin_parse_more_chewing(pinyin_context_t * context,
+ const char * chewings,
+ PinyinKeyVector * pinyin_keys);
bool pinyin_get_candidates(pinyin_context_t * context,
size_t offset,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fd9039d..94c831c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,7 +31,8 @@ INCLUDES = -I$(top_srcdir)/src \
@GLIB2_CPPFLAGS@
noinst_PROGRAMS = test_pinyin \
- test_phrase
+ test_phrase \
+ test_chewing
test_pinyin_SOURCES = test_pinyin.cpp
@@ -40,3 +41,7 @@ test_pinyin_LDADD = ../src/libpinyin.la @GLIB2_LDFLAGS@
test_phrase_SOURCES = test_phrase.cpp
test_phrase_LDADD = ../src/libpinyin.la @GLIB2_LDFLAGS@
+
+test_chewing_SOURCES = test_chewing.cpp
+
+test_chewing_LDADD = ../src/libpinyin.la @GLIB2_LDFLAGS@ \ No newline at end of file
diff --git a/tests/test_chewing.cpp b/tests/test_chewing.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/test_chewing.cpp