translationoption.cpp.svn-base
来自「解码器是基于短语的统计机器翻译系统的核心模块」· SVN-BASE 代码 · 共 107 行
SVN-BASE
107 行
// $Id$// vim:tabstop=2/***********************************************************************Moses - factored phrase-based language decoderCopyright (C) 2006 University of EdinburghThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA***********************************************************************/#include "TranslationOption.h"#include "WordsBitmap.h"#include "PhraseDictionaryMemory.h"#include "GenerationDictionary.h"#include "LMList.h"#include "StaticData.h"using namespace std;//TODO this should be a factory function!TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetPhrase &targetPhrase) : m_targetPhrase(targetPhrase),m_sourcePhrase(targetPhrase.GetSourcePhrase()) ,m_sourceWordsRange (wordsRange){ // set score m_scoreBreakdown.PlusEquals(targetPhrase.GetScoreBreakdown());}//TODO this should be a factory function!TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetPhrase &targetPhrase, int /*whatever*/): m_targetPhrase(targetPhrase),m_sourceWordsRange (wordsRange),m_futureScore(0){}void TranslationOption::MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection& score, const std::vector<FactorType>& featuresToAdd){ assert(phrase.GetSize() == m_targetPhrase.GetSize()); if (featuresToAdd.size() == 1) { m_targetPhrase.MergeFactors(phrase, featuresToAdd[0]); } else if (featuresToAdd.empty()) { /* features already there, just update score */ } else { m_targetPhrase.MergeFactors(phrase, featuresToAdd); } m_scoreBreakdown.PlusEquals(score);}bool TranslationOption::IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const{ if (featuresToCheck.size() == 1) { return m_targetPhrase.IsCompatible(phrase, featuresToCheck[0]); } else if (featuresToCheck.empty()) { return true; /* features already there, just update score */ } else { return m_targetPhrase.IsCompatible(phrase, featuresToCheck); }}bool TranslationOption::Overlap(const Hypothesis &hypothesis) const{ const WordsBitmap &bitmap = hypothesis.GetWordsBitmap(); return bitmap.Overlap(GetSourceWordsRange());}void TranslationOption::CalcScore(){ // LM scores float m_ngramScore = 0; float retFullScore = 0; const LMList &allLM = StaticData::Instance()->GetAllLM(); allLM.CalcScore(GetTargetPhrase(), retFullScore, m_ngramScore, &m_scoreBreakdown); // future score m_futureScore = retFullScore - m_ngramScore; size_t phraseSize = GetTargetPhrase().GetSize(); m_futureScore += m_scoreBreakdown.InnerProduct(StaticData::Instance()->GetAllWeights()) - phraseSize * StaticData::Instance()->GetWeightWordPenalty();}TO_STRING_BODY(TranslationOption);// friendostream& operator<<(ostream& out, const TranslationOption& possibleTranslation){ out << possibleTranslation.GetTargetPhrase() << "c=" << possibleTranslation.GetFutureScore() << " [" << possibleTranslation.GetSourceWordsRange() << "]" << possibleTranslation.GetScoreBreakdown(); return out;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?