Commit bd0a7f68 authored by Yuanle Song's avatar Yuanle Song
Browse files

v0.5.1 support pinyin with ' in them.

now xi'an etc types okay.
parent 402bd26e
Loading
Loading
Loading
Loading
+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',
+38 −7
Original line number Diff line number Diff line
@@ -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.
@@ -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,
@@ -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;
@@ -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;