00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <set>
00022
00023 #include "StaticData.h"
00024 #include "LMList.h"
00025 #include "Phrase.h"
00026 #include "ScoreComponentCollection.h"
00027
00028 using namespace std;
00029
00030 namespace Moses
00031 {
00032 LMList::~LMList()
00033 {
00034 }
00035
00036 void LMList::CleanUp()
00037 {
00038 RemoveAllInColl(m_coll);
00039 }
00040
00041 void LMList::CalcScore(const Phrase &phrase, float &retFullScore, float &retNGramScore, float &retOOVScore, ScoreComponentCollection* breakdown) const
00042 {
00043 const_iterator lmIter;
00044 for (lmIter = begin(); lmIter != end(); ++lmIter) {
00045 const LanguageModel &lm = **lmIter;
00046 const float weightLM = lm.GetWeight();
00047 const float oovWeightLM = lm.GetOOVWeight();
00048
00049 float fullScore, nGramScore;
00050 size_t oovCount;
00051
00052
00053 if (!lm.Useable(phrase))
00054 continue;
00055
00056 lm.CalcScore(phrase, fullScore, nGramScore, oovCount);
00057
00058 if (StaticData::Instance().GetLMEnableOOVFeature()) {
00059 vector<float> scores(2);
00060 scores[0] = nGramScore;
00061 scores[1] = oovCount;
00062 breakdown->Assign(&lm, scores);
00063 retOOVScore += oovCount * oovWeightLM;
00064 } else {
00065 breakdown->Assign(&lm, nGramScore);
00066 }
00067
00068
00069 retFullScore += fullScore * weightLM;
00070 retNGramScore += nGramScore * weightLM;
00071 }
00072 }
00073
00074 void LMList::Add(LanguageModel *lm)
00075 {
00076 m_coll.push_back(lm);
00077
00078 const ScoreIndexManager &scoreMgr = StaticData::Instance().GetScoreIndexManager();
00079 size_t startInd = scoreMgr.GetBeginIndex(lm->GetScoreBookkeepingID())
00080 ,endInd = scoreMgr.GetEndIndex(lm->GetScoreBookkeepingID()) - 1;
00081
00082 m_minInd = min(m_minInd, startInd);
00083 m_maxInd = max(m_maxInd, endInd);
00084 }
00085
00086 }
00087