void run_tests(ngram_model_t *model) { int32 n_used; ngram_tg_score(model, ngram_wid(model, "daines"), ngram_wid(model, "huggins"), ngram_wid(model, "huggins"), &n_used); TEST_EQUAL(n_used, 2); ngram_tg_score(model, ngram_wid(model, "david"), ngram_wid(model, "david"), ngram_wid(model, "david"), &n_used); TEST_EQUAL(n_used, 1); /* Apply weights. */ ngram_model_apply_weights(model, 7.5, 0.5, 1.0); /* -9452 * 7.5 + log(0.5) = -77821 */ TEST_EQUAL_LOG(ngram_score(model, "daines", "huggins", "david", NULL), -77821); /* Recover original score. */ TEST_EQUAL_LOG(ngram_probv(model, "daines", "huggins", "david", NULL), -9452); TEST_EQUAL_LOG(ngram_probv(model, "huggins", "david", NULL), -831); /* Un-apply weights. */ ngram_model_apply_weights(model, 1.0, 1.0, 1.0); TEST_EQUAL_LOG(ngram_score(model, "daines", "huggins", "david", NULL), -9452); TEST_EQUAL_LOG(ngram_score(model, "huggins", "david", NULL), -831); /* Recover original score. */ TEST_EQUAL_LOG(ngram_probv(model, "daines", "huggins", "david", NULL), -9452); /* Pre-weighting, this should give the "raw" score. */ TEST_EQUAL_LOG(ngram_score(model, "daines", "huggins", "david", NULL), -9452); TEST_EQUAL_LOG(ngram_score(model, "huggins", "david", NULL), -831); /* Verify that backoff mode calculations work. */ ngram_bg_score(model, ngram_wid(model, "huggins"), ngram_wid(model, "david"), &n_used); TEST_EQUAL(n_used, 2); ngram_bg_score(model, ngram_wid(model, "blorglehurfle"), ngram_wid(model, "david"), &n_used); TEST_EQUAL(n_used, 1); ngram_bg_score(model, ngram_wid(model, "david"), ngram_wid(model, "david"), &n_used); TEST_EQUAL(n_used, 1); ngram_tg_score(model, ngram_wid(model, "daines"), ngram_wid(model, "huggins"), ngram_wid(model, "david"), &n_used); TEST_EQUAL(n_used, 3); }
static int test_lm_vals(ngram_model_t *model) { int32 n_used; TEST_ASSERT(model); TEST_EQUAL(ngram_wid(model, "<UNK>"), 0); TEST_EQUAL(strcmp(ngram_word(model, 0), "<UNK>"), 0); TEST_EQUAL(ngram_wid(model, "absolute"), 13); TEST_EQUAL(strcmp(ngram_word(model, 13), "absolute"), 0); /* Test unigrams. */ TEST_EQUAL(ngram_score(model, "<UNK>", NULL), -75346); TEST_EQUAL(ngram_bg_score(model, ngram_wid(model, "<UNK>"), NGRAM_INVALID_WID, &n_used), -75346); TEST_EQUAL(n_used, 1); TEST_EQUAL(ngram_score(model, "sphinxtrain", NULL), -64208); TEST_EQUAL(ngram_bg_score(model, ngram_wid(model, "sphinxtrain"), NGRAM_INVALID_WID, &n_used), -64208); TEST_EQUAL(n_used, 1); /* Test bigrams. */ TEST_EQUAL(ngram_score(model, "huggins", "david", NULL), -831); /* Test trigrams. */ TEST_EQUAL_LOG(ngram_score(model, "daines", "huggins", "david", NULL), -9450); return 0; }