diff --git a/moses/src/LanguageModel_SRI.cpp b/moses/src/LanguageModel_SRI.cpp index cb8ed46e2..30346e340 100755 --- a/moses/src/LanguageModel_SRI.cpp +++ b/moses/src/LanguageModel_SRI.cpp @@ -103,10 +103,10 @@ LmId LanguageModel_SRI::GetLmID( const std::string &str ) const return res; } -float LanguageModel_SRI::GetValue(LmId wordId, VocabIndex *context) const +float LanguageModel_SRI::GetValue(VocabIndex wordId, VocabIndex *context) const { LanguageModel_SRI *lm = const_cast(this); // hack. not sure if supposed to cast this - float p = lm->m_srilmModel->wordProb( wordId.sri, context ); + float p = lm->m_srilmModel->wordProb( wordId, context ); return FloorSRIScore(TransformSRIScore(p)); // log10->log } @@ -114,16 +114,15 @@ float LanguageModel_SRI::GetValue(const vector &contextFactor) co { // set up context size_t count = contextFactor.size(); - VocabIndex *context = (VocabIndex*) malloc(count * sizeof(VocabIndex)); + VocabIndex context[MAX_NGRAM_SIZE]; for (size_t i = 0 ; i < count - 1 ; i++) { - context[i] = GetLmID(contextFactor[count-2-i]).sri; + context[i] = contextFactor[count-2-i]->GetLmId().sri; } context[count-1] = Vocab_None; // call sri lm fn - float ret = GetValue(GetLmID(contextFactor[count-1]->GetString()), context); - free(context); + float ret = GetValue(contextFactor[count-1]->GetLmId().sri, context); return ret; } diff --git a/moses/src/LanguageModel_SRI.h b/moses/src/LanguageModel_SRI.h index 32e9b1b30..f1a0acbd5 100755 --- a/moses/src/LanguageModel_SRI.h +++ b/moses/src/LanguageModel_SRI.h @@ -56,7 +56,7 @@ protected: Vocab *m_srilmVocab; // TODO - make this a ptr, remove #include from header Ngram *m_srilmModel; // " " - float GetValue(LmId wordId, VocabIndex *context) const; + float GetValue(VocabIndex wordId, VocabIndex *context) const; LmId GetLmID( const Factor *factor ) const { diff --git a/moses/src/TypeDef.h b/moses/src/TypeDef.h index ed88dcc71..ff7107109 100755 --- a/moses/src/TypeDef.h +++ b/moses/src/TypeDef.h @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #define UNKNOWN_FACTOR "UNK" #define NOT_FOUND std::numeric_limits::max() +#define MAX_NGRAM_SIZE 20 const size_t DEFAULT_MAX_HYPOSTACK_SIZE = 200; const size_t ARRAY_SIZE_INCR = 20; //amount by which a hypostack gets resized when necessary