(linenum→info "unix/slp.c:2238")

anthy/9100e/test/prediction.c

    1: #include <stdlib.h>
    2: #include <stdio.h>
    3: #include <anthy/anthy.h>
    4: 
    5: 
    6: /* Makefile $B$N(B $(srcdir) ($B@EE*%G!<%?%U%!%$%k$N4p=`%G%#%l%/%H%j(B) */
    7: #ifndef SRCDIR
    8: # define SRCDIR "."
    9: #endif
   10: 
   11: static void
   12: init_lib(void)
   13: {
   14:   /* $B4{$K%$%s%9%H!<%k$5$l$F$$$k%U%!%$%k$N1F6A$r<u$1$J$$$h$&$K$9$k(B */
   15:   anthy_conf_override("CONFFILE", "../anthy-conf");
   16:   anthy_conf_override("DEPWORD", "master.depword");
   17:   anthy_conf_override("DEPGRAPH", "../depgraph/anthy.dep");
   18:   anthy_conf_override("DIC_FILE", "../mkanthydic/anthy.dic");
   19:   anthy_conf_override("ANTHYDIR", SRCDIR "/../depgraph");
   20:   if (anthy_init()) {
   21:     printf("failed to init anthy\n");
   22:     exit(0);
   23:   }
   24: }
   25: 
   26: 
   27: int main(int argc, char** argv)
   28: {
   29:   struct anthy_prediction_stat ps;
   30:   anthy_context_t ac;
   31:   int i;
   32: 
   33:   if (argc == 1) {
   34:     return 0;
   35:   }
   36:   init_lib();
   37:   ac = anthy_create_context();
   38: 
   39:   anthy_set_prediction_string(ac, argv[1]);
   40:   anthy_get_prediction_stat(ac, &ps);
   41:   for (i = 0; i < ps.nr_prediction; ++i) {
   42:     char* buf;
   43:     int len;
   44:     len = anthy_get_prediction(ac, i, NULL, 0);
   45:     buf = malloc(sizeof(char) * (len + 1));
   46:     len = anthy_get_prediction(ac, i, buf, len + 1);
   47:     printf("%s, %d\n", buf, len);
   48:     free(buf);
   49:   }
   50:   anthy_commit_prediction(ac, 0);
   51: 
   52:   anthy_release_context(ac);
   53: 
   54:   anthy_quit();
   55: 
   56:   return 0;
   57: }
Syntax (Markdown)