/* cc libkkc-test.c -I/usr/local/include/ -I/usr/local/include/glib-2.0 \ -I/usr/local/lib/glib-2.0/include -I/usr/local/include/json-glib-1.0 \ -I/usr/local/include/gee-0.8 -L/usr/local/lib -lkkc -Wall */ #include #include #include int main(int argc, char *argv[]) { KkcLanguageModel *model; KkcDecoder *decoder; KkcSegment **segment, *s; gint nbest, *constraint, constraint_length, result_length; gint i; if (argc < 2) { printf("SENTENCE [N-BEST [SEGMENT-BOUNDARY ... ]]\n"); return 0; } kkc_init(); model = kkc_language_model_load("sorted3", NULL); if (model == NULL) { printf("language model error\n"); return 0; } // XXX call kkc_system_segment_dictionary_new() to // add user dictionary (SKK-JISYO.L) ?? decoder = kkc_decoder_create(model); if (decoder == NULL) { printf("decoder create error\n"); return 0; } constraint_length = (argc >= 4) ? (argc - 3) : 0; constraint = alloca(sizeof(gint) * constraint_length); for (i = 0; i < constraint_length; i++) constraint[i] = atoi(argv[3 + i]); nbest = (argc >= 3) ? atoi(argv[2]) : 1; segment = kkc_decoder_decode(decoder, argv[1] /* input */, nbest, constraint, constraint_length, &result_length); for (i = 0; i < result_length; i++) { printf("%d: ", i); s = segment[i]; while (s != NULL) { printf("<%s/%s>", kkc_segment_get_output(s), kkc_segment_get_input(s)); s = s->next; } printf("\n"); } return 0; }