2016-04-26 13:40:57 +03:00
|
|
|
/*
|
|
|
|
* TargetPhrase.h
|
|
|
|
*
|
|
|
|
* Created on: 26 Apr 2016
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2016-04-27 10:53:51 +03:00
|
|
|
#include "PhraseImplTemplate.h"
|
2016-04-26 16:47:31 +03:00
|
|
|
#include "System.h"
|
|
|
|
#include "Scores.h"
|
2016-04-26 13:40:57 +03:00
|
|
|
|
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
2016-04-26 22:53:53 +03:00
|
|
|
template<typename WORD>
|
2016-04-27 10:53:51 +03:00
|
|
|
class TargetPhrase: public PhraseImplTemplate<WORD>
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
const PhraseTable &pt;
|
|
|
|
mutable void **ffData;
|
|
|
|
SCORE *scoreProperties;
|
|
|
|
|
2016-04-27 10:53:51 +03:00
|
|
|
TargetPhrase(MemPool &pool, const PhraseTable &pt, const System &system, size_t size)
|
|
|
|
: PhraseImplTemplate<WORD>(pool, size)
|
|
|
|
, pt(pt)
|
2016-04-26 16:47:31 +03:00
|
|
|
, scoreProperties(NULL)
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
2016-04-26 16:47:31 +03:00
|
|
|
m_scores = new (pool.Allocate<Scores>()) Scores(system, pool,
|
|
|
|
system.featureFunctions.GetNumScores());
|
2016-04-26 13:40:57 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 16:47:31 +03:00
|
|
|
Scores &GetScores()
|
|
|
|
{ return *m_scores; }
|
|
|
|
|
2016-04-26 13:40:57 +03:00
|
|
|
const Scores &GetScores() const
|
2016-04-26 16:47:31 +03:00
|
|
|
{ return *m_scores; }
|
2016-04-26 13:40:57 +03:00
|
|
|
|
2016-04-26 16:47:31 +03:00
|
|
|
SCORE GetFutureScore() const
|
|
|
|
{ return m_scores->GetTotalScore() + m_estimatedScore; }
|
2016-04-26 13:40:57 +03:00
|
|
|
|
|
|
|
void SetEstimatedScore(const SCORE &value)
|
2016-04-26 16:47:31 +03:00
|
|
|
{ m_estimatedScore = value; }
|
2016-04-26 13:40:57 +03:00
|
|
|
|
2016-04-26 16:47:31 +03:00
|
|
|
SCORE *GetScoresProperty(int propertyInd) const
|
|
|
|
{ return scoreProperties ? scoreProperties + propertyInd : NULL; }
|
2016-04-26 13:40:57 +03:00
|
|
|
|
2016-06-18 00:54:32 +03:00
|
|
|
virtual std::ostream &Debug(std::ostream &out, const System &system) const
|
2016-06-11 00:03:11 +03:00
|
|
|
{
|
2016-06-11 04:07:43 +03:00
|
|
|
Phrase<WORD>::Debug(out, system);
|
2016-06-11 04:12:48 +03:00
|
|
|
out << " SCORES:";
|
|
|
|
GetScores().Debug(out, system);
|
2016-06-18 00:54:32 +03:00
|
|
|
|
|
|
|
return out;
|
2016-06-11 00:03:11 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 13:40:57 +03:00
|
|
|
protected:
|
|
|
|
Scores *m_scores;
|
|
|
|
SCORE m_estimatedScore;
|
|
|
|
};
|
|
|
|
|
2016-04-26 16:47:31 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
2016-06-13 15:59:26 +03:00
|
|
|
template<typename TP>
|
2016-04-26 13:40:57 +03:00
|
|
|
struct CompareFutureScore
|
|
|
|
{
|
2016-06-13 15:59:26 +03:00
|
|
|
bool operator()(const TP *a, const TP *b) const
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
|
|
|
return a->GetFutureScore() > b->GetFutureScore();
|
|
|
|
}
|
|
|
|
|
2016-06-13 15:59:26 +03:00
|
|
|
bool operator()(const TP &a, const TP &b) const
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
|
|
|
return a.GetFutureScore() > b.GetFutureScore();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-13 16:34:50 +03:00
|
|
|
template<typename TP>
|
|
|
|
struct Compare1Score
|
|
|
|
{
|
|
|
|
bool operator()(const TP *a, const TP *b) const
|
|
|
|
{
|
|
|
|
size_t numScores = a->pt.GetNumScores();
|
|
|
|
//std::cerr << "numScores=" << numScores << std::endl;
|
|
|
|
size_t offset;
|
|
|
|
if (numScores == 1) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
else if (numScores == 4 || numScores == 5) {
|
|
|
|
offset = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCORE scoreA = a->GetScores().GetScore(a->pt, offset);
|
|
|
|
SCORE scoreB = b->GetScores().GetScore(b->pt, offset);
|
|
|
|
|
|
|
|
return scoreA > scoreB;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2016-04-26 13:40:57 +03:00
|
|
|
|
|
|
|
} /* namespace Moses2a */
|
|
|
|
|