2010-07-18 03:23:09 +04:00
|
|
|
// $Id$
|
2010-04-12 14:15:49 +04:00
|
|
|
// vim:tabstop=2
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2010 Hieu Hoang
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2010-04-12 14:15:49 +04:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2011-09-25 14:44:47 +04:00
|
|
|
#if HAVE_CONFIG_H
|
2011-09-24 14:06:21 +04:00
|
|
|
#include "config.h"
|
2011-09-25 14:44:47 +04:00
|
|
|
#endif
|
2011-09-24 14:06:21 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
#include <vector>
|
2011-03-11 16:08:43 +03:00
|
|
|
#include "Util.h"
|
|
|
|
#include "WordsRange.h"
|
|
|
|
#include "ScoreComponentCollection.h"
|
|
|
|
#include "Phrase.h"
|
|
|
|
#include "ChartTranslationOption.h"
|
|
|
|
#include "ObjectPool.h"
|
|
|
|
|
|
|
|
namespace Moses
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-06-27 19:13:15 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartHypothesis;
|
|
|
|
class ChartManager;
|
2011-06-27 19:13:15 +04:00
|
|
|
class RuleCubeItem;
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
typedef std::vector<ChartHypothesis*> ChartArcList;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
class ChartHypothesis
|
2010-04-08 21:16:10 +04:00
|
|
|
{
|
2011-03-11 16:08:43 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const ChartHypothesis&);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
#ifdef USE_HYPO_POOL
|
2011-03-11 16:08:43 +03:00
|
|
|
static ObjectPool<ChartHypothesis> s_objectPool;
|
2010-04-08 21:16:10 +04:00
|
|
|
#endif
|
|
|
|
|
2011-06-27 19:13:15 +04:00
|
|
|
const TargetPhrase &m_targetPhrase;
|
2011-03-11 19:28:36 +03:00
|
|
|
const ChartTranslationOption &m_transOpt;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
Phrase m_contextPrefix, m_contextSuffix;
|
|
|
|
WordsRange m_currSourceWordsRange;
|
2011-06-16 01:31:27 +04:00
|
|
|
std::vector<const FFState*> m_ffStates; /*! stateful feature function states */
|
2011-03-11 19:28:36 +03:00
|
|
|
ScoreComponentCollection m_scoreBreakdown /*! detailed score break-down by components (for instance language model, word penalty, etc) */
|
2011-02-24 15:36:50 +03:00
|
|
|
,m_lmNGram
|
|
|
|
,m_lmPrefix;
|
|
|
|
float m_totalScore;
|
|
|
|
size_t m_numTargetTerminals;
|
2010-05-06 22:09:03 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
ChartArcList *m_arcList; /*! all arcs that end at the same trellis point as this hypothesis */
|
|
|
|
const ChartHypothesis *m_winningHypo;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
std::vector<const ChartHypothesis*> m_prevHypos;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
ChartManager& m_manager;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
size_t CalcPrefix(Phrase &ret, size_t size) const;
|
|
|
|
size_t CalcSuffix(Phrase &ret, size_t size) const;
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
ChartHypothesis(); // not implemented
|
|
|
|
ChartHypothesis(const ChartHypothesis ©); // not implemented
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
#ifdef USE_HYPO_POOL
|
2011-02-24 19:17:38 +03:00
|
|
|
void *operator new(size_t /* num_bytes */) {
|
2011-02-24 15:36:50 +03:00
|
|
|
void *ptr = s_objectPool.getPtr();
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
static void Delete(ChartHypothesis *hypo) {
|
2011-02-24 15:36:50 +03:00
|
|
|
s_objectPool.freeObject(hypo);
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
#else
|
2011-03-11 16:08:43 +03:00
|
|
|
static void Delete(ChartHypothesis *hypo) {
|
2011-02-24 15:36:50 +03:00
|
|
|
delete hypo;
|
|
|
|
}
|
2010-04-08 21:16:10 +04:00
|
|
|
#endif
|
|
|
|
|
2011-06-27 19:13:15 +04:00
|
|
|
ChartHypothesis(const ChartTranslationOption &, const RuleCubeItem &item,
|
|
|
|
ChartManager &manager);
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
~ChartHypothesis();
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2011-09-24 18:48:52 +04:00
|
|
|
const ChartHypothesis *GetId() const { return this; }
|
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
const ChartTranslationOption &GetTranslationOption()const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_transOpt;
|
|
|
|
}
|
2011-03-11 19:28:36 +03:00
|
|
|
const TargetPhrase &GetCurrTargetPhrase()const {
|
2011-06-27 19:13:15 +04:00
|
|
|
return m_targetPhrase;
|
2011-02-24 15:36:50 +03:00
|
|
|
}
|
2011-03-11 19:28:36 +03:00
|
|
|
const WordsRange &GetCurrSourceRange()const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_currSourceWordsRange;
|
|
|
|
}
|
2011-03-11 16:08:43 +03:00
|
|
|
inline const ChartArcList* GetArcList() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_arcList;
|
|
|
|
}
|
2011-06-16 01:31:27 +04:00
|
|
|
inline const FFState* GetFFState( size_t featureID ) const {
|
|
|
|
return m_ffStates[ featureID ];
|
|
|
|
}
|
|
|
|
inline const ChartManager& GetManager() const { return m_manager; }
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
void CreateOutputPhrase(Phrase &outPhrase) const;
|
|
|
|
Phrase GetOutputPhrase() const;
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2011-06-16 01:31:27 +04:00
|
|
|
int RecombineCompare(const ChartHypothesis &compare) const;
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
const Phrase &GetPrefix() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_contextPrefix;
|
|
|
|
}
|
2011-03-11 19:28:36 +03:00
|
|
|
const Phrase &GetSuffix() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_contextSuffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CalcScore();
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
void AddArc(ChartHypothesis *loserHypo);
|
2011-02-24 15:36:50 +03:00
|
|
|
void CleanupArcList();
|
2011-03-11 16:08:43 +03:00
|
|
|
void SetWinningHypo(const ChartHypothesis *hypo);
|
2011-02-24 15:36:50 +03:00
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
const ScoreComponentCollection &GetScoreBreakdown() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_scoreBreakdown;
|
|
|
|
}
|
|
|
|
float GetTotalScore() const {
|
|
|
|
return m_totalScore;
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
const std::vector<const ChartHypothesis*> &GetPrevHypos() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return m_prevHypos;
|
|
|
|
}
|
|
|
|
|
2011-06-16 01:31:27 +04:00
|
|
|
const ChartHypothesis* GetPrevHypo(size_t pos) const {
|
|
|
|
return m_prevHypos[pos];
|
|
|
|
}
|
|
|
|
|
2011-03-11 19:28:36 +03:00
|
|
|
const Word &GetTargetLHS() const {
|
2011-02-24 15:36:50 +03:00
|
|
|
return GetCurrTargetPhrase().GetTargetLHS();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetNumTargetTerminals() const {
|
|
|
|
return m_numTargetTerminals;
|
|
|
|
}
|
|
|
|
|
2011-06-27 04:38:43 +04:00
|
|
|
const ChartHypothesis* GetWinningHypothesis() const {
|
|
|
|
return m_winningHypo;
|
|
|
|
}
|
|
|
|
|
2011-02-24 15:36:50 +03:00
|
|
|
TO_STRING();
|
2010-04-08 21:16:10 +04:00
|
|
|
|
2011-03-11 16:08:43 +03:00
|
|
|
}; // class ChartHypothesis
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|