linux上的输入法确实是个问题. 通过libpinyin库则实现拼音到文字的转换.
-
#include <pinyin.h>
-
#include <stdio.h>
-
-
int main()
-
{
-
char input[64];
-
pinyin_context_t * context = pinyin_init (SYSTEM_CONF, ""); //SYSTEM_CONF编译时指定的变量
-
-
if (context == NULL)
-
{
-
printf("Context not allocted...\n");
-
return 1;
-
}
-
-
pinyin_instance_t * instance = pinyin_alloc_instance (context);
-
-
if (instance == NULL)
-
{
-
printf("Instance not allocted...\n");
-
return 1;
-
}
-
-
printf("Please input pinyin:\n");
-
-
scanf("%s", input);
-
-
pinyin_parse_more_full_pinyins (instance, input);
-
-
pinyin_guess_sentence (instance);
-
-
guint number;
-
-
pinyin_guess_candidates(instance, 0, {});
-
-
pinyin_get_n_candidate (instance, &number);
-
-
printf ("%s has %d candidates\n", input, number);
-
-
for (guint i = 0; i < 5 && i < number; ++i)
-
{
-
lookup_candidate_t * candidate;
-
pinyin_get_candidate(instance, i, &candidate);
-
-
const gchar *display_string;
-
pinyin_get_candidate_string(instance, candidate, &display_string);
-
printf("%s\t", display_string);
-
}
-
printf("\n");
-
-
pinyin_free_instance (instance);
-
-
pinyin_fini (context);
-
-
return 0;
-
}
-
-
-
CFLAGS := --std=c++11 $(shell pkg-config --cflags libpinyin)
-
LIBS := $(shell pkg-config --libs libpinyin)
-
DATADIR := $(shell pkg-config --variable=pkgdatadir libpinyin)
-
-
test_pinyin_parse_functions.out: test_pinyin_parse_functions.c
-
g++ -D SYSTEM_CONF=\"$(DATADIR)/data\" $(CFLAGS) $(LIBS) test_pinyin_parse_functions.c -o test_pinyin_parse_functions.out
OK, 现在是不是可以用某个 UI component 制作自己的汉字输入法了.
阅读(1409) | 评论(0) | 转发(0) |