1 /* ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¸Æ¤Ó½Ð¤·¤Î¥Æ¥¹¥È
3 * ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢test.txt¤«¤é1¹Ô¤º¤ÄÆɤ߹þ¤ó¤ÇÊÑ´¹¤ò¹Ô¤¦¡£
4 * ÊÑ´¹Á°¤Îʸ»úÎó¤ÈÊÑ´¹¤ò¹Ô¤Ã¤¿·ë²Ì¤òtest.exp¤«¤éõ¤·¡¢
5 * ÊÑ´¹·ë²Ì¤¬¹ç¤Ã¤Æ¤¤¤ë¤«¤ò¥«¥¦¥ó¥È¤·¤ÆºÇ¸å¤Ë½ÐÎϤ¹¤ë¡£
7 * ./anthy --from 1 --to 10 ¤Î¤è¤¦¤Ë¼Â¹Ô¤¹¤ë¤Ètest.txt¤ÎºÇ½é¤Î10¸Ä¤Î
8 * ¹Ô¤ÎÊÑ´¹¥Æ¥¹¥È¤¬¹Ô¤ï¤ì¤Þ¤¹¡£
10 * --ask¥ª¥×¥·¥ç¥ó¤òÉÕ¤±¤Æ¼Â¹Ô¤¹¤ë¤È¡¢·ë²Ì¤¬¹ç¤Ã¤Æ¤¤¤ë¤«¤ÎȽÃǤò
11 * ÀßÄꤹ¤ë¥â¡¼¥É¤Ë¤Ê¤ë¤Î¤Ç¡¢É½¼¨¤µ¤ì¤¿·ë²Ì¤ËÂФ¹¤ëȽÃǤò
12 * ɸ½àÆþÎϤ«¤é'y', 'n', 'd', 'q'¤ÇÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£
13 * 'd' dont care, 'q' quit
14 * ȽÃǤǤ¤Ê¤¤¾ì¹ç¤Ï¤½¤Î¾¤Îʸ»ú¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£
16 * Copyright (C) 2000-2006 TABATA Yusuke
17 * Copyright (C) 2004-2006 YOSHIDA Yuichi
18 * Copyright (C) 2001-2002 TAKAI Kosuke
27 #include <anthy/anthy.h>
28 #include <anthy/convdb.h>
31 /* Makefile ¤Î $(srcdir) (ÀÅŪ¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë¤Î´ð½à¥Ç¥£¥ì¥¯¥È¥ê) */
35 /* ¥Ó¥ë¥É»þ¤Î¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê (¤³¤³¤Ë .anthy ¤òºî¤ë) */
37 # define TEST_HOME "." /* FIXME: ¼ÂºÝ¤ÏÁêÂХѥ¹¤À¤È¸íÆ°ºî¤¹¤ë */
40 /* ¥Æ¥¹¥È¥Ç¡¼¥¿¤È¤Ê¤ëÊÑ´¹Á°¤Îʸ»úÎó */
41 #define TESTDATA "test.txt"
42 const char *testdata = SRCDIR "/" TESTDATA;
44 /* ÊÑ´¹¸å¤Îʸ»úÎó¤¬ÂÅÅö¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¤¿¤á¤Î¥Ç¡¼¥¿ */
45 #define EXPDATA "test.exp"
46 const char *expdata = SRCDIR "/" EXPDATA;
53 /* ¥Æ¥¹¥È¤ò¹Ô¤¦¾ò·ï */
55 /* conversion condition */
67 read_file(FILE *fp, struct input *in)
70 while(fgets(buf, 256, fp)) {
81 buf[strlen(buf)-1] = 0;
82 in->str = strdup(&buf[1]);
92 check_cond(struct condition *cond, struct input *in)
94 if (in->serial == cond->serial) {
97 if (in->serial <= cond->to && in->serial >= cond->from) {
104 log_print(int lv, const char *msg)
106 printf("log:%d:%s\n", lv, msg);
109 static anthy_context_t
110 init_lib(int use_utf8)
113 /* ´û¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤Î±Æ¶Á¤ò¼õ¤±¤Ê¤¤¤è¤¦¤Ë¤¹¤ë */
114 anthy_conf_override("CONFFILE", "../anthy-conf");
115 anthy_conf_override("HOME", TEST_HOME);
116 anthy_conf_override("DIC_FILE", "../mkanthydic/anthy.dic");
117 anthy_set_logger(log_print, 0);
119 printf("failed to init anthy\n");
122 anthy_set_personality("");
124 ac = anthy_create_context();
126 anthy_context_set_encoding(ac, ANTHY_UTF8_ENCODING);
128 anthy_context_set_encoding(ac, ANTHY_EUC_JP_ENCODING);
136 printf("Anthy "VERSION"\n"
137 "./anthy [test-id]\n"
140 " ./anthy --to 100\n"
141 " ./anthy --from 10 --to 100\n"
142 " ./anthy --all --print-miss-only --ask\n"
143 " ./anthy --ll 1\n\n");
148 parse_args(struct condition *cond, int argc, char **argv)
152 for (i = 1; i < argc; i++) {
154 if (!strncmp(arg, "--", 2)) {
156 if (!strcmp(arg, "help") || !strcmp(arg, "version")) {
159 if (!strcmp(arg, "all")) {
161 cond->to = 100000000;
162 } else if (!strcmp(arg, "quiet")) {
164 } else if (!strcmp(arg, "ask") ||
165 !strcmp(arg, "query")) {
167 } else if (!strcmp(arg, "print-miss-only")) {
169 } else if (!strcmp(arg, "utf8")) {
174 if (!strcmp(arg, "from")){
175 cond->from = atoi(argv[i+1]);
177 }else if (!strcmp(arg, "to")){
178 cond->to = atoi(argv[i+1]);
180 }else if (!strcmp(arg, "ll")) {
181 anthy_set_logger(NULL, atoi(argv[i+1]));
190 char *buf = alloca(strlen(SRCDIR)+strlen(arg) + 10);
191 sprintf(buf, SRCDIR "/%s.txt", arg);
192 testdata = strdup(buf);
203 env = getenv("ANTHY_ENABLE_DEBUG_PRINT");
207 printf("ANTHY_ENABLE_DEBUG_PRINT=(%s)\n", env);
208 env = getenv("ANTHY_SPLITTER_PRINT");
212 printf("ANTHY_SPLITTER_PRINT=(%s)\n", env);
213 printf("SRCDIR=(%s)\n", SRCDIR);
215 printf(PACKAGE "-" VERSION " %s", ctime(&t));
219 sum_up(struct res_db *db, struct conv_res *cr)
225 if (cr->res_str[0] == '|') {
232 if (cr->check == CHK_OK) {
234 } else if (cr->check == CHK_MISS) {
236 } else if (cr->check == CHK_DONTCARE) {
244 set_string(struct condition *cond, struct res_db *db,
245 struct input *in, anthy_context_t ac)
247 struct conv_res *cr1, *cr2;
250 anthy_set_string(ac, in->str);
253 cr1 = find_conv_res(db, ac, in->str, 1);
256 cr2 = find_conv_res(db, ac, in->str, 0);
261 if (cond->miss_only) {
262 if (cr1->check == CHK_MISS ||
263 cr2->check == CHK_MISS) {
266 } else if (!cond->quiet) {
271 printf("%d:(%s)\n", in->serial, in->str);
272 anthy_print_context(ac);
274 anthy_reset_context(ac);
279 dump_res(FILE *fp, struct conv_res *r)
281 fprintf(fp, "%s %s ", r->src_str, r->res_str);
282 if (r->check == CHK_MISS) {
284 } else if (r->check == CHK_OK) {
286 } else if (r->check == CHK_DONTCARE) {
295 save_db(const char *fn, struct res_db *db)
297 FILE *fp = fopen(fn, "w");
300 printf("failed to open (%s) to write\n", fn);
303 for (cr = db->res_list.next; cr; cr = cr->next) {
310 ask_results(struct res_db *db)
313 for (cr = db->res_list.next; cr; cr = cr->next) {
314 if (cr->check == CHK_UNKNOWN && cr->used == 1) {
316 printf("%s -> %s (y/n/d/q)\n", cr->src_str, cr->res_str);
317 fgets(buf, 256, stdin);
320 } else if (buf[0] == 'n') {
321 cr->check = CHK_MISS;
322 } else if (buf[0] == 'd') {
323 cr->check = CHK_DONTCARE;
324 } else if (buf[0] == 'q') {
332 show_stat(struct res_db *db)
337 printf("%d items\n", db->total);
338 for (i = 0; i < 2; i++) {
340 printf("conversion result\n");
343 printf("split result\n");
346 printf("ok : %d\n", rs->ok);
347 printf("miss : %d\n", rs->miss);
348 printf("unknown : %d\n", rs->unknown);
354 init_condition(struct condition *cond)
367 main(int argc,char **argv)
371 struct input cur_input;
373 struct condition cond;
375 cur_input.serial = 0;
377 init_condition(&cond);
379 parse_args(&cond, argc, argv);
381 read_db(db, expdata);
383 printf("./test_anthy --help to print usage.\n");
387 fp = fopen(testdata, "r");
389 printf("failed to open %s.\n", testdata);
393 ac = init_lib(cond.use_utf8);
395 /* ¥Õ¥¡¥¤¥ë¤òÆɤó¤Ç¤¤¤¯¥ë¡¼¥× */
396 while (!read_file(fp, &cur_input)) {
397 if (check_cond(&cond, &cur_input)) {
398 set_string(&cond, db, &cur_input, ac);
402 anthy_release_context(ac);
411 save_db(expdata, db);