File size: 1,764 Bytes
5610573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
#include <pocketsphinx.h>
#include <stdio.h>
#include <string.h>
#include "util/ckd_alloc.h"

#include "test_macros.h"

int
main(int argc, char *argv[])
{
	ps_decoder_t *ps;
	ps_config_t *config;
        char *pron;

	(void)argc;
	(void)argv;
	TEST_ASSERT(config =
                    ps_config_parse_json(
                        NULL, "hmm: \"" DATADIR "/tidigits/hmm\","
                        "dict: \"" DATADIR "/tidigits/lm/tidigits.dic\""));
	TEST_ASSERT(ps = ps_init(config));
	ps_config_free(config);

	TEST_ASSERT(config =
                    ps_config_parse_json(
                        NULL, "hmm: \"" MODELDIR "/en-us/en-us\","
                        "dict: \"" MODELDIR "/en-us/cmudict-en-us.dict\""));
	TEST_EQUAL(0, ps_reinit(ps, config));

	/* Reinit when adding words */
	ps_add_word(ps, "foobie", "F UW B IY", FALSE);
	ps_add_word(ps, "hellosomething", "HH EH L OW S", TRUE);

        /* Reinit features only, words should remain */
        ps_config_set_str(config, "cmninit", "41,-4,1");
	TEST_EQUAL(0, ps_reinit_feat(ps, config));
        TEST_EQUAL(0, strcmp(ps_config_str(ps_get_config(ps), "cmninit"),
                             "41,-4,1"));
        pron = ps_lookup_word(ps, "foobie");
        TEST_ASSERT(pron != NULL);
        TEST_EQUAL(0, strcmp(pron, "F UW B IY"));
        ckd_free(pron);

	/* Reinit with existing config */
	ps_reinit(ps, NULL);
        /* Words added above are gone, we expect that. */
        pron = ps_lookup_word(ps, "foobie");
        TEST_ASSERT(pron == NULL);
        /* Hooray! -cmninit isn't in feat.params anymore, so yes! */
        TEST_EQUAL(0, strcmp(ps_config_str(ps_get_config(ps), "cmninit"),
                                "41,-4,1"));

	ps_free(ps);
	ps_config_free(config);

	return 0;
}