templatize TargetPhrase class

This commit is contained in:
Hieu Hoang 2016-04-26 23:53:53 +04:00
parent 23d3ec326d
commit 5ed6fe1434
50 changed files with 95 additions and 82 deletions

View File

@ -92,7 +92,7 @@ void Distortion::EmptyHypothesisState(FFState &state, const ManagerBase &mgr,
}
void Distortion::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
}

View File

@ -27,7 +27,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void EvaluateWhenApplied(const std::deque<Hypothesis*> &hypos) const

View File

@ -15,10 +15,11 @@
namespace Moses2
{
template<typename WORD>
class TargetPhrase;
class System;
class PhraseImpl;
class TargetPhrase;
class TargetPhrases;
class Scores;
class ManagerBase;
@ -74,7 +75,7 @@ public:
// source from the input sentence
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const = 0;
/*

View File

@ -164,7 +164,7 @@ const PhraseTable *FeatureFunctions::GetPhraseTablesExcludeUnknownWordPenalty(
}
void FeatureFunctions::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, TargetPhrase &targetPhrase) const
const Phrase<Moses2::Word> &source, TargetPhrase<Moses2::Word> &targetPhrase) const
{
SCORE estimatedScore = 0;

View File

@ -16,6 +16,8 @@
namespace Moses2
{
template<typename WORD>
class TargetPhrase;
class System;
class FeatureFunction;
@ -24,7 +26,6 @@ class PhraseTable;
class Manager;
class MemPool;
class PhraseImpl;
class TargetPhrase;
class TargetPhrases;
class Scores;
@ -69,7 +70,7 @@ public:
// the pool here must be the system pool if the rule was loaded during load, or the mgr pool if it was loaded on demand
void EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, TargetPhrase &targetPhrase) const;
const Phrase<Moses2::Word> &source, TargetPhrase<Moses2::Word> &targetPhrase) const;
void EvaluateAfterTablePruning(MemPool &pool, const TargetPhrases &tps,
const Phrase<Moses2::Word> &sourcePhrase) const;

View File

@ -27,7 +27,7 @@ BidirectionalReorderingState::~BidirectionalReorderingState()
}
void BidirectionalReorderingState::Init(const LRState *prev,
const TargetPhrase &topt, const InputPathBase &path, bool first,
const TargetPhrase<Moses2::Word> &topt, const InputPathBase &path, bool first,
const Bitmap *coverage)
{
if (m_backward) {

View File

@ -18,7 +18,7 @@ public:
virtual ~BidirectionalReorderingState();
void Init(const LRState *prev, const TargetPhrase &topt,
void Init(const LRState *prev, const TargetPhrase<Moses2::Word> &topt,
const InputPathBase &path, bool first, const Bitmap *coverage);
size_t hash() const;

View File

@ -26,7 +26,7 @@ HReorderingBackwardState::~HReorderingBackwardState()
}
void HReorderingBackwardState::Init(const LRState *prev,
const TargetPhrase &topt, const InputPathBase &path, bool first,
const TargetPhrase<Moses2::Word> &topt, const InputPathBase &path, bool first,
const Bitmap *coverage)
{
prevTP = &topt;

View File

@ -19,7 +19,7 @@ private:
public:
HReorderingBackwardState(MemPool &pool, const LRModel &config, size_t offset);
virtual void Init(const LRState *prev, const TargetPhrase &topt,
virtual void Init(const LRState *prev, const TargetPhrase<Moses2::Word> &topt,
const InputPathBase &path, bool first, const Bitmap *coverage);
virtual ~HReorderingBackwardState();

View File

@ -27,7 +27,7 @@ HReorderingForwardState::~HReorderingForwardState()
}
void HReorderingForwardState::Init(const LRState *prev,
const TargetPhrase &topt, const InputPathBase &path, bool first,
const TargetPhrase<Moses2::Word> &topt, const InputPathBase &path, bool first,
const Bitmap *coverage)
{
prevTP = &topt;

View File

@ -19,7 +19,7 @@ public:
HReorderingForwardState(const LRModel &config, size_t offset);
virtual ~HReorderingForwardState();
void Init(const LRState *prev, const TargetPhrase &topt,
void Init(const LRState *prev, const TargetPhrase<Moses2::Word> &topt,
const InputPathBase &path, bool first, const Bitmap *coverage);
size_t hash() const;

View File

@ -21,7 +21,7 @@ LRState::LRState(const LRModel &config, LRModel::Direction dir, size_t offset) :
{
}
int LRState::ComparePrevScores(const TargetPhrase *other) const
int LRState::ComparePrevScores(const TargetPhrase<Moses2::Word> *other) const
{
LexicalReordering* producer = m_configuration.GetScoreProducer();
size_t phraseTableInd = producer->GetPhraseTableInd();
@ -43,14 +43,14 @@ int LRState::ComparePrevScores(const TargetPhrase *other) const
}
void LRState::CopyScores(const System &system, Scores &accum,
const TargetPhrase &topt, ReorderingType reoType) const
const TargetPhrase<Moses2::Word> &topt, ReorderingType reoType) const
{
// don't call this on a bidirectional object
UTIL_THROW_IF2(
m_direction != LRModel::Backward && m_direction != LRModel::Forward,
"Unknown direction: " << m_direction);
TargetPhrase const* relevantOpt = (
TargetPhrase<Moses2::Word> const* relevantOpt = (
(m_direction == LRModel::Backward) ? &topt : prevTP);
LexicalReordering* producer = m_configuration.GetScoreProducer();

View File

@ -4,6 +4,8 @@
namespace Moses2
{
template<typename WORD>
class TargetPhrase;
class LexicalReordering;
class Hypothesis;
@ -11,26 +13,26 @@ class System;
class Scores;
class Bitmap;
class ManagerBase;
class TargetPhrase;
class InputType;
class InputPathBase;
class Word;
class LRState: public FFState
{
public:
typedef LRModel::ReorderingType ReorderingType;
const TargetPhrase *prevTP;
const TargetPhrase<Moses2::Word> *prevTP;
LRState(const LRModel &config, LRModel::Direction dir, size_t offset);
virtual void Init(const LRState *prev, const TargetPhrase &topt,
virtual void Init(const LRState *prev, const TargetPhrase<Moses2::Word> &topt,
const InputPathBase &path, bool first, const Bitmap *coverage) = 0;
virtual void Expand(const ManagerBase &mgr, const LexicalReordering &ff,
const Hypothesis &hypo, size_t phraseTableInd, Scores &scores,
FFState &state) const = 0;
void CopyScores(const System &system, Scores &accum, const TargetPhrase &topt,
void CopyScores(const System &system, Scores &accum, const TargetPhrase<Moses2::Word> &topt,
ReorderingType reoType) const;
protected:
@ -39,7 +41,7 @@ protected:
size_t m_offset;
int
ComparePrevScores(const TargetPhrase *other) const;
ComparePrevScores(const TargetPhrase<Moses2::Word> *other) const;
};

View File

@ -124,7 +124,7 @@ void LexicalReordering::EmptyHypothesisState(FFState &state,
}
void LexicalReordering::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
}
@ -132,13 +132,13 @@ void LexicalReordering::EvaluateInIsolation(MemPool &pool, const System &system,
void LexicalReordering::EvaluateAfterTablePruning(MemPool &pool,
const TargetPhrases &tps, const Phrase<Moses2::Word> &sourcePhrase) const
{
BOOST_FOREACH(const TargetPhrase *tp, tps){
BOOST_FOREACH(const TargetPhrase<Moses2::Word> *tp, tps){
EvaluateAfterTablePruning(pool, *tp, sourcePhrase);
}
}
void LexicalReordering::EvaluateAfterTablePruning(MemPool &pool,
const TargetPhrase &targetPhrase, const Phrase<Moses2::Word> &sourcePhrase) const
const TargetPhrase<Moses2::Word> &targetPhrase, const Phrase<Moses2::Word> &sourcePhrase) const
{
if (m_propertyInd >= 0) {
SCORE *scoreArr = targetPhrase.GetScoresProperty(m_propertyInd);

View File

@ -40,7 +40,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void
@ -60,7 +60,7 @@ protected:
LRModel *m_configuration;
virtual void
EvaluateAfterTablePruning(MemPool &pool, const TargetPhrase &targetPhrase,
EvaluateAfterTablePruning(MemPool &pool, const TargetPhrase<Moses2::Word> &targetPhrase,
const Phrase<Moses2::Word> &sourcePhrase) const;
// PROPERTY IN PT

View File

@ -26,7 +26,7 @@ PhraseBasedReorderingState::PhraseBasedReorderingState(const LRModel &config,
}
void PhraseBasedReorderingState::Init(const LRState *prev,
const TargetPhrase &topt, const InputPathBase &path, bool first,
const TargetPhrase<Moses2::Word> &topt, const InputPathBase &path, bool first,
const Bitmap *coverage)
{
prevTP = &topt;

View File

@ -22,7 +22,7 @@ public:
PhraseBasedReorderingState(const LRModel &config, LRModel::Direction dir,
size_t offset);
void Init(const LRState *prev, const TargetPhrase &topt,
void Init(const LRState *prev, const TargetPhrase<Moses2::Word> &topt,
const InputPathBase &path, bool first, const Bitmap *coverage);
size_t hash() const;

View File

@ -23,7 +23,7 @@ PhrasePenalty::~PhrasePenalty()
}
void PhrasePenalty::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
scores.PlusEquals(system, *this, 1);

View File

@ -20,7 +20,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
};

View File

@ -70,7 +70,7 @@ void SkeletonStatefulFF::EmptyHypothesisState(FFState &state,
void SkeletonStatefulFF::EvaluateInIsolation(MemPool &pool,
const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
}

View File

@ -25,7 +25,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void EvaluateWhenApplied(const ManagerBase &mgr,

View File

@ -25,7 +25,7 @@ SkeletonStatelessFF::~SkeletonStatelessFF()
void SkeletonStatelessFF::EvaluateInIsolation(MemPool &pool,
const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{

View File

@ -20,7 +20,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
};

View File

@ -26,7 +26,7 @@ WordPenalty::~WordPenalty()
}
void WordPenalty::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
SCORE score = -(SCORE) targetPhrase.GetSize();

View File

@ -21,7 +21,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
};

View File

@ -130,7 +130,7 @@ void KENLM<Model>::EmptyHypothesisState(FFState &state, const ManagerBase &mgr,
template<class Model>
void KENLM<Model>::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
// contains factors used by this LM

View File

@ -44,7 +44,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void EvaluateWhenApplied(const ManagerBase &mgr,

View File

@ -142,7 +142,7 @@ void LanguageModel::EmptyHypothesisState(FFState &state, const ManagerBase &mgr,
}
void LanguageModel::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
if (targetPhrase.GetSize() == 0) {
@ -193,7 +193,7 @@ void LanguageModel::EvaluateWhenApplied(const ManagerBase &mgr,
SCORE score = 0;
std::pair<SCORE, void*> fromScoring;
const TargetPhrase &tp = hypo.GetTargetPhrase();
const TargetPhrase<Moses2::Word> &tp = hypo.GetTargetPhrase();
for (size_t i = 0; i < tp.GetSize(); ++i) {
const Word &word = tp[i];
const Factor *factor = word[m_factorType];

View File

@ -60,7 +60,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void EvaluateWhenApplied(const ManagerBase &mgr,

View File

@ -40,7 +40,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void EvaluateWhenApplied(const ManagerBase &mgr,

View File

@ -67,7 +67,7 @@ void QueueItem::CreateHypothesis(Manager &mgr)
{
const Hypothesis *prevHypo =
static_cast<const Hypothesis*>(edge->hypos[hypoIndex]);
const TargetPhrase &tp = edge->tps[tpIndex];
const TargetPhrase<Moses2::Word> &tp = edge->tps[tpIndex];
//cerr << "hypoIndex=" << hypoIndex << endl;
//cerr << "edge.hypos=" << edge.hypos.size() << endl;

View File

@ -50,7 +50,7 @@ Hypothesis::~Hypothesis()
}
void Hypothesis::Init(Manager &mgr, const InputPathBase &path,
const TargetPhrase &tp, const Bitmap &bitmap)
const TargetPhrase<Moses2::Word> &tp, const Bitmap &bitmap)
{
m_mgr = &mgr;
m_targetPhrase = &tp;
@ -66,7 +66,7 @@ void Hypothesis::Init(Manager &mgr, const InputPathBase &path,
}
void Hypothesis::Init(Manager &mgr, const Hypothesis &prevHypo,
const InputPathBase &path, const TargetPhrase &tp, const Bitmap &bitmap,
const InputPathBase &path, const TargetPhrase<Moses2::Word> &tp, const Bitmap &bitmap,
SCORE estimatedScore)
{
m_mgr = &mgr;

View File

@ -35,11 +35,11 @@ public:
virtual ~Hypothesis();
// initial, empty hypo
void Init(Manager &mgr, const InputPathBase &path, const TargetPhrase &tp,
void Init(Manager &mgr, const InputPathBase &path, const TargetPhrase<Moses2::Word> &tp,
const Bitmap &bitmap);
void Init(Manager &mgr, const Hypothesis &prevHypo, const InputPathBase &path,
const TargetPhrase &tp, const Bitmap &bitmap, SCORE estimatedScore);
const TargetPhrase<Moses2::Word> &tp, const Bitmap &bitmap, SCORE estimatedScore);
size_t hash() const;
bool operator==(const Hypothesis &other) const;
@ -64,7 +64,7 @@ public:
return GetScores().GetTotalScore() + m_estimatedScore;
}
const TargetPhrase &GetTargetPhrase() const
const TargetPhrase<Moses2::Word> &GetTargetPhrase() const
{
return *m_targetPhrase;
}
@ -94,7 +94,7 @@ public:
void Swap(Hypothesis &other);
protected:
const TargetPhrase *m_targetPhrase;
const TargetPhrase<Moses2::Word> *m_targetPhrase;
const Bitmap *m_sourceCompleted;
const InputPathBase *m_path;
const Hypothesis *m_prevHypo;

View File

@ -122,7 +122,7 @@ void Manager::CalcFutureScore()
for (size_t i = 0; i < numPt; ++i) {
const TargetPhrases *tps = static_cast<const InputPath*>(path)->targetPhrases[i];
if (tps) {
BOOST_FOREACH(const TargetPhrase *tp, *tps) {
BOOST_FOREACH(const TargetPhrase<Moses2::Word> *tp, *tps) {
SCORE score = tp->GetFutureScore();
if (score > bestScore) {
bestScore = score;

View File

@ -55,7 +55,7 @@ public:
return m_inputPaths;
}
const TargetPhrase &GetInitPhrase() const
const TargetPhrase<Moses2::Word> &GetInitPhrase() const
{
return *m_initPhrase;
}
@ -69,7 +69,7 @@ protected:
InputPaths m_inputPaths;
Bitmaps *m_bitmaps;
EstimatedScores *m_estimatedScores;
TargetPhrase *m_initPhrase;
TargetPhrase<Moses2::Word> *m_initPhrase;
Search *m_search;

View File

@ -108,12 +108,12 @@ void SearchNormal::Extend(const Hypothesis &hypo, const InputPath &path)
void SearchNormal::Extend(const Hypothesis &hypo, const TargetPhrases &tps,
const InputPath &path, const Bitmap &newBitmap, SCORE estimatedScore)
{
BOOST_FOREACH(const TargetPhrase *tp, tps){
BOOST_FOREACH(const TargetPhrase<Moses2::Word> *tp, tps){
Extend(hypo, *tp, path, newBitmap, estimatedScore);
}
}
void SearchNormal::Extend(const Hypothesis &hypo, const TargetPhrase &tp,
void SearchNormal::Extend(const Hypothesis &hypo, const TargetPhrase<Moses2::Word> &tp,
const InputPath &path, const Bitmap &newBitmap, SCORE estimatedScore)
{
Hypothesis *newHypo = Hypothesis::Create(mgr.GetSystemPool(), mgr);

View File

@ -16,11 +16,12 @@
namespace Moses2
{
template<typename WORD>
class TargetPhrase;
class Hypothesis;
class InputPath;
class TargetPhrases;
class TargetPhrase;
class Stacks;
class SearchNormal: public Search
@ -41,7 +42,7 @@ protected:
void Extend(const Hypothesis &hypo, const InputPath &path);
void Extend(const Hypothesis &hypo, const TargetPhrases &tps,
const InputPath &path, const Bitmap &newBitmap, SCORE estimatedScore);
void Extend(const Hypothesis &hypo, const TargetPhrase &tp,
void Extend(const Hypothesis &hypo, const TargetPhrase<Moses2::Word> &tp,
const InputPath &path, const Bitmap &newBitmap, SCORE estimatedScore);
};

View File

@ -23,7 +23,7 @@ class Manager;
class System;
class PhraseTable;
class TargetPhraseImpl: public TargetPhrase, public PhraseImplTemplate<Word>
class TargetPhraseImpl: public TargetPhrase<Moses2::Word>, public PhraseImplTemplate<Word>
{
friend std::ostream& operator<<(std::ostream &, const TargetPhraseImpl &);
public:

View File

@ -40,7 +40,7 @@ TargetPhrases::~TargetPhrases()
std::ostream& operator<<(std::ostream &out, const TargetPhrases &obj)
{
BOOST_FOREACH(const TargetPhrase *tp, obj){
BOOST_FOREACH(const TargetPhrase<Moses2::Word> *tp, obj){
out << *tp << endl;
}
@ -55,7 +55,7 @@ void TargetPhrases::SortAndPrune(size_t tableLimit)
m_coll.end() : m_coll.begin() + tableLimit;
std::partial_sort(m_coll.begin(), iterMiddle, m_coll.end(),
CompareFutureScore());
CompareFutureScore<Word>());
if (tableLimit && m_coll.size() > tableLimit) {
m_coll.resize(tableLimit);

View File

@ -11,12 +11,15 @@
namespace Moses2
{
template<typename WORD>
class TargetPhrase;
class Word;
class TargetPhrases
{
friend std::ostream& operator<<(std::ostream &, const TargetPhrases &);
typedef Array<const TargetPhrase*> Coll;
typedef Array<const TargetPhrase<Moses2::Word>*> Coll;
public:
typedef Coll::iterator iterator;
typedef Coll::const_iterator const_iterator;
@ -34,7 +37,7 @@ public:
//TargetPhrases(MemPool &pool, const System &system, const TargetPhrases &copy);
virtual ~TargetPhrases();
void AddTargetPhrase(const TargetPhrase &targetPhrase)
void AddTargetPhrase(const TargetPhrase<Moses2::Word> &targetPhrase)
{
m_coll[m_currInd++] = &targetPhrase;
}
@ -44,7 +47,7 @@ public:
return m_coll.size();
}
const TargetPhrase& operator[](size_t ind) const
const TargetPhrase<Moses2::Word>& operator[](size_t ind) const
{
return *m_coll[ind];
}

View File

@ -27,7 +27,7 @@ class AlignmentInfo;
namespace SCFG
{
class TargetPhraseImpl: public Moses2::TargetPhrase, public PhraseImplTemplate<SCFG::Word>
class TargetPhraseImpl: public Moses2::TargetPhrase<SCFG::Word>, public PhraseImplTemplate<SCFG::Word>
{
friend std::ostream& operator<<(std::ostream &, const SCFG::TargetPhraseImpl &);
public:

View File

@ -13,6 +13,7 @@
namespace Moses2
{
template<typename WORD>
class TargetPhrase: public Phrase<Word>
{
friend std::ostream& operator<<(std::ostream &, const TargetPhrase &);
@ -52,21 +53,23 @@ protected:
};
///////////////////////////////////////////////////////////////////////
inline std::ostream& operator<<(std::ostream &out, const TargetPhrase &obj)
template<typename WORD>
inline std::ostream& operator<<(std::ostream &out, const TargetPhrase<WORD> &obj)
{
out << (const Phrase<Word> &) obj << " SCORES:" << obj.GetScores();
out << (const Phrase<WORD> &) obj << " SCORES:" << obj.GetScores();
return out;
}
///////////////////////////////////////////////////////////////////////
template<typename WORD>
struct CompareFutureScore
{
bool operator()(const TargetPhrase *a, const TargetPhrase *b) const
bool operator()(const TargetPhrase<WORD> *a, const TargetPhrase<WORD> *b) const
{
return a->GetFutureScore() > b->GetFutureScore();
}
bool operator()(const TargetPhrase &a, const TargetPhrase &b) const
bool operator()(const TargetPhrase<WORD> &a, const TargetPhrase<WORD> &b) const
{
return a.GetFutureScore() > b.GetFutureScore();
}

View File

@ -33,7 +33,7 @@ public:
~Node()
{}
void AddRule(Phrase<WORD> &source, TargetPhrase *target)
void AddRule(Phrase<WORD> &source, TargetPhrase<Moses2::Word> *target)
{
AddRule(source, target, 0);
}
@ -85,7 +85,7 @@ public:
m_targetPhrases = new (pool.Allocate<TargetPhrases>()) TargetPhrases(pool, m_unsortedTPS->size());
for (size_t i = 0; i < m_unsortedTPS->size(); ++i) {
TargetPhrase *tp = (*m_unsortedTPS)[i];
TargetPhrase<Moses2::Word> *tp = (*m_unsortedTPS)[i];
m_targetPhrases->AddTargetPhrase(*tp);
}
@ -103,13 +103,13 @@ protected:
Children m_children;
TargetPhrases *m_targetPhrases;
Phrase<WORD> *m_source;
std::vector<TargetPhrase*> *m_unsortedTPS;
std::vector<TargetPhrase<Moses2::Word>*> *m_unsortedTPS;
Node &AddRule(Phrase<WORD> &source, TargetPhrase *target, size_t pos)
Node &AddRule(Phrase<WORD> &source, TargetPhrase<Moses2::Word> *target, size_t pos)
{
if (pos == source.GetSize()) {
if (m_unsortedTPS == NULL) {
m_unsortedTPS = new std::vector<TargetPhrase*>();
m_unsortedTPS = new std::vector<TargetPhrase<Moses2::Word>*>();
m_source = &source;
}

View File

@ -68,7 +68,7 @@ void PhraseTableMemory::Load(System &system)
//cerr << "line=" << line << endl;
Phrase<Moses2::Word> *source;
TargetPhrase *target;
TargetPhrase<Moses2::Word> *target;
if (m_isPb) {
source = PhraseImpl::CreateFromString(tmpSourcePool, vocab, system,
@ -86,7 +86,7 @@ void PhraseTableMemory::Load(System &system)
targetSCFG = SCFG::TargetPhraseImpl::CreateFromString(systemPool, *this,
system, toks[1]);
targetSCFG->SetAlignmentInfo(toks[3]);
target = targetSCFG;
//target = targetSCFG;
cerr << "created target " << *targetSCFG << endl;
}
@ -237,16 +237,18 @@ void PhraseTableMemory::AddTargetPhrasesToPath(const PtMem::Node<Word> &node,
const SCFG::SymbolBind &symbolBind,
SCFG::InputPath &path) const
{
/*
const TargetPhrases *tps = node.GetTargetPhrases();
if (tps) {
TargetPhrases::const_iterator iter;
for (iter = tps->begin(); iter != tps->end(); ++iter) {
const TargetPhrase *tp = *iter;
const TargetPhrase<Moses2::Word> *tp = *iter;
const SCFG::TargetPhraseImpl *tpCast = static_cast<const SCFG::TargetPhraseImpl*>(tp);
cerr << "tpCast=" << *tpCast << endl;
path.AddTargetPhrase(*this, symbolBind, tpCast);
}
}
*/
}
}

View File

@ -82,7 +82,7 @@ TargetPhrases *PhraseTable::Lookup(const Manager &mgr, MemPool &pool,
}
void PhraseTable::EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{
}

View File

@ -50,7 +50,7 @@ public:
virtual void
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void CleanUpAfterSentenceProcessing();

View File

@ -177,7 +177,7 @@ TargetPhrases *ProbingPT::CreateTargetPhrase(MemPool &pool,
offset += sizeof(uint64_t);
for (size_t i = 0; i < *numTP; ++i) {
TargetPhrase *tp = CreateTargetPhrase(pool, system, offset);
TargetPhrase<Moses2::Word> *tp = CreateTargetPhrase(pool, system, offset);
assert(tp);
const FeatureFunctions &ffs = system.featureFunctions;
ffs.EvaluateInIsolation(pool, system, sourcePhrase, *tp);
@ -194,7 +194,7 @@ TargetPhrases *ProbingPT::CreateTargetPhrase(MemPool &pool,
return tps;
}
TargetPhrase *ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system,
TargetPhrase<Moses2::Word> *ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system,
const char *&offset) const
{
TargetPhraseInfo *tpInfo = (TargetPhraseInfo*) offset;

View File

@ -54,7 +54,7 @@ protected:
InputPathBase &inputPath) const;
TargetPhrases *CreateTargetPhrase(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &sourcePhrase, uint64_t key) const;
TargetPhrase *CreateTargetPhrase(MemPool &pool, const System &system,
TargetPhrase<Moses2::Word> *CreateTargetPhrase(MemPool &pool, const System &system,
const char *&offset) const;
void ConvertToProbingSourcePhrase(const Phrase<Moses2::Word> &sourcePhrase, bool &ok,

View File

@ -99,7 +99,7 @@ TargetPhrases *UnknownWordPenalty::Lookup(const Manager &mgr, MemPool &pool,
}
void UnknownWordPenalty::EvaluateInIsolation(const System &system,
const Phrase<Moses2::Word> &source, const TargetPhrase &targetPhrase, Scores &scores,
const Phrase<Moses2::Word> &source, const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const
{

View File

@ -24,7 +24,7 @@ public:
virtual void
EvaluateInIsolation(const System &system, const Phrase<Moses2::Word> &source,
const TargetPhrase &targetPhrase, Scores &scores,
const TargetPhrase<Moses2::Word> &targetPhrase, Scores &scores,
SCORE *estimatedScore) const;
virtual void InitActiveChart(SCFG::InputPath &path) const;