-
Notifications
You must be signed in to change notification settings - Fork 3
/
lmheap-test.c
41 lines (40 loc) · 998 Bytes
/
lmheap-test.c
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
#include <stdio.h>
#include "dlib.h"
#include "heap.h"
#include "ngram.h"
#include "lm.h"
int main(int argc, char **argv) {
msg("Loading model file %s", argv[1]);
LM lm = lm_init(argv[1]);
msg("==> Enter ngram:");
forline (buf, NULL) {
Ngram ng = ngram_from_string(buf);
for (int i = ngram_size(ng); i > 0; i--) {
Token ng_i = ng[i];
ng[i] = NULLTOKEN;
Heap p = lm_pheap(lm, ng, 1, ngram_size(ng));
if (p != NULL) {
msg("logP[%d]:", i);
for (int j = 1; j <= heap_size(p); j++) {
msg("%g\t%s", p[j].logp, token_to_string(p[j].token));
}
}
p = lm_bheap(lm, ng, 1, ngram_size(ng));
if (p != NULL) {
msg("logB[%d]:", i);
for (int j = 1; j <= heap_size(p); j++) {
msg("%g\t%s", p[j].logp, token_to_string(p[j].token));
}
}
ng[i] = ng_i;
}
msg("==> Enter ngram:");
}
msg("Destroying LM");
lm_free(lm);
msg("Freeing tmp space");
dfreeall();
msg("Freeing symtable");
symtable_free();
msg("done");
}