예제 #1
0
void
test_create_with_long_path(void)
{
    gssize max_size = PATH_MAX - 6;
    GString *long_path;
    const gchar last_component[] = G_DIR_SEPARATOR_S "index";

    long_path = grn_long_path_new(path, max_size - strlen(last_component) - 1);
    g_free(path);

    g_mkdir_with_parents(long_path->str, 0700);
    g_string_append(long_path, last_component);
    path = g_string_free(long_path, FALSE);

    cut_assert_equal_int(max_size, strlen(path) + 1);
    cut_assert_create();

    inverted_index_free();

    long_path = g_string_new(path);
    g_free(path);

    g_string_append(long_path, "X");
    path = g_string_free(long_path, FALSE);

    inverted_index = grn_ii_create(context, path, lexicon, 0);
    cut_assert_null(inverted_index);
}
예제 #2
0
void
cut_teardown(void)
{
    if (context) {
        inverted_index_free();
        if (path)
            grn_ii_remove(context, path);
        grn_ctx_fin(context);
        g_free(context);
    }

    /*
      if (vgram)
        grn_vgram_close(vgram);
    */

    if (path) {
        g_free(path);
        path = NULL;
    }

    remove_tmp_directory();

    record_ids_free();

    expected_messages_free();

    teardown_grn_logger(logger);
}
예제 #3
0
void
test_open_with_null_lexicon(void)
{
    cut_assert_create();
    inverted_index_free();

    inverted_index = grn_ii_open(context, path, NULL);
    cut_assert_null(inverted_index);
}
예제 #4
0
void
test_open(void)
{
    cut_assert_create();
    inverted_index_free();

    inverted_index = grn_ii_open(context, path, lexicon);
    cut_assert(inverted_index);
}
예제 #5
0
파일: test_index.c 프로젝트: luojiada/SDR
int main(int argc, char** argv)
{
    int i;
    int rv;
    FILE* fh;
    char const *hyp, *uttid;
    int32 score;
    ps_decoder_t *ps;
	cmd_ln_t *config;
    ps_lattice_t* dag;

    config = cmd_ln_init(NULL, ps_args(), TRUE,
			     "-hmm", "./hmm/zh_broadcastnews_ptm256_8000",
			     "-lm", "./lm/syllables.lm.DMP",
			     "-dict", "./lm/syllables_sorted.dic",
			     NULL);
	if (config == NULL)
		return 1;
	ps = ps_init(config);
	if (ps == NULL)
		return 1;
   
	fh = fopen(argv[1], "rb");
	if (fh == NULL) {
		perror("Failed to open audio file.");
		return 1;
	}

	rv = ps_decode_raw(ps, fh, "test", -1);
	if (rv < 0)
		return 1;

	hyp = ps_get_hyp(ps, &score, &uttid);
	if (hyp == NULL)
		return 1;
	printf("Recognized: %s\n", hyp);
	inverted_index_t* index = inverted_index_init("./syllable.lst");
    if (index == NULL) {
       exit(1);
    }

	dag = ps_get_lattice(ps);
	if (dag == NULL) {
	    perror("No lattice");
	    return 1;
	}

    /*
    printf("# Total number of words: %d\n", index->n_word);
    for(i = 0; i < index->n_word; i++) {
        printf("%3d: %s\n", i+1, index->word_list[i]);
    }*/
    float32 ascale = cmd_ln_float32_r(config, "-ascale");
    printf("ascale: %f\n", ascale);
    //printf("%d: %s\n", inverted_index_get_wid(index, "ba"), "ba");
    //printf("%d: %s\n", inverted_index_get_wid(index, "bia"), "bia");
    inverted_index_addhits(index, "test", dag, 1.0/ascale);
    inverted_index_write(index, "./index");
    inverted_index_free(index);
    index = inverted_index_read("./index");
    inverted_index_write(index, "./index2");
    
    char* query[] = {"jin", "tian", "jie", "mu"};
    result_list_t* rl;
    inverted_index_search(index, ps_get_lmset(ps), 1.0/ascale, query, 4, &rl);

	inverted_index_free(index);
	return 0;
}