|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#include <vector> |
|
#include <boost/scoped_ptr.hpp> |
|
#include "Util.h" |
|
#include "Range.h" |
|
#include "ScoreComponentCollection.h" |
|
#include "Phrase.h" |
|
#include "ChartTranslationOptions.h" |
|
#include "ObjectPool.h" |
|
|
|
namespace Moses |
|
{ |
|
|
|
class ChartKBestExtractor; |
|
class ChartHypothesis; |
|
class ChartManager; |
|
class RuleCubeItem; |
|
class FFState; |
|
|
|
typedef std::vector<ChartHypothesis*> ChartArcList; |
|
|
|
|
|
|
|
|
|
class ChartHypothesis |
|
{ |
|
friend std::ostream& operator<<(std::ostream&, const ChartHypothesis&); |
|
|
|
|
|
protected: |
|
|
|
boost::shared_ptr<ChartTranslationOption> m_transOpt; |
|
|
|
Range m_currSourceWordsRange; |
|
std::vector<const FFState*> m_ffStates; |
|
|
|
mutable boost::scoped_ptr<ScoreComponentCollection> m_scoreBreakdown; |
|
mutable boost::scoped_ptr<ScoreComponentCollection> m_deltaScoreBreakdown; |
|
ScoreComponentCollection m_currScoreBreakdown |
|
,m_lmNGram |
|
,m_lmPrefix; |
|
float m_totalScore; |
|
|
|
ChartArcList *m_arcList; |
|
const ChartHypothesis *m_winningHypo; |
|
|
|
std::vector<const ChartHypothesis*> m_prevHypos; |
|
|
|
ChartManager& m_manager; |
|
|
|
unsigned m_id; |
|
|
|
|
|
ChartHypothesis(); |
|
|
|
|
|
ChartHypothesis(const ChartHypothesis ©); |
|
|
|
public: |
|
ChartHypothesis(const ChartTranslationOptions &, const RuleCubeItem &item, |
|
ChartManager &manager); |
|
|
|
|
|
ChartHypothesis(const ChartHypothesis &, const ChartKBestExtractor &); |
|
|
|
~ChartHypothesis(); |
|
|
|
unsigned GetId() const { |
|
return m_id; |
|
} |
|
|
|
const ChartTranslationOption &GetTranslationOption() const { |
|
return *m_transOpt; |
|
} |
|
|
|
|
|
const TargetPhrase &GetCurrTargetPhrase() const { |
|
return m_transOpt->GetPhrase(); |
|
} |
|
|
|
|
|
const Range &GetCurrSourceRange() const { |
|
return m_currSourceWordsRange; |
|
} |
|
|
|
|
|
inline const ChartArcList* GetArcList() const { |
|
return m_arcList; |
|
} |
|
|
|
|
|
inline const FFState* GetFFState( size_t featureID ) const { |
|
return m_ffStates[ featureID ]; |
|
} |
|
|
|
|
|
inline const ChartManager& GetManager() const { |
|
return m_manager; |
|
} |
|
|
|
void GetOutputPhrase(Phrase &outPhrase) const; |
|
Phrase GetOutputPhrase() const; |
|
|
|
|
|
|
|
void GetOutputPhrase(size_t leftRightMost, size_t numWords, Phrase &outPhrase) const; |
|
|
|
void EvaluateWhenApplied(); |
|
|
|
void AddArc(ChartHypothesis *loserHypo); |
|
void CleanupArcList(); |
|
void SetWinningHypo(const ChartHypothesis *hypo); |
|
|
|
|
|
const ScoreComponentCollection &GetScoreBreakdown() const { |
|
|
|
if (!m_scoreBreakdown.get()) { |
|
m_scoreBreakdown.reset(new ScoreComponentCollection()); |
|
|
|
if (m_transOpt) { |
|
m_scoreBreakdown->PlusEquals(GetTranslationOption().GetScores()); |
|
} |
|
m_scoreBreakdown->PlusEquals(m_currScoreBreakdown); |
|
|
|
for (std::vector<const ChartHypothesis*>::const_iterator iter = m_prevHypos.begin(); iter != m_prevHypos.end(); ++iter) { |
|
const ChartHypothesis &prevHypo = **iter; |
|
m_scoreBreakdown->PlusEquals(prevHypo.GetScoreBreakdown()); |
|
} |
|
} |
|
return *(m_scoreBreakdown.get()); |
|
} |
|
|
|
|
|
const ScoreComponentCollection &GetDeltaScoreBreakdown() const { |
|
|
|
if (!m_deltaScoreBreakdown.get()) { |
|
m_deltaScoreBreakdown.reset(new ScoreComponentCollection()); |
|
|
|
if (m_transOpt) { |
|
m_deltaScoreBreakdown->PlusEquals(GetTranslationOption().GetScores()); |
|
} |
|
m_deltaScoreBreakdown->PlusEquals(m_currScoreBreakdown); |
|
|
|
} |
|
return *(m_deltaScoreBreakdown.get()); |
|
} |
|
|
|
|
|
float GetFutureScore() const { |
|
|
|
return m_totalScore; |
|
} |
|
|
|
|
|
const std::vector<const ChartHypothesis*> &GetPrevHypos() const { |
|
return m_prevHypos; |
|
} |
|
|
|
|
|
const ChartHypothesis* GetPrevHypo(size_t pos) const { |
|
return m_prevHypos[pos]; |
|
} |
|
|
|
|
|
const Word &GetTargetLHS() const { |
|
return GetCurrTargetPhrase().GetTargetLHS(); |
|
} |
|
|
|
|
|
const ChartHypothesis* GetWinningHypothesis() const { |
|
return m_winningHypo; |
|
} |
|
|
|
|
|
size_t hash() const; |
|
bool operator==(const ChartHypothesis& other) const; |
|
|
|
TO_STRING(); |
|
|
|
}; |
|
|
|
} |
|
|
|
|