summaryrefslogtreecommitdiffstats
path: root/src/PYLibPinyin.cc
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-02-08 11:04:28 +0800
committerPeng Wu <alexepico@gmail.com>2013-02-08 11:04:28 +0800
commit79529dea8225187a0ab1c0d4c87ad558760322d5 (patch)
treebb83fea133ef7138c5c6fa81bb115e49f6f71edc /src/PYLibPinyin.cc
parent42fdd95eeea6e72f65fe74e356b6ab96bc95666c (diff)
downloadibus-libpinyin-79529dea8225187a0ab1c0d4c87ad558760322d5.tar.gz
ibus-libpinyin-79529dea8225187a0ab1c0d4c87ad558760322d5.tar.xz
ibus-libpinyin-79529dea8225187a0ab1c0d4c87ad558760322d5.zip
write importPinyinDictionary
Diffstat (limited to 'src/PYLibPinyin.cc')
-rw-r--r--src/PYLibPinyin.cc48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc
index 811400c..285e52c 100644
--- a/src/PYLibPinyin.cc
+++ b/src/PYLibPinyin.cc
@@ -239,7 +239,51 @@ LibPinyinBackEnd::modified (void)
static_cast<gpointer> (this));
}
-bool
+gboolean
+LibPinyinBackEnd::importPinyinDictionary(const char * filename)
+{
+ /* user phrase library should be loaded here. */
+ FILE * dictfile = fopen(filename, "r");
+ if (NULL == dictfile)
+ return FALSE;
+
+ import_iterator_t * iter = pinyin_begin_add_phrases
+ (m_pinyin_context, 15);
+
+ if (NULL == iter)
+ return FALSE;
+
+ char* linebuf = NULL; size_t size = 0; ssize_t read;
+ while ((read = getline(&linebuf, &size, dictfile)) != -1) {
+ if (0 == strlen(linebuf))
+ continue;
+
+ if ( '\n' == linebuf[strlen(linebuf) - 1] ) {
+ linebuf[strlen(linebuf) - 1] = '\0';
+ }
+
+ gchar ** items = g_strsplit_set(linebuf, " \t", 3);
+ guint len = g_strv_length(items);
+
+ gchar * phrase = NULL, * pinyin = NULL;
+ gint count = -1;
+ if (2 == len || 3 == len) {
+ phrase = items[0];
+ pinyin = items[1];
+ if (3 == len)
+ count = atoi(items[2]);
+ } else
+ continue;
+
+ pinyin_iterator_add_phrase(iter, phrase, pinyin, count);
+ }
+
+ pinyin_end_add_phrases(iter);
+ fclose(dictfile);
+}
+
+
+gboolean
LibPinyinBackEnd::clearPinyinUserData (const char * target)
{
if (0 == strcmp("all", target))
@@ -249,6 +293,8 @@ LibPinyinBackEnd::clearPinyinUserData (const char * target)
PHRASE_INDEX_MAKE_TOKEN(15, null_token));
else
g_warning("unknown clear target: %s.\n", target);
+
+ return TRUE;
}
gboolean