-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://ilk.uvt.nl/svn/trunk/sources/pbmbmt/releases/0.34@6623 12f355fe-0486-481a-ad91-c297ab22b4e3
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
; | ||
} |