1 #include <ngram_model.h>
5 #include "test_macros.h"
12 run_tests(ngram_model_t *model)
17 ngram_wid(model, "daines"),
18 ngram_wid(model, "huggins"),
19 ngram_wid(model, "huggins"), &n_used);
20 TEST_EQUAL(n_used, 2);
22 ngram_wid(model, "david"),
23 ngram_wid(model, "david"),
24 ngram_wid(model, "david"), &n_used);
25 TEST_EQUAL(n_used, 1);
28 ngram_model_apply_weights(model, 7.5, 0.5, 1.0);
29 /* -9452 * 7.5 + log(0.5) = -77821 */
30 TEST_EQUAL_LOG(ngram_score(model, "daines", "huggins", "david", NULL),
32 /* Recover original score. */
33 TEST_EQUAL_LOG(ngram_prob(model, "daines", "huggins", "david", NULL),
35 TEST_EQUAL_LOG(ngram_prob(model, "huggins", "david", NULL), -831);
37 /* Un-apply weights. */
38 ngram_model_apply_weights(model, 1.0, 1.0, 1.0);
39 TEST_EQUAL_LOG(ngram_score(model, "daines", "huggins", "david", NULL),
41 TEST_EQUAL_LOG(ngram_score(model, "huggins", "david", NULL), -831);
42 /* Recover original score. */
43 TEST_EQUAL_LOG(ngram_prob(model, "daines", "huggins", "david", NULL),
46 /* Pre-weighting, this should give the "raw" score. */
47 TEST_EQUAL_LOG(ngram_score(model, "daines", "huggins", "david", NULL),
49 TEST_EQUAL_LOG(ngram_score(model, "huggins", "david", NULL), -831);
50 /* Verify that backoff mode calculations work. */
52 ngram_wid(model, "huggins"),
53 ngram_wid(model, "david"), &n_used);
54 TEST_EQUAL(n_used, 2);
56 ngram_wid(model, "blorglehurfle"),
57 ngram_wid(model, "david"), &n_used);
58 TEST_EQUAL(n_used, 1);
60 ngram_wid(model, "david"),
61 ngram_wid(model, "david"), &n_used);
62 TEST_EQUAL(n_used, 1);
64 ngram_wid(model, "daines"),
65 ngram_wid(model, "huggins"),
66 ngram_wid(model, "david"), &n_used);
67 TEST_EQUAL(n_used, 3);
71 main(int argc, char *argv[])
76 lmath = logmath_init(1.0001, 0, 0);
78 model = ngram_model_read(NULL, LMDIR "/100.arpa.DMP", NGRAM_DMP, lmath);
80 ngram_model_free(model);
82 model = ngram_model_read(NULL, LMDIR "/100.arpa.gz", NGRAM_ARPA, lmath);
84 ngram_model_free(model);