#ifndef _ZERO_PINYIN_SERVICE_H_ #define _ZERO_PINYIN_SERVICE_H_ #include #include #include G_BEGIN_DECLS #define ZERO_PINYIN_WELL_KNOWN_NAME "com.emacsos.zero.ZeroPinyinService1" #define ZERO_PINYIN_OBJECT_PATH "/com/emacsos/zero/ZeroPinyinService1" #define ZERO_PINYIN_INTERFACE_NAME "com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface" static const guint FUZZY_FLAG_NONE = 0; static const guint FUZZY_FLAG_ZCS_ZHCHSH = 1; static const guint FUZZY_FLAG_L_N = 2; /* Note: next flag should be 4, always use a new bit for flag. */ typedef struct { gint shengmu_i; gint yunmu_i; guint length; } Pinyin; typedef struct { gchar *str; /* the candidate string */ guint freq; /* word frequency [0, 65535] */ guint user_freq; /* user frequency [0, 65535] */ guint matched_py_length; /* matched preedit_str length */ guint char_len; /* candidate Chinese character length */ Pinyin **py_indices; /* Pinyin for each character in this candidate */ } Candidate; /** * an implementation of get_candidates() with simple test data. */ void get_candidates_test(const char *preedit_str, const guint fetch_size, GVariantBuilder *candidates_builder, GVariantBuilder *matched_lengths_builder); /** * fetch candidates for preedit_str. * * @preedit_str the preedit_str * @fetch_size try to fetch this many candidates if possible * @candidates_builder candidates will be added to this builder * @matched_lengths_builder matched preedit_str length will be added to this builder */ void get_candidates(sqlite3 *db, const char *preedit_str, const guint fetch_size, const guint fuzzy_flag, GVariantBuilder *candidates_builder, GVariantBuilder *matched_lengths_builder, GVariantBuilder *candidates_pinyin_indices); /** * commit candidate. * * This will save candidate in user db so it's available in the future. * It also update user_freq for given candidate. */ void commit_candidate(sqlite3 *db, const gchar *candidate, GVariant *candidate_pinyin_indices); /* for test only */ char *build_s_y_fields(const guint n); G_END_DECLS #endif /* _ZERO_PINYIN_SERVICE_H_ */