Commit f0977ae0 authored by Yuanle Song's avatar Yuanle Song

make flags param explicit in parse_pinyin()

parent e7afac3c
* COMMENT -*- mode: org -*-
#+Date: 2019-04-05
Time-stamp: <2019-04-05>
Time-stamp: <2019-04-17>
#+STARTUP: content
* notes :entry:
** 2019-04-05 zero-pinyin-service file structure :doc:
......@@ -42,5 +42,9 @@ Time-stamp: <2019-04-05>
* later :entry:
* current :entry:
**
** 2019-04-17 make flags configurable at runtime.
- add dbus method to set flags.
- make the method work. use gobject property maybe.
- set default flags to my flags. reflect this in UI/config file.
* done :entry:
* wontfix :entry:
......@@ -9,7 +9,7 @@ test_parse_pinyin()
GList *result = NULL;
Pinyin *thispy = NULL;
result = parse_pinyin("liyifeng", 15);
result = parse_pinyin("liyifeng", 15, PINYIN_FLAGS_NONE);
g_assert_cmpint(g_list_length(result), ==, 3);
thispy = (Pinyin *) g_list_nth_data(result, 0);
......@@ -52,7 +52,7 @@ test_parse_pinyin_incomplete_pinyin()
GList *result = NULL;
Pinyin *thispy = NULL;
result = parse_pinyin("zhey", 15);
result = parse_pinyin("zhey", 15, PINYIN_INCOMPLETE_PINYIN);
print_parse_result(result);
g_assert_cmpint(g_list_length(result), ==, 2);
......
......@@ -4,13 +4,14 @@
#include "../Const.h"
GList *
parse_pinyin(const char *preedit_str, const guint max_pinyin)
parse_pinyin(const char *preedit_str, const guint max_pinyin, const guint flags)
{
GList *result = NULL;
PyZy::PinyinArray pyar = {0};
Pinyin *thispy = NULL;
const guint FLAGS = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL | PINYIN_FUZZY_ALL;
PyZy::PinyinParser::parse(preedit_str, strlen(preedit_str), FLAGS, pyar, max_pinyin);
PyZy::PinyinParser::parse(preedit_str, strlen(preedit_str), flags,
pyar, max_pinyin);
for (guint i = 0; i < pyar.size(); ++i) {
thispy = g_new(Pinyin, 1);
thispy->shengmu_i = (int) pyar[i].pinyin->pinyin_id[0].sheng;
......
......@@ -3,20 +3,26 @@
#include <glib.h>
#include "zero-pinyin-service.h"
#include "../Const.h"
#ifdef __cplusplus
extern "C"
{
#endif
G_BEGIN_DECLS
#define PINYIN_FLAGS_NONE 0
/**
* parse preedit_str to groups of pinyin.
* caller should free each Pinyin and the GList after use.
*
* @preedit_str: the preedit str
* @max_pinyin: parse at most this many pinyin from preedit str.
* @flags: support incomplete pinyin, fuzzy pinyin, correction, see ../Const.h
*
* Returns: a list of Pinyin struct. caller should free each Pinyin and the
* GList after use.
*/
GList *parse_pinyin(const char *preedit_str, const guint max_pinyin);
GList *parse_pinyin(const char *preedit_str,
const guint max_pinyin,
const guint flags);
#ifdef __cplusplus
}
#endif
G_END_DECLS
#endif /* _PARSE_PINYIN_H_ */
......@@ -310,8 +310,18 @@ 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);
pylist = parse_pinyin(preedit_str, 15, FLAGS);
pylist_len = g_list_length(pylist);
guint group_size = pylist_len;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment