2011-12-20 13:44:45 +04:00
|
|
|
#include "lm/ngram_query.hh"
|
2010-09-10 04:36:07 +04:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2011-02-04 18:38:47 +03:00
|
|
|
if (!(argc == 2 || (argc == 3 && !strcmp(argv[2], "null")))) {
|
|
|
|
std::cerr << "Usage: " << argv[0] << " lm_file [null]" << std::endl;
|
|
|
|
std::cerr << "Input is wrapped in <s> and </s> unless null is passed." << std::endl;
|
|
|
|
return 1;
|
2010-09-10 04:36:07 +04:00
|
|
|
}
|
2011-11-17 23:12:19 +04:00
|
|
|
try {
|
|
|
|
bool sentence_context = (argc == 2);
|
|
|
|
lm::ngram::ModelType model_type;
|
|
|
|
if (lm::ngram::RecognizeBinary(argv[1], model_type)) {
|
|
|
|
switch(model_type) {
|
|
|
|
case lm::ngram::HASH_PROBING:
|
2011-12-20 13:44:45 +04:00
|
|
|
Query<lm::ngram::ProbingModel>(argv[1], sentence_context, std::cin, std::cout);
|
2011-11-17 23:12:19 +04:00
|
|
|
break;
|
|
|
|
case lm::ngram::TRIE_SORTED:
|
2011-12-20 13:44:45 +04:00
|
|
|
Query<lm::ngram::TrieModel>(argv[1], sentence_context, std::cin, std::cout);
|
2011-11-17 23:12:19 +04:00
|
|
|
break;
|
|
|
|
case lm::ngram::QUANT_TRIE_SORTED:
|
2011-12-20 13:44:45 +04:00
|
|
|
Query<lm::ngram::QuantTrieModel>(argv[1], sentence_context, std::cin, std::cout);
|
2011-11-17 23:12:19 +04:00
|
|
|
break;
|
|
|
|
case lm::ngram::ARRAY_TRIE_SORTED:
|
2011-12-20 13:44:45 +04:00
|
|
|
Query<lm::ngram::ArrayTrieModel>(argv[1], sentence_context, std::cin, std::cout);
|
2011-11-17 23:12:19 +04:00
|
|
|
break;
|
|
|
|
case lm::ngram::QUANT_ARRAY_TRIE_SORTED:
|
2011-12-20 13:44:45 +04:00
|
|
|
Query<lm::ngram::QuantArrayTrieModel>(argv[1], sentence_context, std::cin, std::cout);
|
2011-11-17 23:12:19 +04:00
|
|
|
break;
|
|
|
|
case lm::ngram::HASH_SORTED:
|
|
|
|
default:
|
|
|
|
std::cerr << "Unrecognized kenlm model type " << model_type << std::endl;
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
} else {
|
2011-12-20 13:44:45 +04:00
|
|
|
Query<lm::ngram::ProbingModel>(argv[1], sentence_context, std::cin, std::cout);
|
2011-01-25 22:11:48 +03:00
|
|
|
}
|
|
|
|
|
2011-11-17 23:12:19 +04:00
|
|
|
PrintUsage("Total time including destruction:\n");
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2011-02-04 18:38:47 +03:00
|
|
|
return 0;
|
2010-09-10 04:36:07 +04:00
|
|
|
}
|