diff --git a/.gitignore b/.gitignore index 790ab50ad8939a56606bf1b3019308bc097a5ff9..509e2a83bf88757838eae9767fc5be7737411f38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ DEST/ *.deb +build/ +release/ diff --git a/meson.build b/meson.build index bdb054620db66b2262cb193c382cf302fb1ecdcd..3b84d877cf204bc20fae6aa79d03793bd3b9b213 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ # -*- mode: conf -*- project('zero-pinyin-service', ['c', 'cpp'], - version: '0.7.3', + version: '0.8.0', license: 'GPL', default_options: [ 'warning_level=2', @@ -63,8 +63,8 @@ executable('zero-pinyin-service', src, dependencies: shared_dep, install: true, install_dir: '/home/sylecn/bin/sbin/') -test('parse-pinyin', - executable('parse-pinyin', +test('parse-pinyin-test', + executable('parse-pinyin-test', ['../PinyinParser.cc', 'parse-pinyin.cpp', 'parse-pinyin-test.cpp'], dependencies: shared_dep)) test('zero-pinyin-service-test', diff --git a/operational b/operational index 9f6b38725a2a45de148e717c93fadca87286147c..dc79827f01fbcc441bca722d61ac35e62c13874a 100644 --- a/operational +++ b/operational @@ -1,6 +1,6 @@ * COMMENT -*- mode: org -*- #+Date: 2019-04-05 -Time-stamp: <2019-08-31> +Time-stamp: <2019-10-22> #+STARTUP: content * notes :entry: ** 2019-08-31 ibus-pinyin userdb inference notice. @@ -52,6 +52,40 @@ shared between zero-pinyin and ibus-pinyin. * later :entry: * current :entry: ** +** 2019-10-22 handle a an o en etc differently. only match exactly the character. +no fuzzy matching or incomplete pinyin matching. + +if shengmu is 0, always strict match it. +do not allow omit shengmu in zero. + +ao men +澳门 +e nuo +婀娜 + +- DONE use different FLAGS for them. + FLAGS doesn't affect pinyin parsing. + if flag support is to be added, just add it in appdata, as property. + then use the property when building SQL. +- DONE test in bogon VM. +- DONE git push +- build on debian 9 and release deb. later. + +- problems + - result = parse_pinyin("an", 15, PINYIN_FUZZY_ALL); + this only return 1 result. + not an and ang. + why? + + - maybe flag is not used when parsing pinyin string. only used when building + the SQL statement. + + build_sql_for_n_pinyin() + build_where_clause(pylist, n); + yes. here. I should pass the flags around. + + - + ** 2019-08-31 how to format C code? do it before git commit. see ~/c/gtk-im-module/, it uses myastyle-pre-commit-check in git pre-commit ~/bin/myastyle-pre-commit-check diff --git a/parse-pinyin-test.cpp b/parse-pinyin-test.cpp index 21b85e6c5cf032cfef809e6d4fc223fd116e0fef..b8ff10ef862c98bfb61c0600c33fe2703ae5388a 100644 --- a/parse-pinyin-test.cpp +++ b/parse-pinyin-test.cpp @@ -69,6 +69,32 @@ test_parse_pinyin_incomplete_pinyin() g_list_free_full(result, g_free); } +static void +test_parse_pinyin_yunmu_only_pinyin() +{ + GList *result = NULL; + Pinyin *thispy = NULL; + + result = parse_pinyin("a", 15, PINYIN_FLAGS_NONE); + print_parse_result(result); + g_assert_cmpint(g_list_length(result), ==, 1); + + thispy = (Pinyin *) g_list_nth_data(result, 0); + g_assert_cmpint(thispy->shengmu_i, ==, 0); + g_assert_cmpint(thispy->yunmu_i, ==, 24); + g_assert_cmpint(thispy->length, ==, 1); + + g_list_free_full(result, g_free); + + // flag doesn't affect pinyin parsing. + // flags are only effective when building the SQL. + result = parse_pinyin("an", 15, PINYIN_FUZZY_ALL); + print_parse_result(result); + g_assert_cmpint(g_list_length(result), ==, 1); + + g_list_free_full(result, g_free); +} + int main(int argc, char *argv[]) { @@ -77,6 +103,8 @@ main(int argc, char *argv[]) test_parse_pinyin); g_test_add_func("/zero/test_parse_pinyin incomplete pinyin", test_parse_pinyin_incomplete_pinyin); + g_test_add_func("/zero/test_parse_pinyin yunmu only pinyin", + test_parse_pinyin_yunmu_only_pinyin); return g_test_run(); } diff --git a/zero-pinyin-service.c b/zero-pinyin-service.c index 0bb24f32ef31ff0f7d083774122fc5503c2dd3ad..ecd5fc7c4f9e738d1e5f41c172677df07b5ecce7 100644 --- a/zero-pinyin-service.c +++ b/zero-pinyin-service.c @@ -52,14 +52,14 @@ build_where_clause(GList *pylist, for (guint i = 0; i < n; ++i) { g_assert_nonnull(iter); thispy = (Pinyin *) iter->data; - if (thispy->shengmu_i) { - if (G_LIKELY(first_condition_done)) { - g_string_append_printf(s, "AND s%u=%d ", i, thispy->shengmu_i); - } else { - g_string_append_printf(s, "s%u=%d ", i, thispy->shengmu_i); - first_condition_done = TRUE; - } + /* do not allow omit shengmu. always do strict match */ + if (G_LIKELY(first_condition_done)) { + g_string_append_printf(s, "AND s%u=%d ", i, thispy->shengmu_i); + } else { + g_string_append_printf(s, "s%u=%d ", i, thispy->shengmu_i); + first_condition_done = TRUE; } + /* allow omit yunmu, if 0 don't match on it */ if (thispy->yunmu_i) { if (G_LIKELY(first_condition_done)) { g_string_append_printf(s, "AND y%u=%d ", i, thispy->yunmu_i); @@ -310,18 +310,7 @@ get_candidates(sqlite3 *db, } GList *pylist = NULL; guint pylist_len = 0; - const guint FLAGS = (PINYIN_INCOMPLETE_PINYIN | - PINYIN_FUZZY_C_CH | - PINYIN_FUZZY_CH_C | - PINYIN_FUZZY_Z_ZH | - PINYIN_FUZZY_ZH_Z | - PINYIN_FUZZY_S_SH | - PINYIN_FUZZY_SH_S | - PINYIN_FUZZY_IN_ING | - PINYIN_FUZZY_ING_IN | - PINYIN_CORRECT_ALL); - - pylist = parse_pinyin(preedit_str, 15, FLAGS); + pylist = parse_pinyin(preedit_str, 15, PINYIN_FLAGS_NONE); pylist_len = g_list_length(pylist); guint group_size = pylist_len;