00001 #include "PhraseBasedReorderingState.h"
00002
00003 namespace Moses
00004 {
00005
00006
00007
00008 bool PhraseBasedReorderingState::m_useFirstBackwardScore = true;
00009
00010 PhraseBasedReorderingState::
00011 PhraseBasedReorderingState(const PhraseBasedReorderingState *prev,
00012 const TranslationOption &topt)
00013 : LRState(prev, topt)
00014 , m_prevRange(topt.GetSourceWordsRange())
00015 , m_first(false)
00016 { }
00017
00018
00019 PhraseBasedReorderingState::
00020 PhraseBasedReorderingState(const LRModel &config,
00021 LRModel::Direction dir, size_t offset)
00022 : LRState(config, dir, offset)
00023 , m_prevRange(NOT_FOUND,NOT_FOUND)
00024 , m_first(true)
00025 { }
00026
00027
00028 size_t PhraseBasedReorderingState::hash() const
00029 {
00030 size_t ret;
00031 ret = hash_value(m_prevRange);
00032 boost::hash_combine(ret, m_direction);
00033
00034 return ret;
00035 }
00036
00037 bool PhraseBasedReorderingState::operator==(const FFState& o) const
00038 {
00039 if (&o == this) return true;
00040
00041 const PhraseBasedReorderingState &other = static_cast<const PhraseBasedReorderingState&>(o);
00042 if (m_prevRange == other.m_prevRange) {
00043 if (m_direction == LRModel::Forward) {
00044 int compareScore = ComparePrevScores(other.m_prevOption);
00045 return compareScore == 0;
00046 } else {
00047 return true;
00048 }
00049 } else {
00050 return false;
00051 }
00052 }
00053
00054 LRState*
00055 PhraseBasedReorderingState::
00056 Expand(const TranslationOption& topt, const InputType& input,
00057 ScoreComponentCollection* scores) const
00058 {
00059
00060
00061 if ((m_direction != LRModel::Forward && m_useFirstBackwardScore) || !m_first) {
00062 LRModel const& lrmodel = m_configuration;
00063 Range const cur = topt.GetSourceWordsRange();
00064 LRModel::ReorderingType reoType = (m_first ? lrmodel.GetOrientation(cur)
00065 : lrmodel.GetOrientation(m_prevRange,cur));
00066 CopyScores(scores, topt, input, reoType);
00067 }
00068 return new PhraseBasedReorderingState(this, topt);
00069 }
00070
00071 }
00072