File: prediction.c

package info (click to toggle)
anthy 1%3A0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,632 kB
  • sloc: ansic: 24,445; sh: 4,186; lisp: 1,265; makefile: 238
file content (56 lines) | stat: -rw-r--r-- 1,267 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdlib.h>
#include <stdio.h>
#include <anthy/anthy.h>


/* Makefile の $(srcdir) (静的データファイルの基準ディレクトリ) */
#ifndef SRCDIR
# define SRCDIR "."
#endif

static void
init_lib(void)
{
  /* 既にインストールされているファイルの影響を受けないようにする */
  anthy_conf_override("CONFFILE", "../anthy-conf");
  anthy_conf_override("DEPGRAPH", "../depgraph/anthy.dep");
  anthy_conf_override("DIC_FILE", "../mkanthydic/anthy.dic");
  anthy_conf_override("ANTHYDIR", SRCDIR "/../depgraph");
  if (anthy_init()) {
    printf("failed to init anthy\n");
    exit(0);
  }
}


int main(int argc, char** argv)
{
  struct anthy_prediction_stat ps;
  anthy_context_t ac;
  int i;

  if (argc == 1) {
    return 0;
  }
  init_lib();
  ac = anthy_create_context();

  anthy_set_prediction_string(ac, argv[1]);
  anthy_get_prediction_stat(ac, &ps);
  for (i = 0; i < ps.nr_prediction; ++i) {
    char* buf;
    int len;
    len = anthy_get_prediction(ac, i, NULL, 0);
    buf = malloc(sizeof(char) * (len + 1));
    len = anthy_get_prediction(ac, i, buf, len + 1);
    printf("%s, %d\n", buf, len);
    free(buf);
  }
  anthy_commit_prediction(ac, 0);

  anthy_release_context(ac);

  anthy_quit();

  return 0;
}