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 std::vector<TranslationOption*> m_linkedTransOpts;
00070
00075 ScoreComponentCollection m_scoreBreakdown;
00076
00077 typedef std::map<const ScoreProducer *, const Scores *> _ScoreCacheMap;
00078 _ScoreCacheMap m_cachedScores;
00079
00080 public:
00082 TranslationOption(const WordsRange &wordsRange
00083 , const TargetPhrase &targetPhrase
00084 , const InputType &inputType);
00086 TranslationOption(const WordsRange &wordsRange
00087 , const TargetPhrase &targetPhrase
00088 , const InputType &inputType
00089 , const UnknownWordPenaltyProducer* uwpProducer);
00091 TranslationOption(const TranslationOption ©);
00092
00094 TranslationOption(const TranslationOption ©, const WordsRange &sourceWordsRange);
00095
00096 ~TranslationOption()
00097 {
00098 delete m_sourcePhrase;
00099 for(_ScoreCacheMap::const_iterator it = m_cachedScores.begin(); it != m_cachedScores.end(); ++it)
00100 delete it->second;
00101 }
00102
00104 bool IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const;
00105
00107 void MergeNewFeatures(const Phrase& phrase, const ScoreComponentCollection& score, const std::vector<FactorType>& featuresToMerge);
00108
00110 inline const TargetPhrase &GetTargetPhrase() const
00111 {
00112 return m_targetPhrase;
00113 }
00114
00116 inline const WordsRange &GetSourceWordsRange() const
00117 {
00118 return m_sourceWordsRange;
00119 }
00120
00122 const Phrase *GetSourcePhrase() const
00123 {
00124 return m_sourcePhrase;
00125 }
00126
00128 inline const std::vector<TranslationOption*> &GetLinkedTransOpts() const
00129 {
00130 return m_linkedTransOpts;
00131 }
00132
00134 inline void AddLinkedTransOpt(TranslationOption* to)
00135 {
00136 m_linkedTransOpts.push_back(to);
00137 }
00138
00140 bool Overlap(const Hypothesis &hypothesis) const;
00141
00143 inline size_t GetStartPos() const
00144 {
00145 return m_sourceWordsRange.GetStartPos();
00146 }
00147
00149 inline size_t GetEndPos() const
00150 {
00151 return m_sourceWordsRange.GetEndPos();
00152 }
00153
00155 inline size_t GetSize() const
00156 {
00157 return m_sourceWordsRange.GetEndPos() - m_sourceWordsRange.GetStartPos() + 1;
00158 }
00159
00161 inline float GetFutureScore() const
00162 {
00163 return m_futureScore;
00164 }
00165
00167 inline bool IsDeletionOption() const
00168 {
00169 return m_targetPhrase.GetSize() == 0;
00170 }
00171
00173 inline const ScoreComponentCollection &GetScoreBreakdown() const
00174 {
00175 return m_scoreBreakdown;
00176 }
00177
00179 inline const Scores *GetCachedScores(const ScoreProducer *scoreProducer) const
00180 {
00181 _ScoreCacheMap::const_iterator it = m_cachedScores.find(scoreProducer);
00182 if(it == m_cachedScores.end())
00183 return NULL;
00184 else
00185 return it->second;
00186 }
00187
00189 void CalcScore(const TranslationSystem* system);
00190
00191 void CacheScores(const ScoreProducer &scoreProducer, const Scores &score);
00192
00193 TO_STRING();
00194 };
00195
00196 }
00197
00198 #endif
00199
00200