1 /*
2 * libpinyin
3 * Library to deal with pinyin.
4 *
5 * Copyright (C) 2017 Peng Wu <alexepico@gmail.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "zhuyin.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
main(int argc,char * argv[])31 int main(int argc, char * argv[]){
32 zhuyin_context_t * context =
33 zhuyin_init("../data", "../data");
34
35 zhuyin_instance_t * instance = zhuyin_alloc_instance(context);
36
37 char* linebuf = NULL;
38 size_t size = 0;
39 ssize_t read;
40 while( (read = getline(&linebuf, &size, stdin)) != -1 ){
41 if ( '\n' == linebuf[strlen(linebuf) - 1] ) {
42 linebuf[strlen(linebuf) - 1] = '\0';
43 }
44
45 if ( strcmp ( linebuf, "quit" ) == 0)
46 break;
47
48 zhuyin_parse_more_chewings
49 (instance, linebuf);
50 zhuyin_guess_sentence(instance);
51
52 char * sentence = NULL;
53 zhuyin_get_sentence (instance, &sentence);
54 if (sentence)
55 printf("%s\n", sentence);
56 g_free(sentence);
57
58 zhuyin_train(instance);
59 zhuyin_reset(instance);
60 zhuyin_save(context);
61 }
62
63 zhuyin_free_instance(instance);
64
65 zhuyin_mask_out(context, 0x0, 0x0);
66 zhuyin_save(context);
67 zhuyin_fini(context);
68
69 free(linebuf);
70 return 0;
71 }
72