00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "TranslationOption.h"
00024 #include "WordsBitmap.h"
00025 #include "GenerationDictionary.h"
00026 #include "LexicalReordering.h"
00027 #include "StaticData.h"
00028 #include "InputType.h"
00029
00030 using namespace std;
00031
00032 namespace Moses
00033 {
00034
00035
00036 TranslationOption::TranslationOption(const WordsRange &wordsRange
00037 , const TargetPhrase &targetPhrase)
00038 : m_targetPhrase(targetPhrase)
00039 , m_sourceWordsRange(wordsRange)
00040 , m_futureScore(targetPhrase.GetFutureScore())
00041 {
00042 }
00043
00044 TranslationOption::TranslationOption(const TranslationOption ©, const WordsRange &sourceWordsRange)
00045 : m_targetPhrase(copy.m_targetPhrase)
00046
00047 , m_sourceWordsRange(sourceWordsRange)
00048 , m_futureScore(copy.m_futureScore)
00049 , m_lexReorderingScores(copy.m_lexReorderingScores)
00050 {}
00051
00052 bool TranslationOption::IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const
00053 {
00054 if (featuresToCheck.size() == 1) {
00055 return m_targetPhrase.IsCompatible(phrase, featuresToCheck[0]);
00056 } else if (featuresToCheck.empty()) {
00057 return true;
00058
00059 } else {
00060 return m_targetPhrase.IsCompatible(phrase, featuresToCheck);
00061 }
00062 }
00063
00064 bool TranslationOption::Overlap(const Hypothesis &hypothesis) const
00065 {
00066 const WordsBitmap &bitmap = hypothesis.GetWordsBitmap();
00067 return bitmap.Overlap(GetSourceWordsRange());
00068 }
00069
00070 void TranslationOption::CacheLexReorderingScores(const LexicalReordering &producer, const Scores &score)
00071 {
00072 m_lexReorderingScores[&producer] = score;
00073 }
00074
00075 void TranslationOption::Evaluate(const InputType &source)
00076 {
00077 m_targetPhrase.Evaluate(source);
00078 }
00079
00080 TO_STRING_BODY(TranslationOption);
00081
00082
00083 ostream& operator<<(ostream& out, const TranslationOption& possibleTranslation)
00084 {
00085 out << possibleTranslation.GetTargetPhrase()
00086 << " c=" << possibleTranslation.GetFutureScore()
00087 << " [" << possibleTranslation.GetSourceWordsRange() << "]"
00088 << possibleTranslation.GetScoreBreakdown();
00089 return out;
00090 }
00091
00092
00093 }
00094
00095