File: test_alignment.c

package info (click to toggle)
pocketsphinx 0.8%2B5prealpha-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,276 kB
  • ctags: 2,161
  • sloc: ansic: 22,812; sh: 11,451; python: 599; makefile: 393; perl: 301
file content (56 lines) | stat: -rw-r--r-- 1,720 bytes parent folder | download
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 <pocketsphinx.h>

#include "ps_alignment.h"
#include "pocketsphinx_internal.h"

#include "test_macros.h"

int
main(int argc, char *argv[])
{
	bin_mdef_t *mdef;
	dict_t *dict;
	dict2pid_t *d2p;
	ps_alignment_t *al;
	ps_alignment_iter_t *itor;
	cmd_ln_t *config;

	config = cmd_ln_init(NULL, NULL, FALSE,
			     "-dict", MODELDIR "/en-us/cmudict-en-us.dict",
			     "-fdict", MODELDIR "/en-us/en-us/noisedict",
			     NULL);
	mdef = bin_mdef_read(NULL, MODELDIR "/en-us/en-us/mdef");
	dict = dict_init(config, mdef);
	d2p = dict2pid_build(mdef, dict);

	al = ps_alignment_init(d2p);
	TEST_EQUAL(1, ps_alignment_add_word(al, dict_wordid(dict, "<s>"), 0));
	TEST_EQUAL(2, ps_alignment_add_word(al, dict_wordid(dict, "hello"), 0));
	TEST_EQUAL(3, ps_alignment_add_word(al, dict_wordid(dict, "world"), 0));
	TEST_EQUAL(4, ps_alignment_add_word(al, dict_wordid(dict, "</s>"), 0));
	TEST_EQUAL(0, ps_alignment_populate(al));

	itor = ps_alignment_words(al);
	TEST_EQUAL(ps_alignment_iter_get(itor)->id.wid, dict_wordid(dict, "<s>"));
	itor = ps_alignment_iter_next(itor);
	TEST_EQUAL(ps_alignment_iter_get(itor)->id.wid, dict_wordid(dict, "hello"));
	itor = ps_alignment_iter_next(itor);
	TEST_EQUAL(ps_alignment_iter_get(itor)->id.wid, dict_wordid(dict, "world"));
	itor = ps_alignment_iter_next(itor);
	TEST_EQUAL(ps_alignment_iter_get(itor)->id.wid, dict_wordid(dict, "</s>"));
	itor = ps_alignment_iter_next(itor);
	TEST_EQUAL(itor, NULL);

	printf("%d words %d phones %d states\n",
	       ps_alignment_n_words(al),
	       ps_alignment_n_phones(al),
	       ps_alignment_n_states(al));

	ps_alignment_free(al);
	dict_free(dict);
	dict2pid_free(d2p);
	bin_mdef_free(mdef);
	cmd_ln_free_r(config);

	return 0;
}