00001 // $Id$ 00002 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2006 University of Edinburgh 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 ***********************************************************************/ 00021 00022 #ifndef moses_TranslationOption_h 00023 #define moses_TranslationOption_h 00024 00025 #include <map> 00026 #include <vector> 00027 #include <boost/functional/hash.hpp> 00028 #include "WordsBitmap.h" 00029 #include "WordsRange.h" 00030 #include "Phrase.h" 00031 #include "TargetPhrase.h" 00032 #include "Hypothesis.h" 00033 #include "Util.h" 00034 #include "TypeDef.h" 00035 #include "ScoreComponentCollection.h" 00036 #include "StaticData.h" 00037 00038 namespace Moses 00039 { 00040 00041 class PhraseDictionary; 00042 class GenerationDictionary; 00043 class FeatureFunction; 00044 class LexicalReordering; 00045 00046 00062 class TranslationOption 00063 { 00064 friend std::ostream& operator<<(std::ostream& out, const TranslationOption& possibleTranslation); 00065 00066 protected: 00067 00068 TargetPhrase m_targetPhrase; /*< output phrase when using this translation option */ 00069 const WordsRange m_sourceWordsRange; /*< word position in the input that are covered by this translation option */ 00070 float m_futureScore; /*< estimate of total cost when using this translation option, includes language model probabilities */ 00071 00072 typedef std::map<const LexicalReordering*, Scores> _ScoreCacheMap; 00073 _ScoreCacheMap m_lexReorderingScores; 00074 00075 public: 00077 TranslationOption(const WordsRange &wordsRange 00078 , const TargetPhrase &targetPhrase); 00079 00081 TranslationOption(const TranslationOption ©, const WordsRange &sourceWordsRange); 00082 00083 00085 bool IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const; 00086 00088 inline const TargetPhrase &GetTargetPhrase() const { 00089 return m_targetPhrase; 00090 } 00091 00093 inline const WordsRange &GetSourceWordsRange() const { 00094 return m_sourceWordsRange; 00095 } 00096 00098 const Phrase *GetSourcePhrase() const { 00099 return &(m_targetPhrase.GetSourcePhrase()); 00100 } 00101 00103 bool Overlap(const Hypothesis &hypothesis) const; 00104 00106 inline size_t GetStartPos() const { 00107 return m_sourceWordsRange.GetStartPos(); 00108 } 00109 00111 inline size_t GetEndPos() const { 00112 return m_sourceWordsRange.GetEndPos(); 00113 } 00114 00116 inline size_t GetSize() const { 00117 return m_sourceWordsRange.GetEndPos() - m_sourceWordsRange.GetStartPos() + 1; 00118 } 00119 00121 inline float GetFutureScore() const { 00122 return m_futureScore; 00123 } 00124 00126 inline bool IsDeletionOption() const { 00127 return m_targetPhrase.GetSize() == 0; 00128 } 00129 00131 inline const ScoreComponentCollection &GetScoreBreakdown() const { 00132 return m_targetPhrase.GetScoreBreakdown(); 00133 } 00134 00136 inline const Scores *GetLexReorderingScores(const LexicalReordering *scoreProducer) const { 00137 _ScoreCacheMap::const_iterator it = m_lexReorderingScores.find(scoreProducer); 00138 if(it == m_lexReorderingScores.end()) 00139 return NULL; 00140 else 00141 return &(it->second); 00142 } 00143 00144 void CacheLexReorderingScores(const LexicalReordering &scoreProducer, const Scores &score); 00145 00146 TO_STRING(); 00147 00148 bool operator== (const TranslationOption &rhs) const 00149 { 00150 return m_sourceWordsRange == rhs.m_sourceWordsRange && 00151 m_targetPhrase == rhs.m_targetPhrase; 00152 } 00153 00154 }; 00155 00156 00157 //XXX: This doesn't look at the alignment. Is this correct? 00158 inline size_t hash_value(const TranslationOption& translationOption) { 00159 size_t seed = 0; 00160 boost::hash_combine(seed, translationOption.GetTargetPhrase()); 00161 boost::hash_combine(seed, translationOption.GetStartPos()); 00162 boost::hash_combine(seed, translationOption.GetEndPos()); 00163 return seed; 00164 } 00165 00166 00167 } 00168 00169 #endif 00170 00171
1.5.9