00001 #include "VWState.h"
00002
00003 #include "moses/FF/FFState.h"
00004 #include "moses/Phrase.h"
00005 #include "moses/Hypothesis.h"
00006 #include "moses/Util.h"
00007 #include "moses/TypeDef.h"
00008 #include "moses/StaticData.h"
00009 #include "moses/TranslationOption.h"
00010 #include <boost/functional/hash.hpp>
00011
00012 namespace Moses
00013 {
00014
00015 VWState::VWState() : m_spanStart(0), m_spanEnd(0)
00016 {
00017 ComputeHash();
00018 }
00019
00020 VWState::VWState(const Phrase &phrase)
00021 : m_phrase(phrase), m_spanStart(0), m_spanEnd(0)
00022 {
00023 ComputeHash();
00024 }
00025
00026 VWState::VWState(const VWState &prevState, const Hypothesis &curHypo)
00027 {
00028 VERBOSE(3, "VW :: updating state\n>> previous state: " << prevState << "\n");
00029
00030
00031 Phrase phrase = prevState.GetPhrase();
00032 size_t contextSize = phrase.GetSize();
00033
00034
00035 phrase.Append(curHypo.GetCurrTargetPhrase());
00036
00037 VERBOSE(3, ">> current hypo: " << curHypo.GetCurrTargetPhrase() << "\n");
00038
00039
00040 Range range(phrase.GetSize() - contextSize, phrase.GetSize() - 1);
00041 m_phrase = phrase.GetSubString(range);
00042
00043
00044 m_spanStart = curHypo.GetTranslationOption().GetStartPos();
00045 m_spanEnd = curHypo.GetTranslationOption().GetEndPos();
00046
00047
00048 ComputeHash();
00049
00050 VERBOSE(3, ">> updated state: " << *this << "\n");
00051 }
00052
00053 bool VWState::operator==(const FFState& o) const
00054 {
00055 const VWState &other = static_cast<const VWState &>(o);
00056
00057 return m_phrase == other.GetPhrase()
00058 && m_spanStart == other.GetSpanStart()
00059 && m_spanEnd == other.GetSpanEnd();
00060 }
00061
00062 void VWState::ComputeHash()
00063 {
00064 m_hash = 0;
00065
00066 boost::hash_combine(m_hash, m_phrase);
00067 boost::hash_combine(m_hash, m_spanStart);
00068 boost::hash_combine(m_hash, m_spanEnd);
00069 }
00070
00071 std::ostream &operator<<(std::ostream &out, const VWState &state)
00072 {
00073 out << state.GetPhrase() << "::" << state.GetSpanStart() << "-" << state.GetSpanEnd();
00074 return out;
00075 }
00076
00077 }