From 46fce4029ccc13e2cd75710f3f03cc4982fd507e Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Mon, 12 Aug 2013 10:34:45 +0100 Subject: [PATCH] create ChartTranslationOption class that store pointer to target phrase. Don't store target phrase itself. QUicker, but still not as quick as storing pointer to target phrase in hypo --- moses/ChartHypothesis.h | 4 ++-- moses/ChartManager.cpp | 2 +- moses/ChartTranslationOptions.cpp | 6 +++++- moses/ChartTranslationOptions.h | 18 +++++++++++++++++- moses/RuleCubeItem.cpp | 2 +- moses/RuleCubeItem.h | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/moses/ChartHypothesis.h b/moses/ChartHypothesis.h index 96f98930b..6de33dd72 100644 --- a/moses/ChartHypothesis.h +++ b/moses/ChartHypothesis.h @@ -49,7 +49,7 @@ protected: static ObjectPool s_objectPool; #endif - boost::shared_ptr m_targetPhrase; + boost::shared_ptr m_targetPhrase; WordsRange m_currSourceWordsRange; std::vector m_ffStates; /*! stateful feature function states */ @@ -102,7 +102,7 @@ public: //! Get the rule that created this hypothesis const TargetPhrase &GetCurrTargetPhrase()const { - return *m_targetPhrase; + return m_targetPhrase->GetPhrase(); } //! the source range that this hypothesis spans diff --git a/moses/ChartManager.cpp b/moses/ChartManager.cpp index 2fa6d995d..bbff9a985 100644 --- a/moses/ChartManager.cpp +++ b/moses/ChartManager.cpp @@ -136,7 +136,7 @@ void ChartManager::AddXmlChartOptions() i != xmlChartOptionsList.end(); ++i) { ChartTranslationOptions* opt = *i; - const TargetPhrase &targetPhrase = *opt->GetTargetPhrases()[0]; + const TargetPhrase &targetPhrase = opt->GetTargetPhrases()[0]->GetPhrase(); const WordsRange &range = opt->GetSourceWordsRange(); RuleCubeItem* item = new RuleCubeItem( *opt, m_hypoStackColl ); diff --git a/moses/ChartTranslationOptions.cpp b/moses/ChartTranslationOptions.cpp index e46a8d3cf..76d2b0c6f 100644 --- a/moses/ChartTranslationOptions.cpp +++ b/moses/ChartTranslationOptions.cpp @@ -25,6 +25,10 @@ namespace Moses { +ChartTranslationOption::ChartTranslationOption(const TargetPhrase &targetPhrase) +:m_targetPhrase(targetPhrase) +{ +} ChartTranslationOptions::ChartTranslationOptions(const TargetPhraseCollection &targetPhraseColl, const StackVec &stackVec, @@ -38,7 +42,7 @@ ChartTranslationOptions::ChartTranslationOptions(const TargetPhraseCollection &t for (iter = targetPhraseColl.begin(); iter != targetPhraseColl.end(); ++iter) { const TargetPhrase *origTP = *iter; - boost::shared_ptr ptr(new TargetPhrase(*origTP)); + boost::shared_ptr ptr(new ChartTranslationOption(*origTP)); m_targetPhraseCollection.push_back(ptr); } } diff --git a/moses/ChartTranslationOptions.h b/moses/ChartTranslationOptions.h index 94bf032a8..38698a2ca 100644 --- a/moses/ChartTranslationOptions.h +++ b/moses/ChartTranslationOptions.h @@ -31,13 +31,29 @@ namespace Moses { +class ChartTranslationOption +{ +protected: + const TargetPhrase &m_targetPhrase; + +public: + ChartTranslationOption(const TargetPhrase &targetPhrase); + + const TargetPhrase &GetPhrase() const + { return m_targetPhrase; } + + const ScoreComponentCollection &GetScores() const + { return m_targetPhrase.GetScoreBreakdown(); } + +}; + /** Similar to a DottedRule, but contains a direct reference to a list * of translations and provdes an estimate of the best score. For a specific range in the input sentence */ class ChartTranslationOptions { public: - typedef std::vector > CollType; + typedef std::vector > CollType; /** Constructor \param targetPhraseColl @todo dunno diff --git a/moses/RuleCubeItem.cpp b/moses/RuleCubeItem.cpp index 92539b39f..47703a630 100644 --- a/moses/RuleCubeItem.cpp +++ b/moses/RuleCubeItem.cpp @@ -65,7 +65,7 @@ RuleCubeItem::~RuleCubeItem() void RuleCubeItem::EstimateScore() { - m_score = m_translationDimension.GetTargetPhrase()->GetFutureScore(); + m_score = m_translationDimension.GetTargetPhrase()->GetPhrase().GetFutureScore(); std::vector::const_iterator p; for (p = m_hypothesisDimensions.begin(); p != m_hypothesisDimensions.end(); ++p) { diff --git a/moses/RuleCubeItem.h b/moses/RuleCubeItem.h index 5089b2bd1..a74e8d94a 100644 --- a/moses/RuleCubeItem.h +++ b/moses/RuleCubeItem.h @@ -53,7 +53,7 @@ public: return m_pos+1 < m_orderedTargetPhrases.size(); } - const boost::shared_ptr &GetTargetPhrase() const { + const boost::shared_ptr &GetTargetPhrase() const { return m_orderedTargetPhrases[m_pos]; }