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 "Bitmap.h"
00025 #include "GenerationDictionary.h"
00026 #include "StaticData.h"
00027 #include "InputType.h"
00028 #include "moses/FF/LexicalReordering/LexicalReordering.h"
00029
00030 using namespace std;
00031
00032 namespace Moses
00033 {
00034
00035 TranslationOption::TranslationOption()
00036 :m_targetPhrase(NULL)
00037 ,m_inputPath(NULL)
00038 ,m_sourceWordsRange(NOT_FOUND, NOT_FOUND)
00039 { }
00040
00041
00042 TranslationOption::TranslationOption(const Range &range
00043 , const TargetPhrase &targetPhrase)
00044 : m_targetPhrase(targetPhrase)
00045 , m_inputPath(NULL)
00046 , m_sourceWordsRange(range)
00047 , m_futureScore(targetPhrase.GetFutureScore())
00048 {
00049 }
00050
00051 bool TranslationOption::IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const
00052 {
00053 if (featuresToCheck.size() == 1) {
00054 return m_targetPhrase.IsCompatible(phrase, featuresToCheck[0]);
00055 } else if (featuresToCheck.empty()) {
00056 return true;
00057
00058 } else {
00059 return m_targetPhrase.IsCompatible(phrase, featuresToCheck);
00060 }
00061 }
00062
00063 bool TranslationOption::Overlap(const Hypothesis &hypothesis) const
00064 {
00065 const Bitmap &bitmap = hypothesis.GetWordsBitmap();
00066 return bitmap.Overlap(GetSourceWordsRange());
00067 }
00068
00069 void
00070 TranslationOption::
00071 CacheLexReorderingScores(const LexicalReordering &producer, const Scores &score)
00072 {
00073 if (score.empty()) return;
00074 boost::shared_ptr<Scores> stored(new Scores(score));
00075 m_targetPhrase.SetExtraScores(&producer,stored);
00076
00077 }
00078
00079 void TranslationOption::EvaluateWithSourceContext(const InputType &input)
00080 {
00081 const InputPath &inputPath = GetInputPath();
00082 m_targetPhrase.EvaluateWithSourceContext(input, inputPath);
00083 }
00084
00085 const InputPath &TranslationOption::GetInputPath() const
00086 {
00087 UTIL_THROW_IF2(m_inputPath == NULL,
00088 "No input path");
00089 return *m_inputPath;
00090 }
00091
00092 void TranslationOption::SetInputPath(const InputPath &inputPath)
00093 {
00094 UTIL_THROW_IF2(m_inputPath,
00095 "Input path already specified");
00096 m_inputPath = &inputPath;
00097 }
00098
00099
00100 TO_STRING_BODY(TranslationOption);
00101
00102
00103 ostream& operator<<(ostream& out, const TranslationOption& possibleTranslation)
00104 {
00105 out << possibleTranslation.GetTargetPhrase()
00106 << " c=" << possibleTranslation.GetFutureScore()
00107 << " [" << possibleTranslation.GetSourceWordsRange() << "]"
00108 << possibleTranslation.GetScoreBreakdown();
00109 return out;
00110 }
00111
00113 const Scores*
00114 TranslationOption::
00115 GetLexReorderingScores(LexicalReordering const* scoreProducer) const
00116 {
00117 return m_targetPhrase.GetExtraScores(scoreProducer);
00118
00119
00120
00121
00122
00123
00124 }
00125
00126 }
00127
00128