Skip to content

Commit

Permalink
for release
Browse files Browse the repository at this point in the history
git-svn-id: https://ilk.uvt.nl/svn/trunk/sources/pbmbmt/releases/0.34@6623 12f355fe-0486-481a-ad91-c297ab22b4e3
  • Loading branch information
proycon committed Oct 25, 2010
1 parent 48a4d1f commit 1026441
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions srilm.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <string>

#include <boost/python.hpp>
using namespace boost::python;

#include "srilm/include/File.h"
#include "srilm/include/Ngram.h"
#include "srilm/include/Vocab.h"
//#include <NgramStats.h>
#include "srilm/lm/src/NgramStatsLong.cc"

class LanguageModel
{
private:
Vocab vocab;
Ngram model;

public:
LanguageModel(const std::string& filename, int order) : model(vocab, order)
{
File file(filename.c_str(), "r");
model.read(file);
}

LogP wordProb(const std::string& context1, const std::string& context2, const std::string& word)
{
const VocabIndex context[] = {
context2 == "__" ? Vocab_None : vocab.getIndex(context2.c_str()),
context1 == "__" ? Vocab_None : vocab.getIndex(context1.c_str())
};

return model.wordProb(vocab.getIndex(word.c_str()), context);
}
};


BOOST_PYTHON_MODULE(srilm)
{
class_<LanguageModel, boost::noncopyable>("LanguageModel", init<const std::string&, int>())
.def("wordProb", &LanguageModel::wordProb)
;
}

0 comments on commit 1026441

Please sign in to comment.