Skip to content
zero-pinyin-service.h 2.13 KiB
Newer Older
Yuanle Song's avatar
Yuanle Song committed
#ifndef _ZERO_PINYIN_SERVICE_H_
#define _ZERO_PINYIN_SERVICE_H_

#include <glib.h>
#include <string.h>
Yuanle Song's avatar
Yuanle Song committed

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"
Yuanle Song's avatar
Yuanle Song committed

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. */

Yuanle Song's avatar
Yuanle Song committed
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 */
Yuanle Song's avatar
Yuanle Song committed
} Candidate;

/**
 * an implementation of get_candidates() with simple test data.
 */
Yuanle Song's avatar
Yuanle Song committed
void get_candidates_test(const char *preedit_str,
			 const guint fetch_size,
			 GVariantBuilder *candidates_builder,
			 GVariantBuilder *matched_lengths_builder);
Yuanle Song's avatar
Yuanle Song committed

/**
 * 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
Yuanle Song's avatar
Yuanle Song committed
 */
Yuanle Song's avatar
Yuanle Song committed
void get_candidates(sqlite3 *db,
		    const char *preedit_str,
		    const guint fetch_size,
		    const guint fuzzy_flag,
Yuanle Song's avatar
Yuanle Song committed
		    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.
 */
Yuanle Song's avatar
Yuanle Song committed
void commit_candidate(sqlite3 *db,
		      const gchar *candidate,
		      GVariant *candidate_pinyin_indices);

/* for test only */
Yuanle Song's avatar
Yuanle Song committed
char *build_s_y_fields(const guint n);
Yuanle Song's avatar
Yuanle Song committed

Yuanle Song's avatar
Yuanle Song committed

#endif /* _ZERO_PINYIN_SERVICE_H_ */