00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef moses_TranslationOption_h
00023 #define moses_TranslationOption_h
00024
00025 #include <map>
00026 #include <vector>
00027 #include "WordsBitmap.h"
00028 #include "WordsRange.h"
00029 #include "Phrase.h"
00030 #include "TargetPhrase.h"
00031 #include "Hypothesis.h"
00032 #include "Util.h"
00033 #include "TypeDef.h"
00034 #include "ScoreComponentCollection.h"
00035 #include "StaticData.h"
00036
00037 namespace Moses
00038 {
00039
00040 class PhraseDictionary;
00041 class GenerationDictionary;
00042 class LexicalReordering;
00043
00059 class TranslationOption
00060 {
00061 friend std::ostream& operator<<(std::ostream& out, const TranslationOption& possibleTranslation);
00062
00063 protected:
00064
00065 TargetPhrase m_targetPhrase;
00066 Phrase *m_sourcePhrase;
00067 const WordsRange m_sourceWordsRange;
00068 float m_futureScore;
00069
00074 ScoreComponentCollection m_scoreBreakdown;
00075
00076 typedef std::map<const ScoreProducer *, const Scores *> _ScoreCacheMap;
00077 _ScoreCacheMap m_cachedScores;
00078
00079 public:
00081 TranslationOption(const WordsRange &wordsRange
00082 , const TargetPhrase &targetPhrase
00083 , const InputType &inputType);
00085 TranslationOption(const WordsRange &wordsRange
00086 , const TargetPhrase &targetPhrase
00087 , const InputType &inputType
00088 , const UnknownWordPenaltyProducer* uwpProducer);
00090 TranslationOption(const TranslationOption ©);
00091
00093 TranslationOption(const TranslationOption ©, const WordsRange &sourceWordsRange);
00094
00095 ~TranslationOption() {
00096 delete m_sourcePhrase;
00097 for(_ScoreCacheMap::const_iterator it = m_cachedScores.begin(); it != m_cachedScores.end(); ++it)
00098 delete it->second;
00099 }
00100
00102 bool IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const;
00103
00105 void MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection& score, const std::vector<FactorType>& featuresToMerge);
00106
00108 inline const TargetPhrase &GetTargetPhrase() const {
00109 return m_targetPhrase;
00110 }
00111
00113 inline const WordsRange &GetSourceWordsRange() const {
00114 return m_sourceWordsRange;
00115 }
00116
00118 const Phrase *GetSourcePhrase() const {
00119 return m_sourcePhrase;
00120 }
00121
00123 bool Overlap(const Hypothesis &hypothesis) const;
00124
00126 inline size_t GetStartPos() const {
00127 return m_sourceWordsRange.GetStartPos();
00128 }
00129
00131 inline size_t GetEndPos() const {
00132 return m_sourceWordsRange.GetEndPos();
00133 }
00134
00136 inline size_t GetSize() const {
00137 return m_sourceWordsRange.GetEndPos() - m_sourceWordsRange.GetStartPos() + 1;
00138 }
00139
00141 inline float GetFutureScore() const {
00142 return m_futureScore;
00143 }
00144
00146 inline bool IsDeletionOption() const {
00147 return m_targetPhrase.GetSize() == 0;
00148 }
00149
00151 inline const ScoreComponentCollection &GetScoreBreakdown() const {
00152 return m_scoreBreakdown;
00153 }
00154
00156 inline const Scores *GetCachedScores(const ScoreProducer *scoreProducer) const {
00157 _ScoreCacheMap::const_iterator it = m_cachedScores.find(scoreProducer);
00158 if(it == m_cachedScores.end())
00159 return NULL;
00160 else
00161 return it->second;
00162 }
00163
00165 void CalcScore(const TranslationSystem* system);
00166
00167 void CacheScores(const ScoreProducer &scoreProducer, const Scores &score);
00168
00169 TO_STRING();
00170 };
00171
00172 }
00173
00174 #endif
00175
00176