summaryrefslogtreecommitdiff
path: root/klm/lm/fragment_main.cc
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2013-03-03 12:06:43 +0100
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2013-03-03 12:06:43 +0100
commitf7f9048f8e4d34682f17bfd050d238005feb3ee3 (patch)
treefa20fa16b0f5a8009a9254622b65ebeaec049399 /klm/lm/fragment_main.cc
parent9d306b30c9abba995ba35243e5cb461bb472a61f (diff)
parent12f2eab0e7dc7167af47cddf8ef88968656277da (diff)
Merge branch 'master' of github.com:pks/cdec-dtrain
Diffstat (limited to 'klm/lm/fragment_main.cc')
-rw-r--r--klm/lm/fragment_main.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/klm/lm/fragment_main.cc b/klm/lm/fragment_main.cc
new file mode 100644
index 00000000..0267cd4e
--- /dev/null
+++ b/klm/lm/fragment_main.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;
+ }
+}