scorer.h 896 字节
Newer Older
Y
Yibing Liu 已提交
1 2 3 4 5
#ifndef SCORER_H_
#define SCORER_H_

#include <string>

6 7 8
/* External scorer to evaluate a prefix or a complete sentence
 * when a new word appended during decoding, consisting of word
 * count and language model scoring.
Y
Yibing Liu 已提交
9

10
 * Example:
11
 *     LmScorer ext_scorer(alpha, beta, "path_to_language_model.klm");
12 13
 *     double score = ext_scorer.get_score("sentence_to_score");
 */
14
class LmScorer{
Y
Yibing Liu 已提交
15 16 17 18 19
private:
    float _alpha;
    float _beta;
    void *_language_model;

20 21 22 23 24
    // word insertion term
    int word_count(std::string);
    // n-gram language model scoring
    double language_model_score(std::string);

Y
Yibing Liu 已提交
25
public:
26 27 28
    LmScorer(){}
    LmScorer(float alpha, float beta, std::string lm_model_path);
    ~LmScorer();
29 30 31 32

    // reset params alpha & beta
    void reset_params(float alpha, float beta);
    // get the final score
33
    double get_score(std::string, bool log=false);
Y
Yibing Liu 已提交
34 35
};

36
#endif //SCORER_H_