Loading meson.build +1 −1 Original line number Diff line number Diff line # -*- mode: conf -*- project('zero-pinyin-service', ['c', 'cpp'], version: '0.5.0', version: '0.5.1', license: 'GPL', default_options: [ 'warning_level=2', Loading zero-pinyin-service.c +38 −7 Original line number Diff line number Diff line Loading @@ -112,9 +112,44 @@ build_sql_for_n_pinyin (GList* pylist, return result; } /** * For a candidate of length group_size, calculate the matched py length. * * This is part of get_candidates_for_n_pinyin(). * * see param meaning there. */ static guint get_matched_py_length (const char* preedit_str, GList* pylist, const guint group_size) { guint matched_py_length = 0; GList* iter = pylist; g_assert_cmpint (group_size, >=, 1); /* For usual pinyin string, just add up the Pinyin length. But for * pinyin that contains ', when a Pinyin in pylist is used, also take * the ' before and after it. */ for (guint i = 0; i < group_size; ++i) { while (preedit_str[matched_py_length] == '\'') { matched_py_length++; } matched_py_length += ((Pinyin*) iter->data)->length; while (preedit_str[matched_py_length] == '\'') { matched_py_length++; } iter = iter->next; } return matched_py_length; } /** * fetch candidates for a fixed word length. * * @db: sqlite3 db handler. * @preedit_str: the pinyin preedit str. can contain '. This is needed to * calculate matched_py_length. * @pylist: the pinyin list. * @group_size: the fixed word length. use this many pinyin from pinyin list. * @limit: fetch this many result is enough for user. more is not a problem though. Loading @@ -124,6 +159,7 @@ build_sql_for_n_pinyin (GList* pylist, */ static guint get_candidates_for_n_pinyin (sqlite3* db, const char* preedit_str, GList* pylist, const guint group_size, const guint limit, Loading @@ -143,12 +179,7 @@ get_candidates_for_n_pinyin (sqlite3* db, sql = build_sql_for_n_pinyin (pylist, group_size, MAX (limit, DEFAULT_LIMIT)); g_message ("build_sql_for_n_pinyin result SQL:\n\n%s\n", sql); guint matched_py_length = 0; GList* iter = pylist; for (guint i = 0; i < group_size; ++i) { matched_py_length += ((Pinyin*) iter->data)->length; iter = iter->next; } guint matched_py_length = get_matched_py_length (preedit_str, pylist, group_size); sqlite3_stmt* stmt = NULL; const char* unused; Loading Loading @@ -221,7 +252,7 @@ get_candidates (sqlite3* db, GList* candidates = NULL; while (fetched_size < fetch_size && group_size > 0) { g_message ("phrase length=%u", group_size); r = get_candidates_for_n_pinyin (db, pylist, group_size, fetch_size - fetched_size, &candidates); r = get_candidates_for_n_pinyin (db, preedit_str, pylist, group_size, fetch_size - fetched_size, &candidates); if (candidates) { GList* iter = g_list_first (candidates); Candidate* c = NULL; Loading Loading
meson.build +1 −1 Original line number Diff line number Diff line # -*- mode: conf -*- project('zero-pinyin-service', ['c', 'cpp'], version: '0.5.0', version: '0.5.1', license: 'GPL', default_options: [ 'warning_level=2', Loading
zero-pinyin-service.c +38 −7 Original line number Diff line number Diff line Loading @@ -112,9 +112,44 @@ build_sql_for_n_pinyin (GList* pylist, return result; } /** * For a candidate of length group_size, calculate the matched py length. * * This is part of get_candidates_for_n_pinyin(). * * see param meaning there. */ static guint get_matched_py_length (const char* preedit_str, GList* pylist, const guint group_size) { guint matched_py_length = 0; GList* iter = pylist; g_assert_cmpint (group_size, >=, 1); /* For usual pinyin string, just add up the Pinyin length. But for * pinyin that contains ', when a Pinyin in pylist is used, also take * the ' before and after it. */ for (guint i = 0; i < group_size; ++i) { while (preedit_str[matched_py_length] == '\'') { matched_py_length++; } matched_py_length += ((Pinyin*) iter->data)->length; while (preedit_str[matched_py_length] == '\'') { matched_py_length++; } iter = iter->next; } return matched_py_length; } /** * fetch candidates for a fixed word length. * * @db: sqlite3 db handler. * @preedit_str: the pinyin preedit str. can contain '. This is needed to * calculate matched_py_length. * @pylist: the pinyin list. * @group_size: the fixed word length. use this many pinyin from pinyin list. * @limit: fetch this many result is enough for user. more is not a problem though. Loading @@ -124,6 +159,7 @@ build_sql_for_n_pinyin (GList* pylist, */ static guint get_candidates_for_n_pinyin (sqlite3* db, const char* preedit_str, GList* pylist, const guint group_size, const guint limit, Loading @@ -143,12 +179,7 @@ get_candidates_for_n_pinyin (sqlite3* db, sql = build_sql_for_n_pinyin (pylist, group_size, MAX (limit, DEFAULT_LIMIT)); g_message ("build_sql_for_n_pinyin result SQL:\n\n%s\n", sql); guint matched_py_length = 0; GList* iter = pylist; for (guint i = 0; i < group_size; ++i) { matched_py_length += ((Pinyin*) iter->data)->length; iter = iter->next; } guint matched_py_length = get_matched_py_length (preedit_str, pylist, group_size); sqlite3_stmt* stmt = NULL; const char* unused; Loading Loading @@ -221,7 +252,7 @@ get_candidates (sqlite3* db, GList* candidates = NULL; while (fetched_size < fetch_size && group_size > 0) { g_message ("phrase length=%u", group_size); r = get_candidates_for_n_pinyin (db, pylist, group_size, fetch_size - fetched_size, &candidates); r = get_candidates_for_n_pinyin (db, preedit_str, pylist, group_size, fetch_size - fetched_size, &candidates); if (candidates) { GList* iter = g_list_first (candidates); Candidate* c = NULL; Loading