diff options
| author | Kenneth Heafield <github@kheafield.com> | 2012-10-14 10:46:34 +0100 | 
|---|---|---|
| committer | Kenneth Heafield <github@kheafield.com> | 2012-10-14 10:46:34 +0100 | 
| commit | f568b392f82fd94b788a1b38094855234d318205 (patch) | |
| tree | 37c09a6c2a006afd719e04009b0908117960354a /klm/lm | |
| parent | b7005385f267596436dd07b1a9e798023ef1c30a (diff) | |
Update to faster but less cute search
Diffstat (limited to 'klm/lm')
| -rw-r--r-- | klm/lm/fragment.cc | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/klm/lm/fragment.cc b/klm/lm/fragment.cc new file mode 100644 index 00000000..0267cd4e --- /dev/null +++ b/klm/lm/fragment.cc @@ -0,0 +1,37 @@ +#include "lm/binary_format.hh" +#include "lm/model.hh" +#include "lm/left.hh" +#include "util/tokenize_piece.hh" + +template <class Model> void Query(const char *name) { +  Model model(name); +  std::string line; +  lm::ngram::ChartState ignored; +  while (getline(std::cin, line)) { +    lm::ngram::RuleScore<Model> scorer(model, ignored); +    for (util::TokenIter<util::SingleCharacter, true> i(line, ' '); i; ++i) { +      scorer.Terminal(model.GetVocabulary().Index(*i)); +    } +    std::cout << scorer.Finish() << '\n'; +  } +} + +int main(int argc, char *argv[]) { +  if (argc != 2) { +    std::cerr << "Expected model file name." << std::endl; +    return 1; +  } +  const char *name = argv[1]; +  lm::ngram::ModelType model_type = lm::ngram::PROBING; +  lm::ngram::RecognizeBinary(name, model_type); +  switch (model_type) { +    case lm::ngram::PROBING: +      Query<lm::ngram::ProbingModel>(name); +      break; +    case lm::ngram::REST_PROBING: +      Query<lm::ngram::RestProbingModel>(name); +      break; +    default: +      std::cerr << "Model type not supported yet." << std::endl; +  } +} | 
