00001 #include "lm/binary_format.hh" 00002 #include "lm/model.hh" 00003 #include "lm/left.hh" 00004 #include "util/tokenize_piece.hh" 00005 00006 template <class Model> void Query(const char *name) { 00007 Model model(name); 00008 std::string line; 00009 lm::ngram::ChartState ignored; 00010 while (getline(std::cin, line)) { 00011 lm::ngram::RuleScore<Model> scorer(model, ignored); 00012 for (util::TokenIter<util::SingleCharacter, true> i(line, ' '); i; ++i) { 00013 scorer.Terminal(model.GetVocabulary().Index(*i)); 00014 } 00015 std::cout << scorer.Finish() << '\n'; 00016 } 00017 } 00018 00019 int main(int argc, char *argv[]) { 00020 if (argc != 2) { 00021 std::cerr << "Expected model file name." << std::endl; 00022 return 1; 00023 } 00024 const char *name = argv[1]; 00025 lm::ngram::ModelType model_type = lm::ngram::PROBING; 00026 lm::ngram::RecognizeBinary(name, model_type); 00027 switch (model_type) { 00028 case lm::ngram::PROBING: 00029 Query<lm::ngram::ProbingModel>(name); 00030 break; 00031 case lm::ngram::REST_PROBING: 00032 Query<lm::ngram::RestProbingModel>(name); 00033 break; 00034 default: 00035 std::cerr << "Model type not supported yet." << std::endl; 00036 } 00037 }